Class: Yar::Client

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#adapterObject (readonly)

Returns the value of attribute adapter.



7
8
9
# File 'lib/Yar/client.rb', line 7

def adapter
  @adapter
end

#formatObject (readonly)

Returns the value of attribute format.



7
8
9
# File 'lib/Yar/client.rb', line 7

def format
  @format
end

#tokenObject (readonly)

Returns the value of attribute token.



7
8
9
# File 'lib/Yar/client.rb', line 7

def token
  @token
end

Instance Method Details

#carrierObject



25
26
27
# File 'lib/Yar/client.rb', line 25

def carrier
  CarrierResource.new(self)
end

#connectionObject



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


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

def copyright
  CopyrightResource.new(self)
end

#nearestObject



29
30
31
# File 'lib/Yar/client.rb', line 29

def nearest
  NearestResource.new(self)
end

#scheduleObject



33
34
35
# File 'lib/Yar/client.rb', line 33

def schedule
  ScheduleResource.new(self)
end

#stationsObject



21
22
23
# File 'lib/Yar/client.rb', line 21

def stations
  StationsResource.new(self)
end