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
12
# 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
  @attributes = {}
end

Instance Method Details

#apiObject



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

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

#convert_response(response) ⇒ Object



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

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

#deleteObject



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

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

#getObject



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

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

#paramsObject



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

def params
  sanitizer.leftover_params
end

#patchObject



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

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

#postObject



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

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

#putObject



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

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

#sanitizerObject



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

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

#urlObject



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

def url
  sanitizer.url
end