Class: Yar::Client
- Inherits:
-
Object
- Object
- Yar::Client
- Defined in:
- lib/Yar/client.rb,
lib/yar/client.rb
Constant Summary collapse
- BASE_URL =
"https://api.rasp.yandex.net/v3.0/"
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #carrier ⇒ Object
- #connection ⇒ Object
- #copyright ⇒ Object
-
#initialize(token:, adapter: Faraday.default_adapter, stubs: nil, format: "json") ⇒ Client
constructor
new client.
- #nearest ⇒ Object
- #schedule ⇒ Object
- #stations ⇒ Object
Constructor Details
#initialize(token:, adapter: Faraday.default_adapter, stubs: nil, format: "json") ⇒ Client
new client
10 11 12 13 14 15 |
# File 'lib/Yar/client.rb', line 10 def initialize(token:, adapter: Faraday.default_adapter, stubs: nil, format: "json") @token = token @adapter = adapter @stubs = stubs @format = format end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
7 8 9 |
# File 'lib/Yar/client.rb', line 7 def adapter @adapter end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
7 8 9 |
# File 'lib/Yar/client.rb', line 7 def format @format end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
7 8 9 |
# File 'lib/Yar/client.rb', line 7 def token @token end |
Instance Method Details
#carrier ⇒ Object
25 26 27 |
# File 'lib/Yar/client.rb', line 25 def carrier CarrierResource.new(self) end |
#connection ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/Yar/client.rb', line 37 def connection @connection ||= Faraday.new(BASE_URL) do |conn| conn.request :authorization, nil, token conn.request :json conn.request :url_encoded # conn.params[:format] = @format conn.response :json, content_type: "application/json" conn.response :xml, content_type: "application/xml" if @format == "xml" conn.adapter adapter, @stubs end end |
#copyright ⇒ Object
17 18 19 |
# File 'lib/Yar/client.rb', line 17 def copyright CopyrightResource.new(self) end |
#nearest ⇒ Object
29 30 31 |
# File 'lib/Yar/client.rb', line 29 def nearest NearestResource.new(self) end |
#schedule ⇒ Object
33 34 35 |
# File 'lib/Yar/client.rb', line 33 def schedule ScheduleResource.new(self) end |
#stations ⇒ Object
21 22 23 |
# File 'lib/Yar/client.rb', line 21 def stations StationsResource.new(self) end |