class Pushwoosh::Request

Attributes

base_request[R]
notification_options[R]
options[R]
url[R]

Public Class Methods

make_post!(*args) click to toggle source
# File lib/pushwoosh/request.rb, line 10
def self.make_post!(*args)
  new(*args).make_post!
end
new(url, options = {}) click to toggle source
# File lib/pushwoosh/request.rb, line 14
def initialize(url, options = {})
  validations!(url, options)

  @options = options
  @notification_options = options.fetch(:notification_options)
  @url = url
  @base_request = {
    request: {
      application: options[:application],
      auth: options[:auth]
    }
  }
end

Public Instance Methods

make_post!() click to toggle source
# File lib/pushwoosh/request.rb, line 28
def make_post!
  response = self.class.post(url, body: build_request.to_json).parsed_response
  Response.new(response)
end

Private Instance Methods

build_request() click to toggle source
# File lib/pushwoosh/request.rb, line 43
def build_request
  { request: full_request_with_notifications }
end
full_request_with_notifications() click to toggle source
# File lib/pushwoosh/request.rb, line 47
def full_request_with_notifications
  base_request[:request].merge(notifications: [notification_options])
end
validations!(url, options) click to toggle source
# File lib/pushwoosh/request.rb, line 37
def validations!(url, options)
  fail Pushwoosh::Exceptions::Error, 'Missing application' unless options.fetch(:application)
  fail Pushwoosh::Exceptions::Error, 'Missing auth key' unless options.fetch(:auth)
  fail Pushwoosh::Exceptions::Error, 'URL is empty' if url.nil? || url.empty?
end