owmo 2.1.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fde6157e383b210aee0eb881e5607997e2de408d9fd63f36cfb33b84f221599f
4
- data.tar.gz: b1e9310c8f042693cc6ff29abebdb6449d111c7281e7605a47fcb6799d0e7bec
3
+ metadata.gz: 125a82a8915262a016d7b78461f403abf325d76d177d97700e1be023ad3e22eb
4
+ data.tar.gz: 6d47d5e59c2d3b31322a478dc252a33cfdbc88139d86d641f29cc67861d9c88c
5
5
  SHA512:
6
- metadata.gz: 92e3df1af5aedba4b8aeeb2724a134e8dfc5ef13d8208420a3ce2a831cf328b51e93b14330c52a9bc725fb834d7eaaa4867ad4ce610472b3f48436d296f0bc10
7
- data.tar.gz: 8418b07518cebc176310097358f933ccd95269df15c099b017f17c60ea0538afd8d450efbc769208774feb1eea16e3844846ccaf17b36d686695afc55990f38f
6
+ metadata.gz: a574a3a6a6b8f81bb77da1a4e8f10809fe8f43012b214061c269c7c91c22768543357e280d18cc7ef72e0f2cce04f9af35ae3c70c3370f5364257cae4fdd79eb
7
+ data.tar.gz: 9a93faefecb90ae2147ef9d20b2fe1f280ba582fba580e8588d7bf6084ab2e9b400e9b0a2e162c0dfc5efac105860fa8b15e28850d26c4215c7d96c80db4640d
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'json'
4
+ require 'net/http'
4
5
 
5
6
  module CoreExtensions
6
7
  module Net
@@ -17,7 +18,8 @@ module CoreExtensions
17
18
  # Returns the response code
18
19
  def weather_code
19
20
  parse_weather
20
- return (weather['cod'] || '200').to_i if weather.is_a? Hash
21
+
22
+ return (weather['cod'] || '500').to_i if weather.is_a? Hash
21
23
 
22
24
  200
23
25
  end
@@ -59,3 +61,5 @@ module CoreExtensions
59
61
  end
60
62
  end
61
63
  end
64
+
65
+ Net::HTTPResponse.include CoreExtensions::Net::HTTPResponse::WeatherResponse
data/lib/owmo/version.rb CHANGED
@@ -3,5 +3,5 @@
3
3
  module OWMO
4
4
  # rdoc
5
5
  # Gem Version
6
- VERSION = '2.1.0'
6
+ VERSION = '2.1.1'
7
7
  end
data/lib/owmo/weather.rb CHANGED
@@ -1,9 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'core_extensions/net/http_response/weather_response'
4
+
5
+ require 'json'
3
6
  require 'logger'
4
7
  require 'net/http'
5
8
 
6
-
7
9
  module OWMO
8
10
  # rdoc
9
11
  # A weather class for retrieving current and forecasted weather conditions.
@@ -18,7 +20,7 @@ module OWMO
18
20
  # Weather response error to handle errors received from OpenWeatherMap.orgs API
19
21
  class WeatherResponseError < StandardError
20
22
  def initialize(response)
21
- super("ERROR #{response[:cod]}: #{response[:message]}")
23
+ super("ERROR #{response.weather_code}: #{response.message}")
22
24
  end
23
25
  end
24
26
 
@@ -82,11 +84,11 @@ module OWMO
82
84
  uri = format_uri(OWMO::URL, PATHS[path], query)
83
85
 
84
86
  # Get the weather data
85
- weather = http_get(uri)
87
+ response = http_get(uri)
86
88
 
87
- raise WeatherResponseError, weather unless weather.fetch(:cod) == 200
89
+ raise(WeatherResponseError, response) if response.error?
88
90
 
89
- weather
91
+ response.weather
90
92
  end
91
93
 
92
94
  private
@@ -121,7 +123,7 @@ module OWMO
121
123
  http.request(Net::HTTP::Get.new(uri))
122
124
  end
123
125
 
124
- JSON.parse(response.weather)
126
+ response
125
127
  end
126
128
  end
127
129
  # :nocov:
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: owmo
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robb Randall
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-01-02 00:00:00.000000000 Z
11
+ date: 2023-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler