Skip to content

Commit

Permalink
apply pr expo-community#14 fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinctzhang committed Sep 4, 2018
1 parent 626abbd commit 9ad1a38
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
[![Build Status](https://travis-ci.org/expo/exponent-server-sdk-ruby.svg?branch=master)](https://travis-ci.org/expo/exponent-server-sdk-ruby)
[![Gem Version](https://badge.fury.io/rb/exponent-server-sdk.svg)](https://badge.fury.io/rb/exponent-server-sdk)

Use to send push notifications to Exponent Experiences from a Ruby server.
FIX: Doing this because SDK has a bug

(fix) Validation situations where Expo returns a 200 with an error #14

## Installation

Expand Down
18 changes: 15 additions & 3 deletions lib/exponent-server-sdk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ def handle_success(response)
end

def extract_data(response)
response.fetch('data').first
# response.fetch('data').first
data_response = response.fetch('data')
return data_response.first if data_response.is_a? Array

data_response
end

def validate_status(status, response)
Expand Down Expand Up @@ -107,20 +111,28 @@ def with_error_handling(response)
end

def from_erroneous_response(response)
error = response.fetch('errors').first
error = extract_key(response, 'errors')
# error = response.fetch('errors').first
error_name = error.fetch('code')
message = error.fetch('message')

get_error_class(error_name).new(message)
end

def from_successful_response(response)
data = response.fetch('data').first
data = extract_key(response, 'data')
# data = response.fetch('data').first
message = data.fetch('message')

get_error_class(data.fetch('details').fetch('error')).new(message)
end

def extract_key(object, key)
key_response = object.fetch(key)
return key_response.first if key_response.is_a? Array
key_response
end

def validate_error_name(condition)
condition ? yield : Exponent::Push::UnknownError
end
Expand Down

0 comments on commit 9ad1a38

Please sign in to comment.