class Exponent::Push::Client
Public Class Methods
new(**args)
click to toggle source
# File lib/exponent-server-sdk.rb, line 39 def initialize(**args) @http_client = args[:http_client] || Typhoeus @error_builder = ErrorBuilder.new # future versions will deprecate this @response_handler = args[:response_handler] || ResponseHandler.new @gzip = args[:gzip] == true end
Public Instance Methods
publish(messages)
click to toggle source
returns a string response with parsed success json or error @deprecated
# File lib/exponent-server-sdk.rb, line 49 def publish(messages) warn '[DEPRECATION] `publish` is deprecated. Please use `send_messages` instead.' @response_handler.handle(push_notifications(messages)) end
send_messages(messages, **args)
click to toggle source
returns response handler that provides access to errors? and other response inspection methods
# File lib/exponent-server-sdk.rb, line 55 def send_messages(messages, **args) # https://docs.expo.io/versions/latest/guides/push-notifications/#message-format raise TooManyMessagesError, 'Only 100 message objects at a time allowed.' if messages.length > 100 response = push_notifications(messages) # each call to send_messages will return a new instance of ResponseHandler handler = args[:response_handler] || ResponseHandler.new handler.process_response(response) handler end
verify_deliveries(receipt_ids, **args)
click to toggle source
# File lib/exponent-server-sdk.rb, line 67 def verify_deliveries(receipt_ids, **args) response = get_receipts(receipt_ids) handler = args[:response_handler] || ResponseHandler.new handler.process_response(response) handler end
Private Instance Methods
get_receipts(receipt_ids)
click to toggle source
# File lib/exponent-server-sdk.rb, line 89 def get_receipts(receipt_ids) @http_client.post( receipts_url, body: { ids: receipt_ids }.to_json, headers: headers, accept_encoding: @gzip ) end
headers()
click to toggle source
# File lib/exponent-server-sdk.rb, line 102 def headers headers = { 'Content-Type' => 'application/json', 'Accept' => 'application/json' } headers end
push_notifications(messages)
click to toggle source
# File lib/exponent-server-sdk.rb, line 76 def push_notifications(messages) @http_client.post( push_url, body: messages.to_json, headers: headers, accept_encoding: @gzip ) end
push_url()
click to toggle source
# File lib/exponent-server-sdk.rb, line 85 def push_url 'https://exp.host/--/api/v2/push/send' end
receipts_url()
click to toggle source
# File lib/exponent-server-sdk.rb, line 98 def receipts_url 'https://exp.host/--/api/v2/push/getReceipts' end