Class: Sift::Router

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/sift/router.rb

Class Method Summary collapse

Class Method Details

.add_default_headers(options) ⇒ Object



25
26
27
28
29
# File 'lib/sift/router.rb', line 25

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

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



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

def get(path, options = {})
  serialize_body(options)
  add_default_headers(options)
  wrap_response(super(path, options))
end

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



15
16
17
18
19
# File 'lib/sift/router.rb', line 15

def post(path, options = {})
  serialize_body(options)
  add_default_headers(options)
  wrap_response(super(path, options))
end

.serialize_body(options) ⇒ Object



21
22
23
# File 'lib/sift/router.rb', line 21

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

.wrap_response(response) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/sift/router.rb', line 31

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