Class: OWMO::WeatherResponse
- Inherits:
-
Object
- Object
- OWMO::WeatherResponse
- Defined in:
- lib/owmo/weather_response.rb
Overview
Weather response class
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#weather ⇒ Object
readonly
Returns the value of attribute weather.
Instance Method Summary collapse
- #error? ⇒ Boolean
-
#initialize(http_response) ⇒ WeatherResponse
constructor
A new instance of WeatherResponse.
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
#code ⇒ Object (readonly)
Returns the value of attribute code.
8 9 10 |
# File 'lib/owmo/weather_response.rb', line 8 def code @code end |
#weather ⇒ Object (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
20 21 22 |
# File 'lib/owmo/weather_response.rb', line 20 def error? code != 200 end |