Class: DuffelAPI::Services::AirlinesService

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



33
34
35
36
37
38
39
40
# File 'lib/duffel_api/services/airlines_service.rb', line 33

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

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

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

Retrieves a single airline by ID

Parameters:

  • id (String)

Returns:

Raises:



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

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

  response = make_request(:get, path, options)

  return if response.raw_body.nil?

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

#list(options = {}) ⇒ Object

Lists airports, returning a single page of results

Parameters:

  • [Hash] (Hash)

    a customizable set of options

Raises:



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/duffel_api/services/airlines_service.rb', line 11

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

  response = make_request(:get, path, options)

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