Class: DuffelAPI::Services::OfferRequestsService
- Inherits:
-
BaseService
- Object
- BaseService
- DuffelAPI::Services::OfferRequestsService
- Defined in:
- lib/duffel_api/services/offer_requests_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::OfferRequest`s.
-
#create(options = {}) ⇒ Resources::OfferRequest
Creates an offer request.
-
#get(id, options = {}) ⇒ Resources::OfferRequest
Retrieves a single offer request by ID.
-
#list(options = {}) ⇒ ListResponse
Lists offer requests, returning a single page of results.
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::OfferRequest`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`.
71 72 73 74 75 76 77 78 |
# File 'lib/duffel_api/services/offer_requests_service.rb', line 71 def all( = {}) [:params] = DEFAULT_ALL_PARAMS.merge([:params] || {}) Paginator.new( service: self, options: , ).enumerator end |
#create(options = {}) ⇒ Resources::OfferRequest
Creates an offer request
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/duffel_api/services/offer_requests_service.rb', line 12 def create( = {}) path = "/air/offer_requests" params = .delete(:params) || {} # The "Create offer request" API expects a JSON body and can also accept the # `return_offers` query parameter. No other endpoints in the Duffel API allow # both. To avoid making the client library interface confusing, we get the client # to pass this value in along with the body params, and we know to move it into # the querystring. return_offers = params.delete(:return_offers) unless return_offers.nil? [:query_params] = { return_offers: return_offers } end [: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::OfferRequest.new(unenvelope_body(response.parsed_body), response) end |
#get(id, options = {}) ⇒ Resources::OfferRequest
Retrieves a single offer request by ID
85 86 87 88 89 90 91 92 93 |
# File 'lib/duffel_api/services/offer_requests_service.rb', line 85 def get(id, = {}) path = substitute_url_pattern("/air/offer_requests/:id", "id" => id) response = make_request(:get, path, ) return if response.raw_body.nil? Resources::OfferRequest.new(unenvelope_body(response.parsed_body), response) end |
#list(options = {}) ⇒ ListResponse
Lists offer requests, returning a single page of results.
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/duffel_api/services/offer_requests_service.rb', line 49 def list( = {}) path = "/air/offer_requests" response = make_request(:get, path, ) ListResponse.new( response: response, unenveloped_body: unenvelope_body(response.parsed_body), resource_class: Resources::OfferRequest, ) end |