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

Instance Method Summary collapse

Constructor Details

#initialize(config: PushNotifications) ⇒ Client

Returns a new instance of Client.



14
15
16
# File 'lib/pusher/push_notifications/client.rb', line 14

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

Instance Method Details

#delete(user) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/pusher/push_notifications/client.rb', line 36

def delete(user)
  url_encoded_user_id = CGI.escape(user)
  url = build_users_url(url_encoded_user_id)

  RestClient::Request.execute(
    method: :delete, url: url,
    headers: headers
  ) do |response|
    status = response.code
    case status
    when 200
      Response.new(status, nil, true)
    else
      Response.new(status, nil, false)
    end
  end
end

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



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

def post(resource, payload = {})
  url = build_publish_url(resource)
  body = payload.to_json

  RestClient::Request.execute(
    method: :post, url: url,
    payload: body, headers: headers
  ) do |response|
    status = response.code
    if json?(response.body)
      body = JSON.parse(response.body)
      Response.new(status, body, status == 200)
    else
      Response.new(status, nil, false)
    end
  end
end