Class: YandexDelivery::APIRequest
- Inherits:
-
Object
- Object
- YandexDelivery::APIRequest
- Defined in:
- lib/yandex-delivery/api_request.rb
Instance Method Summary collapse
- #delete(params: nil, headers: nil) ⇒ Object
- #get(params: nil, headers: nil) ⇒ Object
-
#initialize(builder: nil) ⇒ APIRequest
constructor
A new instance of APIRequest.
- #patch(params: nil, headers: nil, body: {}) ⇒ Object
- #post(params: nil, headers: nil, body: {}) ⇒ Object
- #put(params: nil, headers: nil, body: {}) ⇒ Object
Constructor Details
#initialize(builder: nil) ⇒ APIRequest
Returns a new instance of APIRequest.
4 5 6 |
# File 'lib/yandex-delivery/api_request.rb', line 4 def initialize(builder: nil) @request_builder = builder end |
Instance Method Details
#delete(params: nil, headers: nil) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/yandex-delivery/api_request.rb', line 63 def delete(params: nil, headers: nil) validate_api_key begin response = self.rest_client.delete do |request| configure_request(request: request, params: params, headers: headers) end parse_response(response) rescue => e handle_error(e) end end |
#get(params: nil, headers: nil) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/yandex-delivery/api_request.rb', line 50 def get(params: nil, headers: nil) validate_api_key begin response = self.rest_client.get do |request| configure_request(request: request, params: params, headers: headers) end parse_response(response) rescue => e handle_error(e) end end |
#patch(params: nil, headers: nil, body: {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/yandex-delivery/api_request.rb', line 22 def patch(params: nil, headers: nil, body: {}) validate_api_key begin response = self.rest_client.patch do |request| body[:senderId] = YandexDelivery.senders.first["id"] if body[:senderId].nil? configure_request(request: request, params: params, headers: headers, body: MultiJson.dump(body)) end parse_response(response) rescue => e handle_error(e) end end |
#post(params: nil, headers: nil, body: {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/yandex-delivery/api_request.rb', line 8 def post(params: nil, headers: nil, body: {}) validate_api_key begin response = self.rest_client.post do |request| body[:senderId] = YandexDelivery.senders.first["id"] if body[:senderId].nil? configure_request(request: request, params: params, headers: headers, body: MultiJson.dump(body)) end parse_response(response) rescue => e handle_error(e) end end |
#put(params: nil, headers: nil, body: {}) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/yandex-delivery/api_request.rb', line 36 def put(params: nil, headers: nil, body: {}) validate_api_key begin response = self.rest_client.put do |request| body[:senderId] = YandexDelivery.senders.first["id"] if body[:senderId].nil? configure_request(request: request, params: params, headers: headers, body: MultiJson.dump(body)) end parse_response(response) rescue => e handle_error(e) end end |