Class: DuffelAPI::Services::OrderCancellationsService

Inherits:
BaseService
  • Object
show all
Defined in:
lib/duffel_api/services/order_cancellations_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::OrderCancellation`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:

  • options (Hash) (defaults to: {})

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

Returns:

  • (Enumerator)

Raises:



83
84
85
86
87
88
89
90
# File 'lib/duffel_api/services/order_cancellations_service.rb', line 83

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

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

#confirm(id, options = {}) ⇒ Resources::OrderCancellation

Confirms an order cancellation by ID

Parameters:

  • id (String)

Returns:

Raises:



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/duffel_api/services/order_cancellations_service.rb', line 35

def confirm(id, options = {})
  path = substitute_url_pattern("/air/order_cancellations/:id/actions/confirm",
                                "id" => id)

  params = options.delete(:params) || {}
  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::OrderCancellation.new(unenvelope_body(response.parsed_body), response)
end

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

Creates an order cancellation

Parameters:

  • [required, (Hash)

    a customizable set of options

Returns:

Raises:



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/duffel_api/services/order_cancellations_service.rb', line 11

def create(options = {})
  path = "/air/order_cancellations"

  params = options.delete(:params) || {}
  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::OrderCancellation.new(unenvelope_body(response.parsed_body), response)
end

#get(id, options = {}) ⇒ Resources::OrderCancellation

Retrieves a single order cancellation by ID

Parameters:

  • id (String)

Returns:

Raises:



97
98
99
100
101
102
103
104
105
# File 'lib/duffel_api/services/order_cancellations_service.rb', line 97

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

  response = make_request(:get, path, options)

  return if response.raw_body.nil?

  Resources::OrderCancellation.new(unenvelope_body(response.parsed_body), response)
end

#list(options = {}) ⇒ ListResponse

Lists offers, returning a single page of results.

Parameters:

  • [Hash] (Hash)

    a customizable set of options

Returns:

Raises:



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/duffel_api/services/order_cancellations_service.rb', line 61

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

  response = make_request(:get, path, options)

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