owmo 2.0.4 → 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: f28d1ded9dc4ec39373a376183985f837af3034fc18780defc7bae3158c6fd82
4
- data.tar.gz: 9de5b4bca2d86f98cc4b252b46c7688f74cbbd55d80b52ecb500426909036174
3
+ metadata.gz: 125a82a8915262a016d7b78461f403abf325d76d177d97700e1be023ad3e22eb
4
+ data.tar.gz: 6d47d5e59c2d3b31322a478dc252a33cfdbc88139d86d641f29cc67861d9c88c
5
5
  SHA512:
6
- metadata.gz: e5adf0b05d8cc03aac2363cfec8eadce4390ba84007b7475d40912fce0711808bae275a34a0b7358afa20ae4f996061ccdca4b418eb9c6bf3c294b4b1da89ff1
7
- data.tar.gz: ff5e5372699efc0668f520f30e9df3f2d2b0c00d7cacd954b6a56726835759d85b8df1c30ee1ede3ca1a28bde423f129094664accffb7a239dd91150bf8cb632
6
+ metadata.gz: a574a3a6a6b8f81bb77da1a4e8f10809fe8f43012b214061c269c7c91c22768543357e280d18cc7ef72e0f2cce04f9af35ae3c70c3370f5364257cae4fdd79eb
7
+ data.tar.gz: 9a93faefecb90ae2147ef9d20b2fe1f280ba582fba580e8588d7bf6084ab2e9b400e9b0a2e162c0dfc5efac105860fa8b15e28850d26c4215c7d96c80db4640d
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")
@@ -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.0.4'
6
+ VERSION = '2.1.1'
7
7
  end
data/lib/owmo/weather.rb CHANGED
@@ -1,13 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'logger'
4
- require 'net/http'
5
-
6
3
  require 'core_extensions/net/http_response/weather_response'
7
4
 
8
- # rdoc
9
- # Include some weather response info into Net::HTTPResponse
10
- Net::HTTPResponse.include CoreExtensions::Net::HTTPResponse::WeatherResponse
5
+ require 'json'
6
+ require 'logger'
7
+ require 'net/http'
11
8
 
12
9
  module OWMO
13
10
  # rdoc
@@ -23,8 +20,7 @@ module OWMO
23
20
  # Weather response error to handle errors received from OpenWeatherMap.orgs API
24
21
  class WeatherResponseError < StandardError
25
22
  def initialize(response)
26
- @response = response
27
- super("ERROR #{@response.weather_code}: #{@response.weather_message}")
23
+ super("ERROR #{response.weather_code}: #{response.message}")
28
24
  end
29
25
  end
30
26
 
@@ -88,7 +84,11 @@ module OWMO
88
84
  uri = format_uri(OWMO::URL, PATHS[path], query)
89
85
 
90
86
  # Get the weather data
91
- GET(uri)
87
+ response = http_get(uri)
88
+
89
+ raise(WeatherResponseError, response) if response.error?
90
+
91
+ response.weather
92
92
  end
93
93
 
94
94
  private
@@ -117,15 +117,14 @@ module OWMO
117
117
 
118
118
  # rdoc
119
119
  # Sends the GET request to OpenWeatherMap.org
120
- def GET(uri)
120
+ # :nocov:
121
+ def http_get(uri)
121
122
  response = Net::HTTP.start(uri.hostname, uri.port) do |http|
122
123
  http.request(Net::HTTP::Get.new(uri))
123
124
  end
124
125
 
125
- # Check the response
126
- raise WeatherResponseError, response if response.error?
127
-
128
- response.weather
126
+ response
129
127
  end
130
128
  end
129
+ # :nocov:
131
130
  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.4
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: 2022-12-30 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
@@ -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