Class: DuffelAPI::Services::OrderCancellationsService

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



57
58
59
60
61
62
# File 'lib/duffel_api/services/order_cancellations_service.rb', line 57

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

#confirm(id, options = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/duffel_api/services/order_cancellations_service.rb', line 25

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



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/duffel_api/services/order_cancellations_service.rb', line 6

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



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

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



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/duffel_api/services/order_cancellations_service.rb', line 45

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