owmo 2.0.3 → 2.1.0

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: b7e4b64ccdb32db93f751f28f7c07923244770d68eda25301b1939ac21de38bb
4
- data.tar.gz: f67520f2b29f4bbf95f0bef27a60827fd1f04906ab2fa72da49a7ebefc834f3f
3
+ metadata.gz: fde6157e383b210aee0eb881e5607997e2de408d9fd63f36cfb33b84f221599f
4
+ data.tar.gz: b1e9310c8f042693cc6ff29abebdb6449d111c7281e7605a47fcb6799d0e7bec
5
5
  SHA512:
6
- metadata.gz: e072a5ccce24a3c24032b5d88141feabe29806e6f1825c21700b751b5a9b91e3f43e9218cbed9bcd0a095b9335115979da775374d7093ec46059a51185cff42a
7
- data.tar.gz: 1cd83a94eec07bfcb4d9a96d0a087395fea3b7f4a227cc8665bad66175a9fc4738d3c3813c25db1967768db2a7e32d8488fa857282b957cc1b43dc8bf2cb6e39
6
+ metadata.gz: 92e3df1af5aedba4b8aeeb2724a134e8dfc5ef13d8208420a3ce2a831cf328b51e93b14330c52a9bc725fb834d7eaaa4867ad4ce610472b3f48436d296f0bc10
7
+ data.tar.gz: 8418b07518cebc176310097358f933ccd95269df15c099b017f17c60ea0538afd8d450efbc769208774feb1eea16e3844846ccaf17b36d686695afc55990f38f
data/CONTRIBUTING.MD ADDED
@@ -0,0 +1,10 @@
1
+ ----
2
+ ## Development
3
+
4
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
5
+
6
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
7
+
8
+ ## Contributing
9
+
10
+ Bug reports and pull requests are welcome on GitHub at https://github.com/robb-randall/owmo.
data/Gemfile CHANGED
@@ -4,4 +4,5 @@ source 'https://rubygems.org'
4
4
 
5
5
  gemspec
6
6
 
7
+ gem 'rspec'
7
8
  gem 'simplecov', require: false, group: :test
data/README.md CHANGED
@@ -153,18 +153,6 @@ Then navigate to: http://localhost:4567/current/London,UK
153
153
 
154
154
  [Full example](https://github.com/robb-randall/owmo/blob/master/examples/sinatra_example.rb)
155
155
 
156
- ----
157
- ## Development
158
-
159
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
160
-
161
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
162
-
163
- ## Contributing
164
-
165
- Bug reports and pull requests are welcome on GitHub at https://github.com/robb-randall/owmo.
166
-
167
-
168
156
  ## License
169
157
 
170
158
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/bin/rspec ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rspec' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
12
+
13
+ bundle_binstub = File.expand_path("bundle", __dir__)
14
+
15
+ if File.file?(bundle_binstub)
16
+ if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
17
+ load(bundle_binstub)
18
+ else
19
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
20
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
21
+ end
22
+ end
23
+
24
+ require "rubygems"
25
+ require "bundler/setup"
26
+
27
+ load Gem.bin_path("rspec-core", "rspec")
data/lib/owmo/version.rb CHANGED
@@ -3,5 +3,5 @@
3
3
  module OWMO
4
4
  # rdoc
5
5
  # Gem Version
6
- VERSION = '2.0.3'
6
+ VERSION = '2.1.0'
7
7
  end
data/lib/owmo/weather.rb CHANGED
@@ -3,11 +3,6 @@
3
3
  require 'logger'
4
4
  require 'net/http'
5
5
 
6
- require 'core_extensions/net/http_response/weather_response'
7
-
8
- # rdoc
9
- # Include some weather response info into Net::HTTPResponse
10
- Net::HTTPResponse.include CoreExtensions::Net::HTTPResponse::WeatherResponse
11
6
 
12
7
  module OWMO
13
8
  # rdoc
@@ -23,8 +18,7 @@ module OWMO
23
18
  # Weather response error to handle errors received from OpenWeatherMap.orgs API
24
19
  class WeatherResponseError < StandardError
25
20
  def initialize(response)
26
- @response = response
27
- super("ERROR #{@response.weather_code}: #{@response.weather_message}")
21
+ super("ERROR #{response[:cod]}: #{response[:message]}")
28
22
  end
29
23
  end
30
24
 
@@ -79,7 +73,7 @@ module OWMO
79
73
 
80
74
  def get(path, **query)
81
75
  # Format Geocode info
82
- query = alias_geocodes(query)
76
+ query = alias_geocodes(**query)
83
77
 
84
78
  # Add the api key
85
79
  query[:APPID] = api_key
@@ -88,7 +82,11 @@ module OWMO
88
82
  uri = format_uri(OWMO::URL, PATHS[path], query)
89
83
 
90
84
  # Get the weather data
91
- GET(uri)
85
+ weather = http_get(uri)
86
+
87
+ raise WeatherResponseError, weather unless weather.fetch(:cod) == 200
88
+
89
+ weather
92
90
  end
93
91
 
94
92
  private
@@ -103,7 +101,7 @@ module OWMO
103
101
  # Aliases some geocode parameters to the correct ones, for example :city_name is
104
102
  # easier to read than :q
105
103
  def alias_geocodes(**query)
106
- query_geocode_keys(query).each do |key|
104
+ query_geocode_keys(**query).each do |key|
107
105
  query[GEOCODE_ALIASES[key]] = query.delete(key)
108
106
  end
109
107
  query
@@ -117,15 +115,14 @@ module OWMO
117
115
 
118
116
  # rdoc
119
117
  # Sends the GET request to OpenWeatherMap.org
120
- def GET(uri)
118
+ # :nocov:
119
+ def http_get(uri)
121
120
  response = Net::HTTP.start(uri.hostname, uri.port) do |http|
122
121
  http.request(Net::HTTP::Get.new(uri))
123
122
  end
124
123
 
125
- # Check the response
126
- raise WeatherResponseError, response if response.error?
127
-
128
- response.weather
124
+ JSON.parse(response.weather)
129
125
  end
130
126
  end
127
+ # :nocov:
131
128
  end
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.0.3
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robb Randall
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-29 00:00:00.000000000 Z
11
+ date: 2023-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -64,12 +64,14 @@ files:
64
64
  - ".gitignore"
65
65
  - ".rspec"
66
66
  - ".travis.yml"
67
+ - CONTRIBUTING.MD
67
68
  - Gemfile
68
69
  - LICENSE.txt
69
70
  - README.md
70
71
  - Rakefile
71
72
  - _config.yml
72
73
  - bin/console
74
+ - bin/rspec
73
75
  - bin/setup
74
76
  - examples/current.rb
75
77
  - examples/current_box.rb