owmo 2.1.2 → 2.1.5
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/.github/workflows/{ruby-publish-gem.yml → rake-release.yml} +3 -3
- data/.github/workflows/rake.yml +23 -0
- data/.gitignore +1 -2
- data/.rubocop.yml +7 -0
- data/Gemfile +7 -0
- data/Rakefile +6 -1
- data/bin/examples +65 -32
- data/bin/rake +27 -0
- data/bin/rspec +6 -6
- data/bin/rubocop +27 -0
- data/lib/owmo/version.rb +1 -1
- data/lib/owmo/weather.rb +1 -3
- data/lib/owmo/weather_response.rb +27 -20
- data/owmo.gemspec +2 -1
- metadata +10 -6
- data/.github/workflows/ruby.yml +0 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7206b29a014088dd08403d1199d6b410a4d2d2e7dd1087290058d542add26f79
|
4
|
+
data.tar.gz: 0115ffba7abd0eca441f6117c2cb20561a09c2556b606af56c1cde829372fe7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48059ce954439c46e4c19edc050c9b0d8193caf6b9e464726b255f88aa42b5591dc69b6bbd17c227728bf89a16e4c8adfe744ad0891d1f9bd448c6250ceadc01
|
7
|
+
data.tar.gz: 73af163549823603d7222ed682367c91baa4dab7276bd2bcd318ede49e435b03c4480abb318e3425cec3a5ace4dd8f5c393a5591622c519a8cc75c8e86a9c5e6
|
@@ -1,4 +1,4 @@
|
|
1
|
-
name: Publish
|
1
|
+
name: Publish to Rubygems
|
2
2
|
|
3
3
|
on:
|
4
4
|
push:
|
@@ -13,9 +13,9 @@ jobs:
|
|
13
13
|
steps:
|
14
14
|
- uses: actions/checkout@v3
|
15
15
|
|
16
|
-
- name:
|
16
|
+
- name: Publish to Rubygems
|
17
17
|
if: contains(github.ref, 'refs/tags/v')
|
18
|
-
uses: cadwallion/publish-rubygems-action@
|
18
|
+
uses: cadwallion/publish-rubygems-action@v1.0.0
|
19
19
|
env:
|
20
20
|
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
21
21
|
RUBYGEMS_API_KEY: ${{secrets.RUBYGEMS_API_KEY}}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
name: Ruby CI
|
2
|
+
|
3
|
+
on: [push]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
test:
|
7
|
+
|
8
|
+
runs-on: ubuntu-latest
|
9
|
+
|
10
|
+
strategy:
|
11
|
+
matrix:
|
12
|
+
ruby-version: ['3.1', '3.0', '2.7']
|
13
|
+
|
14
|
+
steps:
|
15
|
+
- uses: actions/checkout@v3
|
16
|
+
- name: Set up Ruby ${{ matrix.ruby-version }}
|
17
|
+
uses: ruby/setup-ruby@359bebbc29cbe6c87da6bc9ea3bc930432750108
|
18
|
+
with:
|
19
|
+
ruby-version: ${{ matrix.ruby-version }}
|
20
|
+
- name: Install dependencies
|
21
|
+
run: bundle install
|
22
|
+
- name: Run tests
|
23
|
+
run: bundle exec rake
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -2,7 +2,12 @@
|
|
2
2
|
|
3
3
|
require 'bundler/gem_tasks'
|
4
4
|
require 'rspec/core/rake_task'
|
5
|
+
require 'rubocop/rake_task'
|
5
6
|
|
6
7
|
RSpec::Core::RakeTask.new :spec
|
7
8
|
|
8
|
-
|
9
|
+
RuboCop::RakeTask.new(:rubocop) do |task|
|
10
|
+
task.requires << 'rubocop-rake'
|
11
|
+
end
|
12
|
+
|
13
|
+
task default: %i[rubocop spec]
|
data/bin/examples
CHANGED
@@ -4,40 +4,73 @@
|
|
4
4
|
require 'bundler/setup'
|
5
5
|
require 'owmo'
|
6
6
|
|
7
|
-
#
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
{
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
7
|
+
# Read the API key
|
8
|
+
api_key_file = 'api_key.txt'
|
9
|
+
|
10
|
+
unless File.exist? api_key_file
|
11
|
+
puts %(
|
12
|
+
File `#{api_key_file}` does not exist in the root of the repository.
|
13
|
+
Please create the file with your OpenWeatherMap API key and rerun bin/example.
|
14
|
+
|
15
|
+
# #{api_key_file} << cat '<your api key>'
|
16
|
+
)
|
17
|
+
exit(1)
|
18
|
+
end
|
19
|
+
|
20
|
+
api_key = File.read(api_key_file).chomp
|
21
|
+
|
22
|
+
unless api_key.length == 32
|
23
|
+
puts %(
|
24
|
+
File `#{api_key_file}` does not contain a valid OpenWeatherMap API key.
|
25
|
+
Please update the file with a valid key and rerun bin/example.
|
26
|
+
|
27
|
+
Found: '#{api_key}'
|
28
|
+
)
|
29
|
+
exit(1)
|
30
|
+
end
|
31
|
+
|
32
|
+
examples = {
|
33
|
+
'current_box' => { path: :box, query: { bbox: [12, 32, 15, 37, 10].join(',') } },
|
34
|
+
'current_circle' => { path: :circle, query: { lat: 55.5, lon: 37.5, cnt: 10 } },
|
35
|
+
'current_group' => { path: :group,
|
36
|
+
query: { id: [4_850_751, 4_887_398, 2_643_743, 4_164_138, 5_368_361].join(',') } },
|
37
|
+
'forecast16 by city_name' => { path: :forecast16, query: { city_name: 'London,UK' } },
|
38
|
+
'forecast5 by city_name' => { path: :forecast5, query: { city_name: 'London,UK' } },
|
39
|
+
'current by city_name, (json/imperial/fr)' => { path: :current,
|
40
|
+
query: { city_name: 'London,UK', mode: 'json', units: 'imperial',
|
41
|
+
lang: 'fr' } },
|
42
|
+
'current by city_id' => { path: :current, query: { city_id: 5_328_041 } },
|
43
|
+
'current by city_name' => { path: :current, query: { city_name: 'Beverly Hills' } },
|
44
|
+
'current by id' => { path: :current, query: { id: 5_328_041 } },
|
45
|
+
'current by lon/lat' => { path: :current, query: { lon: -118.41, lat: 34.09 } },
|
46
|
+
'current by q' => { path: :current, query: { q: 'Beverly Hills' } },
|
47
|
+
'current by zip' => { path: :current, query: { zip: 90_210 } },
|
48
|
+
'current by zip_code' => { path: :current, query: { zip_code: 90_210 } },
|
49
|
+
'current by city_name (html)' => { path: :current, query: { city_name: 'London,UK', mode: :html } },
|
50
|
+
'current by city_name (json)' => { path: :current, query: { city_name: 'London,UK', mode: :json } },
|
51
|
+
'current by city_name (xml)' => { path: :current, query: { city_name: 'London,UK', mode: :xml } },
|
52
|
+
'current by city_name (imperial)' => { path: :current, query: { city_name: 'London,UK', units: :imperial } },
|
53
|
+
'current by city_name (metric)' => { path: :current, query: { city_name: 'London,UK', units: :metric } }
|
54
|
+
}
|
55
|
+
|
56
|
+
execution_output = {}
|
35
57
|
|
36
58
|
puts "OWMO Version #{OWMO::VERSION}"
|
37
59
|
|
38
60
|
OWMO.weather(api_key) do |weather|
|
39
|
-
|
40
|
-
|
41
|
-
|
61
|
+
examples.each do |name, params|
|
62
|
+
puts '', '/********************', name, '********************/'
|
63
|
+
begin
|
64
|
+
pp weather.get params[:path], **params[:query]
|
65
|
+
execution_output[name] = 'SUCCESS'
|
66
|
+
rescue StandardError => e
|
67
|
+
pp e.message
|
68
|
+
execution_output[name] = 'FAILURE'
|
42
69
|
end
|
43
|
-
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
puts "\n\nSummary:"
|
74
|
+
execution_output.each do |name, outcome|
|
75
|
+
puts " - [#{outcome}] #{name.capitalize}"
|
76
|
+
end
|
data/bin/rake
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 'rake' 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('rake', 'rake')
|
data/bin/rspec
CHANGED
@@ -8,12 +8,12 @@
|
|
8
8
|
# this file is here to facilitate running it.
|
9
9
|
#
|
10
10
|
|
11
|
-
ENV[
|
11
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
|
12
12
|
|
13
|
-
bundle_binstub = File.expand_path(
|
13
|
+
bundle_binstub = File.expand_path('bundle', __dir__)
|
14
14
|
|
15
15
|
if File.file?(bundle_binstub)
|
16
|
-
if File.read(bundle_binstub, 300).include?(
|
16
|
+
if File.read(bundle_binstub, 300).include?('This file was generated by Bundler')
|
17
17
|
load(bundle_binstub)
|
18
18
|
else
|
19
19
|
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
@@ -21,7 +21,7 @@ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
require
|
25
|
-
require
|
24
|
+
require 'rubygems'
|
25
|
+
require 'bundler/setup'
|
26
26
|
|
27
|
-
load Gem.bin_path(
|
27
|
+
load Gem.bin_path('rspec-core', 'rspec')
|
data/bin/rubocop
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 'rubocop' 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('rubocop', 'rubocop')
|
data/lib/owmo/version.rb
CHANGED
data/lib/owmo/weather.rb
CHANGED
@@ -121,11 +121,9 @@ module OWMO
|
|
121
121
|
# Sends the GET request to OpenWeatherMap.org
|
122
122
|
# :nocov:
|
123
123
|
def http_get(uri)
|
124
|
-
|
124
|
+
Net::HTTP.start(uri.hostname, uri.port) do |http|
|
125
125
|
http.request(Net::HTTP::Get.new(uri))
|
126
126
|
end
|
127
|
-
|
128
|
-
response
|
129
127
|
end
|
130
128
|
end
|
131
129
|
# :nocov:
|
@@ -3,27 +3,34 @@
|
|
3
3
|
require 'json'
|
4
4
|
|
5
5
|
module OWMO
|
6
|
+
# Weather response class
|
7
|
+
class WeatherResponse
|
8
|
+
attr_reader :weather, :code
|
9
|
+
|
10
|
+
def initialize(http_response)
|
11
|
+
# JSON
|
12
|
+
@weather = JSON.parse(http_response.body)
|
13
|
+
@code = parse_code
|
14
|
+
rescue JSON::ParserError, TypeError
|
15
|
+
# Assume XML or HTML
|
16
|
+
@weather = http_response.body
|
17
|
+
@code = weather.length > 10 ? 200 : 500
|
18
|
+
end
|
6
19
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
def initialize http_response
|
12
|
-
begin
|
13
|
-
# JSON
|
14
|
-
@weather = JSON.parse(http_response.body)
|
15
|
-
@code = self.weather["cod"].to_i
|
16
|
-
rescue JSON::ParserError, TypeError
|
17
|
-
# Assume XML or HTML
|
18
|
-
@weather = http_response.body
|
19
|
-
@code = self.weather.length > 10 ? 200 : 500
|
20
|
-
end
|
21
|
-
end
|
20
|
+
def error?
|
21
|
+
code != 200
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
-
self.code != 200
|
25
|
-
end
|
24
|
+
private
|
26
25
|
|
26
|
+
def parse_code
|
27
|
+
if weather.key? 'cod'
|
28
|
+
weather['cod'].to_i
|
29
|
+
elsif weather.key? 'cnt'
|
30
|
+
weather['cnt'].to_i >= 0 ? 200 : 500
|
31
|
+
else
|
32
|
+
500
|
33
|
+
end
|
27
34
|
end
|
28
|
-
|
29
|
-
end
|
35
|
+
end
|
36
|
+
end
|
data/owmo.gemspec
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
# coding: utf-8
|
3
2
|
|
4
3
|
lib = File.expand_path('lib', __dir__)
|
5
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
@@ -24,7 +23,9 @@ Gem::Specification.new do |spec|
|
|
24
23
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
24
|
spec.require_paths = ['lib']
|
26
25
|
|
26
|
+
spec.required_ruby_version = '>= 2.7'
|
27
27
|
spec.add_development_dependency 'bundler', '~> 2.x'
|
28
28
|
spec.add_development_dependency 'rake', '~> 13.x'
|
29
29
|
spec.add_development_dependency 'rspec', '~> 3.x'
|
30
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
30
31
|
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.1.
|
4
|
+
version: 2.1.5
|
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-
|
11
|
+
date: 2023-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -59,10 +59,11 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
-
- ".github/workflows/
|
63
|
-
- ".github/workflows/
|
62
|
+
- ".github/workflows/rake-release.yml"
|
63
|
+
- ".github/workflows/rake.yml"
|
64
64
|
- ".gitignore"
|
65
65
|
- ".rspec"
|
66
|
+
- ".rubocop.yml"
|
66
67
|
- ".travis.yml"
|
67
68
|
- CONTRIBUTING.MD
|
68
69
|
- Gemfile
|
@@ -72,7 +73,9 @@ files:
|
|
72
73
|
- _config.yml
|
73
74
|
- bin/console
|
74
75
|
- bin/examples
|
76
|
+
- bin/rake
|
75
77
|
- bin/rspec
|
78
|
+
- bin/rubocop
|
76
79
|
- bin/setup
|
77
80
|
- examples/current.rb
|
78
81
|
- examples/current_box.rb
|
@@ -93,7 +96,8 @@ files:
|
|
93
96
|
homepage: https://github.com/robb-randall/owmo
|
94
97
|
licenses:
|
95
98
|
- MIT
|
96
|
-
metadata:
|
99
|
+
metadata:
|
100
|
+
rubygems_mfa_required: 'true'
|
97
101
|
post_install_message:
|
98
102
|
rdoc_options: []
|
99
103
|
require_paths:
|
@@ -102,7 +106,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
102
106
|
requirements:
|
103
107
|
- - ">="
|
104
108
|
- !ruby/object:Gem::Version
|
105
|
-
version: '
|
109
|
+
version: '2.7'
|
106
110
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
111
|
requirements:
|
108
112
|
- - ">="
|
data/.github/workflows/ruby.yml
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
# This workflow uses actions that are not certified by GitHub.
|
2
|
-
# They are provided by a third-party and are governed by
|
3
|
-
# separate terms of service, privacy policy, and support
|
4
|
-
# documentation.
|
5
|
-
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
-
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
-
|
8
|
-
name: Ruby
|
9
|
-
|
10
|
-
on:
|
11
|
-
push:
|
12
|
-
branches: [ "main" ]
|
13
|
-
pull_request:
|
14
|
-
branches: [ "main" ]
|
15
|
-
|
16
|
-
permissions:
|
17
|
-
contents: read
|
18
|
-
|
19
|
-
jobs:
|
20
|
-
test:
|
21
|
-
|
22
|
-
runs-on: ubuntu-latest
|
23
|
-
strategy:
|
24
|
-
matrix:
|
25
|
-
ruby-version: ['2.7', '3.0']
|
26
|
-
|
27
|
-
steps:
|
28
|
-
- uses: actions/checkout@v3
|
29
|
-
- name: Set up Ruby
|
30
|
-
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
31
|
-
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
32
|
-
# uses: ruby/setup-ruby@v1
|
33
|
-
uses: ruby/setup-ruby@ee2113536afb7f793eed4ce60e8d3b26db912da4 # v1.127.0
|
34
|
-
with:
|
35
|
-
ruby-version: ${{ matrix.ruby-version }}
|
36
|
-
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
37
|
-
- name: Run tests
|
38
|
-
run: bundle exec rake
|