Class: Gillbus::V2::Client
- Inherits:
-
Object
- Object
- Gillbus::V2::Client
- Defined in:
- lib/gillbus/v2/client.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
Instance Method Summary collapse
- #authenticate(username:, password:, lang:, time_zone:) ⇒ Object
- #authenticate!(**args) ⇒ Object
- #authenticated? ⇒ Boolean
- #get_locations(langs: %w[en], limit_for_page: 50, from_datetime: nil) ⇒ Object
- #get_locations_page(pagination_uuid:, page_number:) ⇒ Object
- #get_trip_seats(trip_id:, date:, back_date: nil, passengers_count: 1) ⇒ Object
-
#initialize(base_url:, access_token: nil) ⇒ Client
constructor
A new instance of Client.
-
#search_trips(from_id:, to_id:, date:, back_date: nil, passengers_count: 1, search_mode: "full", limit_for_page: 20) ⇒ Object
search_mode: - full - искать все рейсы (по умолчанию) - direct - искать только прямые рейсы.
- #search_trips_page(pagination_uuid:, page_number:) ⇒ Object
Constructor Details
#initialize(base_url:, access_token: nil) ⇒ Client
Returns a new instance of Client.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/gillbus/v2/client.rb', line 6 def initialize(base_url:, access_token: nil) @base_url = base_url @access_token = if access_token.is_a?(Structs::AccessToken) access_token elsif access_token.is_a?(String) Structs::AccessToken.from_token_string(access_token) elsif access_token.is_a?(Hash) Structs::AccessToken.from_raw_data(access_token) end end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
4 5 6 |
# File 'lib/gillbus/v2/client.rb', line 4 def access_token @access_token end |
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
3 4 5 |
# File 'lib/gillbus/v2/client.rb', line 3 def base_url @base_url end |
Instance Method Details
#authenticate(username:, password:, lang:, time_zone:) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/gillbus/v2/client.rb', line 22 def authenticate(username:, password:, lang:, time_zone:) params = { username: username, password: password, lang: lang, timeZone: time_zone, } response = call_api(:post, "/v2/login", params, auth_required: false, response_class: Responses::Authenticate, ) @access_token = response.access_token response end |
#authenticate!(**args) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/gillbus/v2/client.rb', line 37 def authenticate!(**args) response = authenticate(**args) unless authenticated? raise AuthenticationFailed, response. end end |
#authenticated? ⇒ Boolean
18 19 20 |
# File 'lib/gillbus/v2/client.rb', line 18 def authenticated? !access_token.nil? && !access_token.expired? end |
#get_locations(langs: %w[en], limit_for_page: 50, from_datetime: nil) ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/gillbus/v2/client.rb', line 44 def get_locations(langs: %w[en], limit_for_page: 50, from_datetime: nil) params = { lang_array: langs, limit: limit_for_page, timestamp: from_datetime&.rfc3339, } call_api(:get, "/geo/v2/locations", params, response_class: Responses::Locations, ) end |
#get_locations_page(pagination_uuid:, page_number:) ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/gillbus/v2/client.rb', line 55 def get_locations_page(pagination_uuid:, page_number:) params = { page_uuid: pagination_uuid, number_page: page_number, } call_api(:get, "/geo/v2/locations/page", params, response_class: Responses::Locations, ) end |
#get_trip_seats(trip_id:, date:, back_date: nil, passengers_count: 1) ⇒ Object
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/gillbus/v2/client.rb', line 93 def get_trip_seats(trip_id:, date:, back_date: nil, passengers_count: 1) params = { date: date, back_date: back_date, pass_count: passengers_count, } call_api(:get, "/search/v2/trips/#{trip_id}/seats", params, response_class: Responses::TripSeats, ) end |
#search_trips(from_id:, to_id:, date:, back_date: nil, passengers_count: 1, search_mode: "full", limit_for_page: 20) ⇒ Object
search_mode:
-
full - искать все рейсы (по умолчанию)
-
direct - искать только прямые рейсы
68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/gillbus/v2/client.rb', line 68 def search_trips(from_id:, to_id:, date:, back_date: nil, passengers_count: 1, search_mode: "full", limit_for_page: 20) params = { from_id: from_id, to_id: to_id, date: date.iso8601, back_date: back_date&.iso8601, pass_count: passengers_count, search_mode: search_mode, limit: limit_for_page, } call_api(:get, "/search/v2/trips", params, response_class: Responses::SearchTrips, ) end |
#search_trips_page(pagination_uuid:, page_number:) ⇒ Object
83 84 85 86 87 88 89 90 91 |
# File 'lib/gillbus/v2/client.rb', line 83 def search_trips_page(pagination_uuid:, page_number:) params = { page_uuid: pagination_uuid, number_page: page_number, } call_api(:get, "/search/v2/trips/page", params, response_class: Responses::SearchTrips, ) end |