Class: Rasp::Yandex::Client
- Inherits:
-
Object
- Object
- Rasp::Yandex::Client
- Defined in:
- lib/rasp/yandex.rb
Constant Summary collapse
- URL =
"https://api.rasp.yandex.net"
Instance Method Summary collapse
- #all_stations(default_params = nil) ⇒ Object
- #copyright_yandex_rasp(format) ⇒ Object
- #information_about_carrier(code, default_params = nil) ⇒ Object
-
#initialize(api_key = nil, api_version = nil) ⇒ Client
constructor
A new instance of Client.
- #near_city(latitude, longitude, distance = nil, default_params = nil) ⇒ Object
- #near_stations(latitude, longitude, distance, default_params = nil) ⇒ Object
- #stations_of_route(uid, default_params = nil) ⇒ Object
- #timetable_at_station(station, date = nil, default_params = nil) ⇒ Object
- #timetable_between_stations(from, to, date = nil, default_params = nil) ⇒ Object
Constructor Details
#initialize(api_key = nil, api_version = nil) ⇒ Client
Returns a new instance of Client.
12 13 14 15 16 |
# File 'lib/rasp/yandex.rb', line 12 def initialize(api_key = nil, api_version = nil) @api_key = api_key || ENV["RASP_YANDEX_API_KEY"] @api_version = "3.0" || ENV["RASP_YANDEX_API_VERSION"] end |
Instance Method Details
#all_stations(default_params = nil) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/rasp/yandex.rb', line 18 def all_stations(default_params = nil) conn = Faraday.new(url: URL) do |faraday| faraday.request :url_encoded faraday.response :json, content_type: /\bjson$/ faraday.adapter Faraday.default_adapter end conn.get "/v#{@api_version}/stations_list/?apikey=#{@api_key}", default_params end |
#copyright_yandex_rasp(format) ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'lib/rasp/yandex.rb', line 81 def copyright_yandex_rasp(format) conn = Faraday.new(url: URL) do |faraday| faraday.request :url_encoded faraday.response :json, content_type: /\bjson$/ faraday.adapter Faraday.default_adapter end conn.get "v#{@api_key}/copyright/?apikey=#{@api_key}&format=#{format}" end |
#information_about_carrier(code, default_params = nil) ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'lib/rasp/yandex.rb', line 72 def information_about_carrier(code, default_params = nil) conn = Faraday.new(url: URL) do |faraday| faraday.request :url_encoded faraday.response :json, content_type: /\bjson$/ faraday.adapter Faraday.default_adapter end conn.get "/v#{@api_version}/carrier/?apikey=#{@api_key}&code=#{code}", default_params end |
#near_city(latitude, longitude, distance = nil, default_params = nil) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/rasp/yandex.rb', line 54 def near_city(latitude, longitude, distance = nil, default_params = nil) conn = Faraday.new(url: URL) do |faraday| faraday.request :url_encoded faraday.response :json, content_type: /\bjson$/ faraday.adapter Faraday.default_adapter end conn.get "/v#{@api_version}/nearest_settlement/?apikey=#{@api_key}&lat=#{latitude}&lng=#{longitude}&distance=#{distance}", default_params end |
#near_stations(latitude, longitude, distance, default_params = nil) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/rasp/yandex.rb', line 45 def near_stations(latitude, longitude, distance, default_params = nil) conn = Faraday.new(url: URL) do |faraday| faraday.request :url_encoded faraday.response :json, content_type: /\bjson$/ faraday.adapter Faraday.default_adapter end conn.get "/v#{@api_version}/nearest_stations/?apikey=#{@api_key}&lat=#{latitude}&lng=#{longitude}&distance=#{distance}", default_params end |
#stations_of_route(uid, default_params = nil) ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/rasp/yandex.rb', line 63 def stations_of_route(uid, default_params = nil) conn = Faraday.new(url: URL) do |faraday| faraday.request :url_encoded faraday.response :json, content_type: /\bjson$/ faraday.adapter Faraday.default_adapter end conn.get "/v#{@api_version}/thread/?apikey=#{@api_key}&uid=#{uid}", default_params end |
#timetable_at_station(station, date = nil, default_params = nil) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/rasp/yandex.rb', line 36 def (station, date = nil, default_params = nil) conn = Faraday.new(url: URL) do |faraday| faraday.request :url_encoded faraday.response :json, content_type: /\bjson$/ faraday.adapter Faraday.default_adapter end conn.get "/v#{@api_version}/schedule/?apikey=#{@api_key}&station=#{station}&date=#{date}", default_params end |
#timetable_between_stations(from, to, date = nil, default_params = nil) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/rasp/yandex.rb', line 27 def (from, to, date = nil, default_params = nil) conn = Faraday.new(url: URL) do |faraday| faraday.request :url_encoded faraday.response :json, content_type: /\bjson$/ faraday.adapter Faraday.default_adapter end conn.get "/v#{@api_version}/search/?apikey=#{@api_key}&from=#{from}&to=#{to}&date=#{date}", default_params end |