owmo 2.0.3 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CONTRIBUTING.MD +10 -0
- data/Gemfile +1 -0
- data/README.md +0 -12
- data/bin/rspec +27 -0
- data/lib/owmo/version.rb +1 -1
- data/lib/owmo/weather.rb +12 -15
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fde6157e383b210aee0eb881e5607997e2de408d9fd63f36cfb33b84f221599f
|
4
|
+
data.tar.gz: b1e9310c8f042693cc6ff29abebdb6449d111c7281e7605a47fcb6799d0e7bec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
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
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
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:
|
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
|