Class: RESTinPeace::ApiCall

Inherits:
Object
  • Object
show all
Defined in:
lib/rest_in_peace/api_call.rb

Instance Method Summary collapse

Constructor Details

#initialize(api, url_template, klass, params) ⇒ ApiCall

Returns a new instance of ApiCall.



6
7
8
9
10
11
# File 'lib/rest_in_peace/api_call.rb', line 6

def initialize(api, url_template, klass, params)
  @api = api
  @url_template = url_template
  @klass = klass
  @params = params
end

Instance Method Details

#apiObject



54
55
56
# File 'lib/rest_in_peace/api_call.rb', line 54

def api
  @api.respond_to?(:call) ? @api.call : @api
end

#convert_response(response) ⇒ Object



50
51
52
# File 'lib/rest_in_peace/api_call.rb', line 50

def convert_response(response)
  RESTinPeace::ResponseConverter.new(response, @klass).result
end

#deleteObject



33
34
35
36
# File 'lib/rest_in_peace/api_call.rb', line 33

def delete
  response = api.delete(url, params)
  convert_response(response)
end

#getObject



13
14
15
16
# File 'lib/rest_in_peace/api_call.rb', line 13

def get
  response = api.get(url, params)
  convert_response(response)
end

#paramsObject



42
43
44
# File 'lib/rest_in_peace/api_call.rb', line 42

def params
  sanitizer.leftover_params
end

#patchObject



23
24
25
26
# File 'lib/rest_in_peace/api_call.rb', line 23

def patch
  response = api.patch(url, params)
  convert_response(response)
end

#postObject



18
19
20
21
# File 'lib/rest_in_peace/api_call.rb', line 18

def post
  response = api.post(url, params)
  convert_response(response)
end

#putObject



28
29
30
31
# File 'lib/rest_in_peace/api_call.rb', line 28

def put
  response = api.put(url, params)
  convert_response(response)
end

#sanitizerObject



46
47
48
# File 'lib/rest_in_peace/api_call.rb', line 46

def sanitizer
  @sanitizer ||= RESTinPeace::TemplateSanitizer.new(@url_template, @params)
end

#urlObject



38
39
40
# File 'lib/rest_in_peace/api_call.rb', line 38

def url
  sanitizer.url
end