Class: OWMO::WeatherResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/owmo/weather_response.rb

Overview

Weather response class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_response) ⇒ WeatherResponse

Returns a new instance of WeatherResponse.



10
11
12
13
14
15
16
17
18
# File 'lib/owmo/weather_response.rb', line 10

def initialize(http_response)
  # JSON
  @weather = JSON.parse(http_response.body)
  @code = parse_code
rescue JSON::ParserError, TypeError
  # Assume XML or HTML
  @weather = http_response.body
  @code = weather.length > 10 ? 200 : 500
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



8
9
10
# File 'lib/owmo/weather_response.rb', line 8

def code
  @code
end

#weatherObject (readonly)

Returns the value of attribute weather.



8
9
10
# File 'lib/owmo/weather_response.rb', line 8

def weather
  @weather
end

Instance Method Details

#error?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/owmo/weather_response.rb', line 20

def error?
  code != 200
end