Class: Ellen::Weather::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/ellen/weather/client.rb

Constant Summary collapse

LIVEDOOR_WEATHER_API_URL =
'http://weather.livedoor.com/forecast/webservice/json/v1'
CITIES =
{
  tokyo: 130010,
  chiba: 120010,
  yokohama: 140010
}

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



15
16
17
18
19
20
# File 'lib/ellen/weather/client.rb', line 15

def initialize
  @client = Faraday.new do |connection|
    connection.adapter :net_http
    connection.response :json
  end
end

Instance Method Details

#get(city_name) ⇒ Object



22
23
24
25
26
# File 'lib/ellen/weather/client.rb', line 22

def get(city_name)
  return 'undefined city name' unless city_code = cities[city_name.to_sym]
  response = @client.get("#{url}?city=#{city_code}").body
  response['forecasts'][0]['telop']
end