Class: DuffelAPI::Services::OrdersService
- Inherits:
-
BaseService
- Object
- BaseService
- DuffelAPI::Services::OrdersService
- Defined in:
- lib/duffel_api/services/orders_service.rb
Constant Summary
Constants inherited from BaseService
BaseService::DEFAULT_ALL_PARAMS
Instance Method Summary collapse
-
#all(options = {}) ⇒ Enumerator
Returns an ‘Enumerator` which can automatically cycle through multiple pages of `Resources::Order`s.
-
#create(options = {}) ⇒ Resources::Order
Creates an order.
-
#get(id, options = {}) ⇒ Resources::Order
Retrieves a single order by ID.
-
#list(options = {}) ⇒ ListResponse
Lists orders, returning a single page of results.
-
#update(id, options = {}) ⇒ Resources::Order
Updates an order.
Methods inherited from BaseService
Constructor Details
This class inherits a constructor from DuffelAPI::Services::BaseService
Instance Method Details
#all(options = {}) ⇒ Enumerator
Returns an ‘Enumerator` which can automatically cycle through multiple pages of `Resources::Order`s.
By default, this will use pages of 200 results under the hood, but this can be customised by specifying the ‘:limit` option in the `:params`.
82 83 84 85 86 87 88 89 |
# File 'lib/duffel_api/services/orders_service.rb', line 82 def all( = {}) [:params] = DEFAULT_ALL_PARAMS.merge([:params] || {}) Paginator.new( service: self, options: , ).enumerator end |
#create(options = {}) ⇒ Resources::Order
Creates an order
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/duffel_api/services/orders_service.rb', line 11 def create( = {}) path = "/air/orders" params = .delete(:params) || {} [:params] = {} [:params]["data"] = params begin response = make_request(:post, path, ) # Response doesn't raise any errors until #body is called response.tap(&:raw_body) end return if response.raw_body.nil? Resources::Order.new(unenvelope_body(response.parsed_body), response) end |
#get(id, options = {}) ⇒ Resources::Order
Retrieves a single order by ID
96 97 98 99 100 101 102 103 104 |
# File 'lib/duffel_api/services/orders_service.rb', line 96 def get(id, = {}) path = substitute_url_pattern("/air/orders/:id", "id" => id) response = make_request(:get, path, ) return if response.raw_body.nil? Resources::Order.new(unenvelope_body(response.parsed_body), response) end |
#list(options = {}) ⇒ ListResponse
Lists orders, returning a single page of results.
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/duffel_api/services/orders_service.rb', line 60 def list( = {}) path = "/air/orders" response = make_request(:get, path, ) ListResponse.new( response: response, unenveloped_body: unenvelope_body(response.parsed_body), resource_class: Resources::Order, ) end |
#update(id, options = {}) ⇒ Resources::Order
Updates an order
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/duffel_api/services/orders_service.rb', line 35 def update(id, = {}) path = substitute_url_pattern("/air/orders/:id", "id" => id) params = .delete(:params) || {} [:params] = {} [:params]["data"] = params begin response = make_request(:patch, path, ) # Response doesn't raise any errors until #body is called response.tap(&:raw_body) end return if response.raw_body.nil? Resources::Order.new(unenvelope_body(response.parsed_body), response) end |