Class: Pusher::PushNotifications::Client

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/pusher/push_notifications/client.rb

Defined Under Namespace

Classes: Response

Constant Summary collapse

BASE_URL =
'pushnotifications.pusher.com/publish_api/v1/instances'

Instance Method Summary collapse

Constructor Details

#initialize(config: PushNotifications) ⇒ Client

Returns a new instance of Client.



16
17
18
# File 'lib/pusher/push_notifications/client.rb', line 16

def initialize(config: PushNotifications)
  @config = config
end

Instance Method Details

#post(resource, payload = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/pusher/push_notifications/client.rb', line 20

def post(resource, payload = {})
  url = build_url(resource)
  body = payload.to_json
  RestClient::Request.execute(
    method: :post, url: url,
    payload: body, headers: headers
  ) do |response|
    status = response.code
    body = JSON.parse(response.body)
    Response.new(status, body, status == 200 ? true : false)
  end
end