Class: BatchPushNotification::Client
- Inherits:
-
Object
- Object
- BatchPushNotification::Client
- Defined in:
- lib/batch_push_notification/client.rb
Instance Method Summary collapse
- #connection ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #send_notification(notification) ⇒ Object
- #send_url ⇒ Object
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
6 7 8 9 |
# File 'lib/batch_push_notification/client.rb', line 6 def initialize # fail if the required params are not set: raise(StandardError, 'Configuration is missing') unless BatchPushNotification.endpoint && BatchPushNotification.api_key && BatchPushNotification.rest_api_key && !BatchPushNotification.sandbox.nil? end |
Instance Method Details
#connection ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/batch_push_notification/client.rb', line 16 def connection return Faraday.new(:url => BatchPushNotification.endpoint) do |faraday| faraday.response :logger # log requests to STDOUT faraday.headers['Content-Type'] = 'application/json' faraday.headers['X-Authorization'] = BatchPushNotification.rest_api_key faraday.adapter Faraday.default_adapter # make requests with Net::HTTP end end |
#send_notification(notification) ⇒ Object
11 12 13 14 |
# File 'lib/batch_push_notification/client.rb', line 11 def send_notification(notification) response = connection.post send_url, notification.payload return JSON.parse(response.body) end |
#send_url ⇒ Object
26 27 28 |
# File 'lib/batch_push_notification/client.rb', line 26 def send_url BatchPushNotification.api_key + '/transactional/send' end |