Class: MyTargetApi::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/my_target_api/request.rb

Overview

Requests

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Request

Returns a new instance of Request.



10
11
12
# File 'lib/my_target_api/request.rb', line 10

def initialize(options = {})
  @options = options
end

Instance Method Details

#delete(url, params = {}) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/my_target_api/request.rb', line 34

def delete(url, params = {})
  log_hash(method: 'Request#delete', url: url, params: params)

  response = with_exception_handling do
    RestClient.delete(url, headers.merge(query(params)))
  end

  process_response(response)
end

#get(url, params = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/my_target_api/request.rb', line 14

def get(url, params = {})
  log_hash(method: 'Request#get', url: url, params: params)

  response = with_exception_handling do
    RestClient.get(url, headers.merge(query(params)))
  end

  process_response(response)
end

#post(url, params = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/my_target_api/request.rb', line 24

def post(url, params = {})
  log_hash(method: 'Request#post', url: url, params: params)

  response = with_exception_handling do
    RestClient.post(url, body_parameters(params), headers)
  end

  process_response(response)
end

#upload(url, content, params = {}) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/my_target_api/request.rb', line 44

def upload(url, content, params = {})
  log_hash(method: 'Request#upload', url: url, params: params, content: 'no logging')

  response = with_exception_handling do
    RestClient.post(
      url, content, headers.merge(query(params)).merge(content_type: 'application/octet-stream')
    )
  end

  process_response(response)
end