Gdsapi::V2::Ruby

Driver for API.GDS.BUSFOR v2

Development usage

1) Run

    bin/setup

2) Fill in fields in credentials.json 3) Run

    bin/console

Now you can use client instance for querying GDS

How to use Client

Create Gdsapi::V2::Client instance

(NOTE: you can use method #client in bin/console)

Using Faraday

Suppose you want to use Faraday as HTTP Driver. So to instantiate client, you can use Gdsapi::V2::Client#with_faraday_requester method:

Gdsapi::V2::Client.with_faraday_requester base_url: 'https://example.com', login: 'login', password: 'password', language: 'en'
=> #<Gdsapi::V2::Client:0x007fe3bf1e8d68 @requester=#<Gdsapi::V2::Requester:0x007fe3bf1e9330 @driver=#<Faraday::Connection:0x007fe3bf1eafc8 @parallel_manager=nil, @headers={"User-Agent"=>"Faraday v0.12.1", "Accept-Language"=>"en", "Authorization"=>"Basic bG9naW46cGFzc3dvcmQ="}, @params={}, @options=#<Faraday::RequestOptions (empty)>, @ssl=#<Faraday::SSLOptions (empty)>, @default_parallel_manager=nil, @builder=#<Faraday::RackBuilder:0x007fe3bf1ea640 @handlers=[Faraday::Request::UrlEncoded, Faraday::Adapter::NetHttp]>, @url_prefix=#<URI::HTTPS https://example.com/>, @proxy=nil>, @login="login", @password="password", @language="en">>

available arguments are:

  • :base_url - url param for Faraday(requred)
  • :login & :password - HTTP basic auth factors
  • :language: - language slug for which request will be performed (available are: en, ru, uk, pl, th) ### Using custom driver If you want to use custom driver, you can do Gdsapi::V2::Client#with_faraday_requester method: ruby driver_instance = Faraday.new url: 'https://example.com' => #<Faraday::Connection:0x007fe3bf18be88 @parallel_manager=nil, @headers={"User-Agent"=>"Faraday v0.12.1"}, @params={}, @options=#<Faraday::RequestOptions (empty)>, @ssl=#<Faraday::SSLOptions (empty)>, @default_parallel_manager=nil, @builder=#<Faraday::RackBuilder:0x007fe3bf189c28 @handlers=[Faraday::Request::UrlEncoded, Faraday::Adapter::NetHttp]>, @url_prefix=#<URI::HTTPS https://example.com/>, @proxy=nil> Gdsapi::V2::Client.with_requester driver_instance, login: 'login', password: 'password', language: 'en' => #<Gdsapi::V2::Client:0x007fe3c07172e8 @requester=#<Gdsapi::V2::Requester:0x007fe3c07176f8 @driver=#<Faraday::Connection:0x007fe3bf18be88 @parallel_manager=nil, @headers={"User-Agent"=>"Faraday v0.12.1", "Accept-Language"=>"en", "Authorization"=>"Basic bG9naW46cGFzc3dvcmQ="}, @params={}, @options=#<Faraday::RequestOptions (empty)>, @ssl=#<Faraday::SSLOptions (empty)>, @default_parallel_manager=nil, @builder=#<Faraday::RackBuilder:0x007fe3bf189c28 @handlers=[Faraday::Request::UrlEncoded, Faraday::Adapter::NetHttp]>, @url_prefix=#<URI::HTTPS https://example.com/>, @proxy=nil>, @login="login", @password="password", @language="en">> available keyword arguments are:
  • :login & :password - HTTP basic auth factors
  • :language - language slug for which request will be performed (available are: en, ru, uk, pl, th)

driver instance should respond to:

  • get(url, params, headers) = post(url, body, params)
  • basic_auth(login, password)
  • querying and modifying #headers in Hash-style

Use Gdsapi::V2::Client instance

#get_locations

Fetch GDS locations edited after given timestamp. If timestamp is not given, all results are returned in 'upsert' mode.

Returns hash with :upsert and :delete keys, for update or inserting mode and deleting mode respectively. Values for hash are Location objects.

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

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)
client.get_locations limit: 5, offset: 15
=> {:upsert=>[#<Gdsapi::V2::Structs::Location id="3642" name="Кречев" latitude=50.67921380000001 longitude=24.0974334 parent={:id=>"1330"} type={:id=>"6", :name=>"населённый пункт"} sub_type={:id=>"10", :name=>"с."} attributes=[{:id=>"6", :name=>"KOATUU (Ukraine)", :values=>["0721183202"]}]>, #<Gdsapi::V2::Structs::Location id="3643" name="Морозовичи" latitude=50.7066762 longitude=24.1291352 parent={:id=>"1330"} type={:id=>"6", :name=>"населённый пункт"} sub_type={:id=>"10", :name=>"с."} attributes=[{:id=>"6", :name=>"KOATUU (Ukraine)", :values=>["0721183301"]}]>, #<Gdsapi::V2::Structs::Location id="3644" name="Волица-Морозовицкая" latitude=50.7207646 longitude=24.1088641 parent={:id=>"1330"} type={:id=>"6", :name=>"населённый пункт"} sub_type={:id=>"10", :name=>"с."} attributes=[{:id=>"6", :name=>"KOATUU (Ukraine)", :values=>["0721183303"]}]>, #<Gdsapi::V2::Structs::Location id="3645" name="Русовичи" latitude=50.7196979 longitude=24.1388295 parent={:id=>"1330"} type={:id=>"6", :name=>"населённый пункт"} sub_type={:id=>"10", :name=>"с."} attributes=[{:id=>"6", :name=>"KOATUU (Ukraine)", :values=>["0721183305"]}]>, #<Gdsapi::V2::Structs::Location id="3646" name="Мышев" latitude=50.6814711 longitude=24.3183851 parent={:id=>"1330"} type={:id=>"6", :name=>"населённый пункт"} sub_type={:id=>"10", :name=>"с."} attributes=[{:id=>"6", :name=>"KOATUU (Ukraine)", :values=>["0721183401"]}]>]}

#get_points

Fetch GDS points edited after given timestamp. If timestamp is not given, all results are returned in 'upsert' mode.

Returns hash with :upsert and :delete keys, for update or inserting mode and deleting mode respectively. Values for hash are Point objects.

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

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)
client.get_points limit: 5, offset: 5
=> {:upsert=>[#<Gdsapi::V2::Structs::Point id="981165" name="Остановка Патинская" latitude=61.577575 longitude=46.304784 parent={:id=>"72788"} address="Остановка Патинская">, #<Gdsapi::V2::Structs::Point id="981166" name="Остановка Перекоп" latitude=61.589032 longitude=46.372445 parent={:id=>"72789"} address="Остановка Перекоп">, #<Gdsapi::V2::Structs::Point id="981157" name="Остановка Микшино" latitude=61.582234 longitude=46.355782 parent={:id=>"72780"} address="Остановка Микшино">, #<Gdsapi::V2::Structs::Point id="981158" name="Остановка Мичкинская" latitude=61.619846 longitude=46.475554 parent={:id=>"7278

#get_countries

Fetch GDS countries

Returns set of Country objects

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)
client.get_countries limit: 5, offset: 10
=> [#<Gdsapi::V2::Structs::Country id="350" name="Пуэрто-Рико" type={:id=>"1", :name=>"страна"} attributes=[{:id=>"2", :name=>"globus_locality_id", :values=>["22160"]}, {:id=>"5", :name=>"FIPS_Code", :values=>["RQ"]}]>, #<Gdsapi::V2::Structs::Country id="351" name="Реюньон" type={:id=>"1", :name=>"страна"} attributes=[{:id=>"2", :name=>"globus_locality_id", :values=>["22084"]}]>, #<Gdsapi::V2::Structs::Country id="352" name="Сен-Бартелеми" type={:id=>"1", :name=>"страна"} attributes=[{:id=>"2", :name=>"globus_locality_id", :values=>["27236"]}, {:id=>"5", :name=>"FIPS_Code", :values=>["TB"]}]>, #<Gdsapi::V2::Structs::Country id="110" name="Мали" type={:id=>"1", :name=>"страна"} attributes=[{:id=>"2", :name=>"globus_locality_id", :values=>["22342"]}, {:id=>"3", :name=>"GENC_2A_Code", :values=>["ML"]}, {:id=>"4", :name=>"GENC_3A_Code", :values=>["MLI"]}]>, #<Gdsapi::V2::Structs::Country id="353" name="О́стров Свято́й Еле́ны" type={:id=>"1", :name=>"страна"} attributes=[{:id=>"2", :name=>"globus_locality_id", :values=>["27895"]}, {:id=>"5", :name=>"FIPS_Code", :values=>["SH"]}]>]

#get_available trips

Check Availability of trips

Returns set of available dates for specified trip

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
client.get_available_trips arrival: 'A7CD147C07E7CD1BE040A8C0630328EC', 
                           departure: 'CA975BC2ACDBCF7FE040B859C14327B3', 
                           tickets: 2, 
                           dates: '2017-06-22;2017-06-23'
=> ["2017-06-22", "2017-06-23"]