Module: Accuweather

Defined in:
lib/accuweather.rb,
lib/accuweather/version.rb,
lib/accuweather/location/city.rb,
lib/accuweather/location/cache.rb,
lib/accuweather/location/parser.rb,
lib/accuweather/conditions/local.rb,
lib/accuweather/conditions/units.rb,
lib/accuweather/conditions/parser.rb,
lib/accuweather/conditions/current.rb,
lib/accuweather/conditions/planets.rb,
lib/accuweather/conditions/forecast_day.rb,
lib/accuweather/conditions/forecast_weather.rb

Defined Under Namespace

Modules: Conditions, Location Classes: Error

Constant Summary collapse

VERSION =
'0.2.3'

Class Method Summary collapse

Class Method Details

.city_search(name:) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/accuweather.rb', line 19

def self.city_search(name:)
  @cache ||= Accuweather::Location::Cache.new
  cache_result = @cache.cities(name: name)
  return cache_result unless cache_result == []

  response = Net::HTTP.get('samsungmobile.accu-weather.com',
                           "/widget/samsungmobile/city-find.asp?returnGeoPosition=1&location=#{name}")

  Accuweather::Location::Parser.new(response).cities
rescue StandardError => e
  raise Accuweather::Error.new("#{e.class}: #{e.message}")
end

.get_conditions(location_id:, metric: false) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/accuweather.rb', line 32

def self.get_conditions(location_id:, metric: false)
  metric_value = metric ? '1' : '0'
  response = Net::HTTP.get('samsungmobile.accu-weather.com',
                           "/widget/samsungmobile/weather-data.asp?metric=#{metric_value}&location=#{location_id}")

  Accuweather::Conditions::Parser.new(response)
rescue StandardError => e
  raise Accuweather::Error.new("#{e.class}: #{e.message}")
end