Module: Sqoot::Request

Included in:
Client
Defined in:
lib/sqoot/request.rb

Instance Method Summary collapse

Instance Method Details

#convert_params(path, data = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/sqoot/request.rb', line 8

def convert_params(path, data={})
  auth_endpoints = ['commissions', 'clicks']

  if auth_endpoints.include? path.split('/')[2]
    data['authentication_token'] = authentication_token
  else
    data['affiliate_token'] = affiliate_token
  end

  data

end

#get(path, options) ⇒ Object



4
5
6
# File 'lib/sqoot/request.rb', line 4

def get(path, options)
  request(:get, path, convert_params(path, options))
end

#request(method, path, options) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/sqoot/request.rb', line 21

def request(method, path, options)
  response = connection.send(method) do |request|
    case method
    when :delete, :get
      request.url(path, options)
    when :post, :put
      request.path = path
      request.body = MultiJson.encode(options) unless options.empty?
    end
  end

  response.body
end