Class: DuffelAPI::Services::OfferRequestsService

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

Instance Method Summary collapse

Methods inherited from BaseService

#initialize, #make_request

Constructor Details

This class inherits a constructor from DuffelAPI::Services::BaseService

Instance Method Details

#all(options = {}) ⇒ Object



49
50
51
52
53
54
# File 'lib/duffel_api/services/offer_requests_service.rb', line 49

def all(options = {})
  Paginator.new(
    service: self,
    options: options,
  ).enumerator
end

#create(options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/duffel_api/services/offer_requests_service.rb', line 6

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 = {}) ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'lib/duffel_api/services/offer_requests_service.rb', line 56

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 = {}) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/duffel_api/services/offer_requests_service.rb', line 37

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