owmo 2.1.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 125a82a8915262a016d7b78461f403abf325d76d177d97700e1be023ad3e22eb
4
- data.tar.gz: 6d47d5e59c2d3b31322a478dc252a33cfdbc88139d86d641f29cc67861d9c88c
3
+ metadata.gz: 7206b29a014088dd08403d1199d6b410a4d2d2e7dd1087290058d542add26f79
4
+ data.tar.gz: 0115ffba7abd0eca441f6117c2cb20561a09c2556b606af56c1cde829372fe7c
5
5
  SHA512:
6
- metadata.gz: a574a3a6a6b8f81bb77da1a4e8f10809fe8f43012b214061c269c7c91c22768543357e280d18cc7ef72e0f2cce04f9af35ae3c70c3370f5364257cae4fdd79eb
7
- data.tar.gz: 9a93faefecb90ae2147ef9d20b2fe1f280ba582fba580e8588d7bf6084ab2e9b400e9b0a2e162c0dfc5efac105860fa8b15e28850d26c4215c7d96c80db4640d
6
+ metadata.gz: 48059ce954439c46e4c19edc050c9b0d8193caf6b9e464726b255f88aa42b5591dc69b6bbd17c227728bf89a16e4c8adfe744ad0891d1f9bd448c6250ceadc01
7
+ data.tar.gz: 73af163549823603d7222ed682367c91baa4dab7276bd2bcd318ede49e435b03c4480abb318e3425cec3a5ace4dd8f5c393a5591622c519a8cc75c8e86a9c5e6
@@ -1,4 +1,4 @@
1
- name: Publish Gem
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: Release Gem
16
+ - name: Publish to Rubygems
17
17
  if: contains(github.ref, 'refs/tags/v')
18
- uses: cadwallion/publish-rubygems-action@master
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
@@ -13,6 +13,5 @@
13
13
 
14
14
 
15
15
  *.gem
16
- test.rb
17
- scratch.rb
18
16
  api_key.txt
17
+ coverage
data/.rubocop.yml ADDED
@@ -0,0 +1,7 @@
1
+ require:
2
+ - rubocop-rake
3
+ - rubocop-rspec
4
+
5
+ AllCops:
6
+ NewCops: enable
7
+
data/Gemfile CHANGED
@@ -4,5 +4,12 @@ source 'https://rubygems.org'
4
4
 
5
5
  gemspec
6
6
 
7
+ gem 'rake_tasks', '>= 5.x'
8
+
7
9
  gem 'rspec'
10
+
11
+ gem 'rubocop', require: false
12
+ gem 'rubocop-rake', require: false
13
+ gem 'rubocop-rspec', require: false
14
+
8
15
  gem 'simplecov', require: false, group: :test
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
- task default: :spec
9
+ RuboCop::RakeTask.new(:rubocop) do |task|
10
+ task.requires << 'rubocop-rake'
11
+ end
12
+
13
+ task default: %i[rubocop spec]
data/bin/examples ADDED
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'owmo'
6
+
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 = {}
57
+
58
+ puts "OWMO Version #{OWMO::VERSION}"
59
+
60
+ OWMO.weather(api_key) do |weather|
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'
69
+ 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["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
11
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
12
12
 
13
- bundle_binstub = File.expand_path("bundle", __dir__)
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?("This file was generated by Bundler")
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 "rubygems"
25
- require "bundler/setup"
24
+ require 'rubygems'
25
+ require 'bundler/setup'
26
26
 
27
- load Gem.bin_path("rspec-core", "rspec")
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
@@ -3,5 +3,5 @@
3
3
  module OWMO
4
4
  # rdoc
5
5
  # Gem Version
6
- VERSION = '2.1.1'
6
+ VERSION = '2.1.5'
7
7
  end
data/lib/owmo/weather.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'core_extensions/net/http_response/weather_response'
3
+ require 'owmo/weather_response'
4
4
 
5
5
  require 'json'
6
6
  require 'logger'
@@ -19,8 +19,8 @@ module OWMO
19
19
  # rdoc
20
20
  # Weather response error to handle errors received from OpenWeatherMap.orgs API
21
21
  class WeatherResponseError < StandardError
22
- def initialize(response)
23
- super("ERROR #{response.weather_code}: #{response.message}")
22
+ def initialize(weather_response)
23
+ super("ERROR #{weather_response.code}: #{weather_response.weather}")
24
24
  end
25
25
  end
26
26
 
@@ -84,11 +84,13 @@ module OWMO
84
84
  uri = format_uri(OWMO::URL, PATHS[path], query)
85
85
 
86
86
  # Get the weather data
87
- response = http_get(uri)
87
+ http_response = http_get(uri)
88
88
 
89
- raise(WeatherResponseError, response) if response.error?
89
+ weather_response = WeatherResponse.new(http_response)
90
90
 
91
- response.weather
91
+ raise(WeatherResponseError, weather_response) if weather_response.error?
92
+
93
+ weather_response.weather
92
94
  end
93
95
 
94
96
  private
@@ -119,11 +121,9 @@ module OWMO
119
121
  # Sends the GET request to OpenWeatherMap.org
120
122
  # :nocov:
121
123
  def http_get(uri)
122
- response = Net::HTTP.start(uri.hostname, uri.port) do |http|
124
+ Net::HTTP.start(uri.hostname, uri.port) do |http|
123
125
  http.request(Net::HTTP::Get.new(uri))
124
126
  end
125
-
126
- response
127
127
  end
128
128
  end
129
129
  # :nocov:
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+
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
19
+
20
+ def error?
21
+ code != 200
22
+ end
23
+
24
+ private
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
34
+ 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.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-10 00:00:00.000000000 Z
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/ruby-publish-gem.yml"
63
- - ".github/workflows/ruby.yml"
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
@@ -71,7 +72,10 @@ files:
71
72
  - Rakefile
72
73
  - _config.yml
73
74
  - bin/console
75
+ - bin/examples
76
+ - bin/rake
74
77
  - bin/rspec
78
+ - bin/rubocop
75
79
  - bin/setup
76
80
  - examples/current.rb
77
81
  - examples/current_box.rb
@@ -84,15 +88,16 @@ files:
84
88
  - examples/query_mode.rb
85
89
  - examples/query_units.rb
86
90
  - examples/sinatra_example.rb
87
- - lib/core_extensions/net/http_response/weather_response.rb
88
91
  - lib/owmo.rb
89
92
  - lib/owmo/version.rb
90
93
  - lib/owmo/weather.rb
94
+ - lib/owmo/weather_response.rb
91
95
  - owmo.gemspec
92
96
  homepage: https://github.com/robb-randall/owmo
93
97
  licenses:
94
98
  - MIT
95
- metadata: {}
99
+ metadata:
100
+ rubygems_mfa_required: 'true'
96
101
  post_install_message:
97
102
  rdoc_options: []
98
103
  require_paths:
@@ -101,7 +106,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
101
106
  requirements:
102
107
  - - ">="
103
108
  - !ruby/object:Gem::Version
104
- version: '0'
109
+ version: '2.7'
105
110
  required_rubygems_version: !ruby/object:Gem::Requirement
106
111
  requirements:
107
112
  - - ">="
@@ -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
@@ -1,65 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'json'
4
- require 'net/http'
5
-
6
- module CoreExtensions
7
- module Net
8
- module HTTPResponse
9
- module WeatherResponse
10
- # rdoc
11
- # Returns the weather
12
- def weather
13
- parse_weather
14
- @weather
15
- end
16
-
17
- # rdoc
18
- # Returns the response code
19
- def weather_code
20
- parse_weather
21
-
22
- return (weather['cod'] || '500').to_i if weather.is_a? Hash
23
-
24
- 200
25
- end
26
-
27
- # rdoc
28
- # Returns the response message
29
- def weather_message
30
- parse_weather
31
- return weather['message'] if weather.is_a? Hash
32
-
33
- 'None'
34
- end
35
-
36
- # rdoc
37
- # Returns boolean if the response contains an error or not.
38
- def error?
39
- weather_code != 200
40
- end
41
-
42
- private
43
-
44
- # rdoc
45
- # Sets the weather variable
46
- def weather=(weather)
47
- @weather = weather if @weather.nil?
48
- end
49
-
50
- # rdoc
51
- # Attempts to parse the body to JSON. This is so we don't have to continually
52
- # parse the raw JSON.
53
- def parse_weather
54
- # Try to parse the response and return a hash
55
- @weather = JSON.parse(body)
56
- rescue StandardError
57
- # Return the body string if parsing fails (used for html and xml responses)
58
- @weather = body
59
- end
60
- end
61
- end
62
- end
63
- end
64
-
65
- Net::HTTPResponse.include CoreExtensions::Net::HTTPResponse::WeatherResponse