Class: DuffelAPI::Services::OfferRequestsService

Inherits:
BaseService
  • Object
show all
Defined in:
lib/duffel_api/services/offer_requests_service.rb

Constant Summary

Constants inherited from BaseService

BaseService::DEFAULT_ALL_PARAMS

Instance Method Summary collapse

Methods inherited from BaseService

#initialize

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.

Parameters:

  • (defaults to: {})

    options passed to #list, for example :params to send an HTTP querystring with filters

Returns:

Raises:

  • when the Duffel API returns an error



71
72
73
74
75
76
77
78
# File 'lib/duffel_api/services/offer_requests_service.rb', line 71

def all(options = {})
  options[:params] = DEFAULT_ALL_PARAMS.merge(options[:params] || {})

  Paginator.new(
    service: self,
    options: options,
  ).enumerator
end

#create(options = {}) ⇒ Resources::OfferRequest

Creates an offer request

Parameters:

  • a customizable set of options

Returns:

Raises:

  • when the Duffel API returns an error



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(options = {})
  path = "/air/offer_requests"

  params = options.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?
    options[:query_params] = { return_offers: return_offers }
  end

  options[:params] = {}
  options[:params]["data"] = params

  begin
    response = make_request(:post, path, options)

    # 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

Parameters:

Returns:

Raises:

  • when the Duffel API returns an error



85
86
87
88
89
90
91
92
93
# File 'lib/duffel_api/services/offer_requests_service.rb', line 85

def get(id, options = {})
  path = substitute_url_pattern("/air/offer_requests/:id", "id" => id)

  response = make_request(:get, path, options)

  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.

Parameters:

  • a customizable set of options

Returns:

Raises:

  • when the Duffel API returns an error



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/duffel_api/services/offer_requests_service.rb', line 49

def list(options = {})
  path = "/air/offer_requests"

  response = make_request(:get, path, options)

  ListResponse.new(
    response: response,
    unenveloped_body: unenvelope_body(response.parsed_body),
    resource_class: Resources::OfferRequest,
  )
end