Class: RESTinPeace::ApiCall
- Inherits:
-
Object
- Object
- RESTinPeace::ApiCall
- Defined in:
- lib/rest_in_peace/api_call.rb
Instance Method Summary collapse
- #api ⇒ Object
- #convert_response(response) ⇒ Object
- #delete ⇒ Object
- #get ⇒ Object
-
#initialize(api, url_template, klass, params) ⇒ ApiCall
constructor
A new instance of ApiCall.
- #params ⇒ Object
- #patch ⇒ Object
- #post ⇒ Object
- #put ⇒ Object
- #sanitizer ⇒ Object
- #url ⇒ Object
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
#api ⇒ Object
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 |
#delete ⇒ Object
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 |
#get ⇒ Object
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 |
#params ⇒ Object
43 44 45 |
# File 'lib/rest_in_peace/api_call.rb', line 43 def params sanitizer.leftover_params end |
#patch ⇒ Object
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 |
#post ⇒ Object
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 |
#put ⇒ Object
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 |
#sanitizer ⇒ Object
47 48 49 |
# File 'lib/rest_in_peace/api_call.rb', line 47 def sanitizer @sanitizer ||= RESTinPeace::TemplateSanitizer.new(@url_template, @params, @klass) end |
#url ⇒ Object
39 40 41 |
# File 'lib/rest_in_peace/api_call.rb', line 39 def url sanitizer.url end |