Class: Gdsapi::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/gdsapi/client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(requester) ⇒ Client

It is ‘strongly recommended` to use Faraday(see ##with_faraday_requester)

Parameters:



8
9
10
# File 'lib/gdsapi/client.rb', line 8

def initialize(requester)
  @requester = requester
end

Instance Attribute Details

#requesterObject (readonly)

Returns the value of attribute requester.



4
5
6
# File 'lib/gdsapi/client.rb', line 4

def requester
  @requester
end

Class Method Details

.with_faraday_requester(base_url: nil, login: nil, password: nil, language: nil) ⇒ Object

Constructing routine that uses Faraday as driver

Parameters:

  • base_url: (defaults to: nil)

    url param for Faraday(requred)

  • login: (defaults to: nil)

    & password: - HTTP basic auth factors

  • language: (defaults to: nil)
    • language slug for which request will be performed (available are: en, ru, uk, pl, th)



17
18
19
20
# File 'lib/gdsapi/client.rb', line 17

def with_faraday_requester(base_url: nil, login: nil, password: nil, language: nil)
  driver = Faraday.new(url: base_url)
  new(Requester.new(driver, login: , password: password, language: language))
end

.with_requester(driver, login: nil, password: nil, language: nil, prefix: '/api/v2/') ⇒ Object

Constructing routine that uses given driver

Parameters:

  • driver
    • driver instance

  • login: (defaults to: nil)

    & password: - HTTP basic auth factors

  • language: (defaults to: nil)
    • language slug for which request will be performed (available are: en, ru, uk, pl, th)



26
27
28
# File 'lib/gdsapi/client.rb', line 26

def with_requester(driver, login: nil, password: nil, language: nil, prefix: '/api/v2/')
  new(Requester.new(driver, login: , password: password, language: language, prefix: prefix))
end

Instance Method Details

#get_available_trips(**args) ⇒ Object

GDS Method used to check availability of trips For more information, see [demo.gillbus.com/v2/doc.html#поиск-рейсов-доступность-рейсов-get]

Parameters:

  • args
    • keyword args:

    :arrival [String] - GDS arrival point id (required) :departure [String] - GDS departure point id (required) :tickets [Number] - number of tickets for trip (required) :mode [Number] - transport type (optional, buses are: 1,8) :dates [String] - dates for trip (required, format: yyyy-mm-dd, delimiter: ‘;’) :return_only_branded [Boolean] - returns data only for branded trips if true



79
80
81
# File 'lib/gdsapi/client.rb', line 79

def get_available_trips(**args)
  Methods::GetAvailableTrips.new(requester).call(**args)
end

#get_countries(**args) ⇒ Object

GDS Method used to fetch GDS countries For more information, see [demo.gillbus.com/v2/doc.html#получение-географии-страны-get]

Parameters:

  • args
    • keyword args:

    :offset [Number|String] - number of records to be skipped when fetching chunks (optional) :limit [Number|String] - number of records to be fetched when fetching chunks (optional)



66
67
68
# File 'lib/gdsapi/client.rb', line 66

def get_countries(**args)
  Methods::GetCountries.new(requester).call(**args)
end

#get_locations(**args) ⇒ Object

GDS Method used to fetch GDS locations For more information, see [demo.gillbus.com/v2/doc.html#получение-географии-получение-списка-остановок-get]

Parameters:

  • args
    • keyword args:

    :country [Number|String] - GDS country id for which locations are fetched (optional) :offset [Number|String] - number of records to be skipped when fetching chunks (optional) :limit [Number|String] - number of records to be fetched when fetching chunks (optional) :timestamp [String] - temporal checkpoint(i.e. date, records from which are interested)

    (optional, format: yyyy-MM-dd’T’HH:mm:ssZ, GMT+2)
    


44
45
46
# File 'lib/gdsapi/client.rb', line 44

def get_locations(**args)
  Methods::GetLocations.new(requester).call(**args)
end

#get_points(**args) ⇒ Object

GDS Method used to fetch GDS points For more information, see [demo.gillbus.com/v2/doc.html#получение-географии-получение-списка-остановок-get]

Parameters:

  • args
    • keyword args:

    :country [Number|String] - GDS country id for which points are fetched (optional) :location [Number|String] - GDS location id for which points are fetched (optional) :offset [Number|String] - number of records to be skipped when fetching chunks (optional) :limit [Number|String] - number of records to be fetched when fetching chunks (optional) :timestamp [String] - temporal checkpoint(i.e. date, records from which are interested)

    (optional, format: yyyy-MM-dd’T’HH:mm:ssZ, GMT+2)
    


57
58
59
# File 'lib/gdsapi/client.rb', line 57

def get_points(**args)
  Methods::GetPoints.new(requester).call(**args)
end

#language=(value) ⇒ Object

Ad-hoc solution for adding multilanguage support



32
33
34
# File 'lib/gdsapi/client.rb', line 32

def language=(value)
  requester.language = value
end