Class: Sift::Router

Inherits:
Client show all
Defined in:
lib/sift/router.rb

Constant Summary

Constants inherited from Client

Client::API3_ENDPOINT, Client::API_ENDPOINT

Instance Attribute Summary

Attributes inherited from Client

#account_id, #api_key

Class Method Summary collapse

Methods inherited from Client

api3_client, api_client, #apply_decision, #apply_decision!, build_auth_header, #build_default_headers_post, #create_psp_merchant_profile, #decisions, #decisions!, #get_a_psp_merchant_profile, #get_content_decisions, #get_order_decisions, #get_psp_merchant_profiles, #get_session_decisions, #get_user_decisions, #get_user_score, #get_workflow_status, #initialize, #label, #rescore_user, #score, #track, #unlabel, #update_psp_merchant_profile, #user_agent, user_agent, #verification_check, #verification_resend, #verification_send

Constructor Details

This class inherits a constructor from Sift::Client

Class Method Details

.add_default_headers(options) ⇒ Object



28
29
30
31
32
# File 'lib/sift/router.rb', line 28

def add_default_headers(options)
  options[:headers] = {
    "User-Agent" => Sift::Client.user_agent
  }.merge(options[:headers] || {})
end

.get(path, options = {}) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/sift/router.rb', line 8

def get(path, options = {})
  client_class = options.delete(:client_class) || Sift::Client
  options[:base_uri] = nil
  serialize_body(options)
  add_default_headers(options)
  wrap_response(client_class.api3_client.get(path, options))
end

.post(path, options = {}) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/sift/router.rb', line 16

def post(path, options = {})
  client_class = options.delete(:client_class) || Sift::Client
  options[:base_uri] = nil
  serialize_body(options)
  add_default_headers(options)
  wrap_response(client_class.api3_client.post(path, options))
end

.serialize_body(options) ⇒ Object



24
25
26
# File 'lib/sift/router.rb', line 24

def serialize_body(options)
  options[:body] = MultiJson.dump(options[:body]) if options[:body]
end

.wrap_response(response) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/sift/router.rb', line 34

def wrap_response(response)
  Response.new(
    response.body,
    response.code,
    response.response
  )
end