Class: Exponent::Push::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/expo-push.rb

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ Client

Returns a new instance of Client.



39
40
41
42
43
44
45
46
# File 'lib/expo-push.rb', line 39

def initialize(**args)
  @http_client = args[:http_client] || Typhoeus
  @params = args[:params].presence || {}
  @error_builder = ErrorBuilder.new
  # future versions will deprecate this
  @response_handler = args[:response_handler] || ResponseHandler.new
  @gzip             = args[:gzip] == true
end

Instance Method Details

#send_messages(messages, **args) ⇒ Object

returns response handler that provides access to errors? and other response inspection methods



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/expo-push.rb', line 49

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) ⇒ Object



61
62
63
64
65
66
# File 'lib/expo-push.rb', line 61

def verify_deliveries(receipt_ids, **args)
  response = get_receipts(receipt_ids)
  handler  = args[:response_handler] || ResponseHandler.new
  handler.process_response(response)
  handler
end