class Maropost::Service
Attributes
method[RW]
path[RW]
payload[RW]
query[RW]
request_id[RW]
Public Class Methods
new(opts = {})
click to toggle source
# File lib/maropost/service.rb, line 7 def initialize(opts = {}) self.method = opts.fetch(:method) self.path = opts.fetch(:path) self.payload = opts.fetch(:payload, {}) # optional self.query = opts[:query] # optional self.request_id = SecureRandom.uuid end
Public Instance Methods
execute!()
click to toggle source
# File lib/maropost/service.rb, line 15 def execute! RestClient::Request.logged_request(params) end
Private Instance Methods
base_params()
click to toggle source
# File lib/maropost/service.rb, line 35 def base_params { method: method, read_timeout: Maropost.configuration.read_timeout, open_timeout: Maropost.configuration.open_timeout, url: maropost_url, headers: { content_type: 'application/json', accept: 'application/json', request_id: request_id }, verify_ssl: OpenSSL::SSL::VERIFY_PEER } end
encode_query(hash)
click to toggle source
# File lib/maropost/service.rb, line 27 def encode_query(hash) RestClient::Utils.encode_query_string(hash) end
get?()
click to toggle source
# File lib/maropost/service.rb, line 31 def get? method.to_s.casecmp('get').zero? end
maropost_url()
click to toggle source
# File lib/maropost/service.rb, line 21 def maropost_url self.query &&= encode_query(query) uri = URI.join(Maropost.configuration.api_url, path) uri.tap { |u| query && u.query = query }.to_s end
params()
click to toggle source
# File lib/maropost/service.rb, line 50 def params return base_params if get? base_params.merge( payload: { auth_token: Maropost.configuration.auth_token }.merge(payload).to_json ) end