class PushNotifications::Client
Constants
- BASE_URL
- Response
Attributes
config[R]
Public Class Methods
new(config: PushNotifications)
click to toggle source
# File lib/push_notifications/client.rb, line 15 def initialize(config: PushNotifications) @config = config end
Public Instance Methods
post(resource, payload = {})
click to toggle source
# File lib/push_notifications/client.rb, line 19 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
Private Instance Methods
build_url(resource)
click to toggle source
# File lib/push_notifications/client.rb, line 37 def build_url(resource) "https://#{instance_id}.#{BASE_URL}/#{instance_id}/#{resource}" end
headers()
click to toggle source
# File lib/push_notifications/client.rb, line 41 def headers { content_type: 'application/json', accept: :json, Authorization: "Bearer #{secret_key}" } end