weatherfor 0.1.1 → 0.2.2
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/gem-push.yml +42 -0
- data/.rubocop.yml +7 -0
- data/Gemfile +12 -3
- data/Gemfile.lock +43 -1
- data/README.md +22 -4
- data/Rakefile +5 -3
- data/bin/console +4 -3
- data/lib/weatherfor.rb +55 -36
- data/lib/weatherfor/version.rb +3 -1
- data/weatherfor.gemspec +12 -16
- metadata +9 -8
- data/.travis.yml +0 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4a3a7da1e14cacc4b0a0e2650017fa6fc252e98e5b14e5e5eece2327ca0a1650
|
|
4
|
+
data.tar.gz: 77cac703ed39dd4b07dfc6e77c7a4ef22eed49794bbb57620682a54d503a1975
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: dfeaf90ece59194dc2e30ab5cb7204d58c790eff94afcb3b9a883fce8123a6977005fb826c3f01bac8765670d345962b81d9b080925ed052f5055df79bf08107
|
|
7
|
+
data.tar.gz: e1130670918e4f173748e5de0feaa372db9788005db92111482d88452c6a437a3d80b1f35eebba33c4259cf437f258082279ed91ba41b03068162192211291fd
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
name: Ruby Gem
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ main ]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ main ]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
build:
|
|
11
|
+
name: Build + Publish
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v2
|
|
16
|
+
- name: Set up Ruby 2.6
|
|
17
|
+
uses: actions/setup-ruby@v1
|
|
18
|
+
with:
|
|
19
|
+
ruby-version: 2.6.x
|
|
20
|
+
|
|
21
|
+
- name: Publish to GPR
|
|
22
|
+
run: |
|
|
23
|
+
mkdir -p $HOME/.gem
|
|
24
|
+
touch $HOME/.gem/credentials
|
|
25
|
+
chmod 0600 $HOME/.gem/credentials
|
|
26
|
+
printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
|
27
|
+
gem build *.gemspec
|
|
28
|
+
gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
|
|
29
|
+
env:
|
|
30
|
+
GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
|
|
31
|
+
OWNER: ${{ github.repository_owner }}
|
|
32
|
+
|
|
33
|
+
- name: Publish to RubyGems
|
|
34
|
+
run: |
|
|
35
|
+
mkdir -p $HOME/.gem
|
|
36
|
+
touch $HOME/.gem/credentials
|
|
37
|
+
chmod 0600 $HOME/.gem/credentials
|
|
38
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
|
39
|
+
gem build *.gemspec
|
|
40
|
+
gem push *.gem
|
|
41
|
+
env:
|
|
42
|
+
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
|
data/.rubocop.yml
ADDED
data/Gemfile
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
source 'https://rubygems.org'
|
|
2
4
|
require 'net/http'
|
|
3
5
|
|
|
4
6
|
# Specify your gem's dependencies in weatherfor.gemspec
|
|
5
7
|
gemspec
|
|
6
8
|
|
|
7
|
-
gem
|
|
8
|
-
gem
|
|
9
|
+
gem 'rake', '~> 12.0'
|
|
10
|
+
gem 'rspec', '~> 3.0'
|
|
11
|
+
gem 'rubocop', require: false
|
|
12
|
+
gem 'vcr'
|
|
13
|
+
|
|
14
|
+
group :test do
|
|
15
|
+
gem 'simplecov', require: false
|
|
16
|
+
gem 'webmock'
|
|
17
|
+
end
|
data/Gemfile.lock
CHANGED
|
@@ -1,13 +1,27 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
weatherfor (0.
|
|
4
|
+
weatherfor (0.2.1)
|
|
5
5
|
|
|
6
6
|
GEM
|
|
7
7
|
remote: https://rubygems.org/
|
|
8
8
|
specs:
|
|
9
|
+
addressable (2.7.0)
|
|
10
|
+
public_suffix (>= 2.0.2, < 5.0)
|
|
11
|
+
ast (2.4.2)
|
|
12
|
+
crack (0.4.5)
|
|
13
|
+
rexml
|
|
9
14
|
diff-lcs (1.4.4)
|
|
15
|
+
docile (1.3.5)
|
|
16
|
+
hashdiff (1.0.1)
|
|
17
|
+
parallel (1.20.1)
|
|
18
|
+
parser (3.0.1.0)
|
|
19
|
+
ast (~> 2.4.1)
|
|
20
|
+
public_suffix (4.0.6)
|
|
21
|
+
rainbow (3.0.0)
|
|
10
22
|
rake (12.3.3)
|
|
23
|
+
regexp_parser (2.1.1)
|
|
24
|
+
rexml (3.2.5)
|
|
11
25
|
rspec (3.10.0)
|
|
12
26
|
rspec-core (~> 3.10.0)
|
|
13
27
|
rspec-expectations (~> 3.10.0)
|
|
@@ -21,6 +35,30 @@ GEM
|
|
|
21
35
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
22
36
|
rspec-support (~> 3.10.0)
|
|
23
37
|
rspec-support (3.10.2)
|
|
38
|
+
rubocop (1.12.1)
|
|
39
|
+
parallel (~> 1.10)
|
|
40
|
+
parser (>= 3.0.0.0)
|
|
41
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
42
|
+
regexp_parser (>= 1.8, < 3.0)
|
|
43
|
+
rexml
|
|
44
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
|
45
|
+
ruby-progressbar (~> 1.7)
|
|
46
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
|
47
|
+
rubocop-ast (1.4.1)
|
|
48
|
+
parser (>= 2.7.1.5)
|
|
49
|
+
ruby-progressbar (1.11.0)
|
|
50
|
+
simplecov (0.21.2)
|
|
51
|
+
docile (~> 1.1)
|
|
52
|
+
simplecov-html (~> 0.11)
|
|
53
|
+
simplecov_json_formatter (~> 0.1)
|
|
54
|
+
simplecov-html (0.12.3)
|
|
55
|
+
simplecov_json_formatter (0.1.2)
|
|
56
|
+
unicode-display_width (2.0.0)
|
|
57
|
+
vcr (6.0.0)
|
|
58
|
+
webmock (3.12.2)
|
|
59
|
+
addressable (>= 2.3.6)
|
|
60
|
+
crack (>= 0.3.2)
|
|
61
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
|
24
62
|
|
|
25
63
|
PLATFORMS
|
|
26
64
|
ruby
|
|
@@ -28,7 +66,11 @@ PLATFORMS
|
|
|
28
66
|
DEPENDENCIES
|
|
29
67
|
rake (~> 12.0)
|
|
30
68
|
rspec (~> 3.0)
|
|
69
|
+
rubocop
|
|
70
|
+
simplecov
|
|
71
|
+
vcr
|
|
31
72
|
weatherfor!
|
|
73
|
+
webmock
|
|
32
74
|
|
|
33
75
|
BUNDLED WITH
|
|
34
76
|
2.1.2
|
data/README.md
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
# Weatherfor
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://github.com/k41n3w/weatherfor/actions/workflows/gem-push.yml)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Welcome to Weatherfor gem!
|
|
6
|
+
|
|
7
|
+
The purpose of this Gem is to make API requests to OpenWeatherAPI to query meteorological data to process the average temperature for the next five days.
|
|
6
8
|
|
|
7
9
|
## Installation
|
|
8
10
|
|
|
@@ -22,7 +24,23 @@ Or install it yourself as:
|
|
|
22
24
|
|
|
23
25
|
## Usage
|
|
24
26
|
|
|
25
|
-
|
|
27
|
+
After you install the gem you'll have access to this methods:
|
|
28
|
+
|
|
29
|
+
To instance the gem class
|
|
30
|
+
```ruby
|
|
31
|
+
req = Weatherfor::ApiConsultant.new(CityName, OpenWeatherApiKey)
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
With this initialization you can check the parsed data:
|
|
35
|
+
|
|
36
|
+
Methodo to consult average temperature in days:
|
|
37
|
+
```ruby
|
|
38
|
+
req.weather_in_days
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
This will bring a message like that:
|
|
42
|
+
|
|
43
|
+
34°C e nublado em <cidade> em 12/12. Média para os próximos dias: 32°C em 13/12, 25°C em 14/12, 29°C em 15/12, 33°C em 16/12 e 28°C em 16/12.
|
|
26
44
|
|
|
27
45
|
## Development
|
|
28
46
|
|
|
@@ -32,7 +50,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
|
32
50
|
|
|
33
51
|
## Contributing
|
|
34
52
|
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
|
53
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/k41n3w/weatherfor.
|
|
36
54
|
|
|
37
55
|
|
|
38
56
|
## License
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
2
3
|
|
|
3
|
-
require
|
|
4
|
-
require
|
|
4
|
+
require 'bundler/setup'
|
|
5
|
+
require 'weatherfor'
|
|
5
6
|
|
|
6
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
8
|
# with your gem easier. You can also use a different console, if you like.
|
|
@@ -10,5 +11,5 @@ require "weatherfor"
|
|
|
10
11
|
# require "pry"
|
|
11
12
|
# Pry.start
|
|
12
13
|
|
|
13
|
-
require
|
|
14
|
+
require 'irb'
|
|
14
15
|
IRB.start(__FILE__)
|
data/lib/weatherfor.rb
CHANGED
|
@@ -1,60 +1,79 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'weatherfor/version'
|
|
2
4
|
require 'net/http'
|
|
3
5
|
require 'json'
|
|
4
6
|
|
|
5
7
|
module Weatherfor
|
|
6
8
|
class Error < StandardError; end
|
|
7
|
-
|
|
9
|
+
|
|
10
|
+
# Make the API request and parse data
|
|
8
11
|
class ApiConsultant
|
|
12
|
+
attr_reader :obj
|
|
13
|
+
|
|
9
14
|
def initialize(city, api_id)
|
|
10
|
-
uri =
|
|
11
|
-
res = Net::HTTP.get_response(uri)
|
|
15
|
+
uri = url(city, api_id)
|
|
16
|
+
res = Net::HTTP.get_response(uri)
|
|
12
17
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
@obj = case res.code
|
|
19
|
+
when '200'
|
|
20
|
+
JSON.parse(res.body)
|
|
21
|
+
else
|
|
22
|
+
{ error: res.message }
|
|
23
|
+
end
|
|
18
24
|
end
|
|
19
25
|
|
|
20
|
-
def
|
|
21
|
-
|
|
22
|
-
end
|
|
26
|
+
def weather_in_days
|
|
27
|
+
avg_temp_in_days
|
|
23
28
|
|
|
24
|
-
|
|
25
|
-
|
|
29
|
+
"#{today_avg_temp}°C e #{current_temp_desc} em #{city_name} em #{current_date}." \
|
|
30
|
+
" Média para os próximos dias: #{parse_avg_text}"
|
|
26
31
|
end
|
|
27
32
|
|
|
28
|
-
def
|
|
29
|
-
arr = []
|
|
30
|
-
|
|
33
|
+
def avg_temp_in_days
|
|
34
|
+
@arr = []
|
|
35
|
+
obj['list'].group_by { |item| Time.at(item['dt']).strftime('%m-%d-%Y') }.each do |date, data|
|
|
31
36
|
avg_temp = data.sum { |info| info['main']['temp'] }
|
|
32
|
-
avg_temp
|
|
33
|
-
arr << { avg_temp: avg_temp, date: date }
|
|
37
|
+
avg_temp /= data.count
|
|
38
|
+
@arr << { avg_temp: avg_temp, date: date }
|
|
34
39
|
end
|
|
35
|
-
|
|
36
|
-
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def today_avg_temp
|
|
43
|
+
obj['list'][0]['main']['temp'].round
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def city_name
|
|
47
|
+
obj['city']['name']
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def current_temp_desc
|
|
51
|
+
obj['list'][0]['weather'][0]['description']
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def current_date
|
|
55
|
+
Time.now.strftime('%d/%m')
|
|
37
56
|
end
|
|
38
57
|
|
|
39
58
|
private
|
|
40
59
|
|
|
41
|
-
def parse_avg_text
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
arr.last(4).each_with_index do |item, index|
|
|
49
|
-
text += "#{item[:avg_temp].round(0)}°C em #{item[:date].gsub('-', '/').delete_suffix('/2021')}"
|
|
50
|
-
if index < 3
|
|
51
|
-
text += ", "
|
|
52
|
-
else
|
|
53
|
-
text += "."
|
|
54
|
-
end
|
|
60
|
+
def parse_avg_text
|
|
61
|
+
text = ''
|
|
62
|
+
@arr.last(5).each_with_index do |item, index|
|
|
63
|
+
text += "#{item[:avg_temp].round(0)}°C em #{parse_date(item[:date])}"
|
|
64
|
+
text += ', ' if index <= 2
|
|
65
|
+
text += ' e ' if index == 3
|
|
66
|
+
text += '.' if index == 4
|
|
55
67
|
end
|
|
56
|
-
|
|
57
68
|
text
|
|
58
69
|
end
|
|
70
|
+
|
|
71
|
+
def parse_date(date)
|
|
72
|
+
date.gsub('-', '/').delete_suffix('/2021')
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def url(city, api_id)
|
|
76
|
+
URI("https://api.openweathermap.org/data/2.5/forecast?q=#{city}&appid=#{api_id}&lang=pt_br&units=metric")
|
|
77
|
+
end
|
|
59
78
|
end
|
|
60
79
|
end
|
data/lib/weatherfor/version.rb
CHANGED
data/weatherfor.gemspec
CHANGED
|
@@ -1,31 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require_relative 'lib/weatherfor/version'
|
|
2
4
|
|
|
3
5
|
Gem::Specification.new do |spec|
|
|
4
|
-
spec.name =
|
|
6
|
+
spec.name = 'weatherfor'
|
|
5
7
|
spec.version = Weatherfor::VERSION
|
|
6
|
-
spec.authors = [
|
|
7
|
-
spec.email = [
|
|
8
|
+
spec.authors = ['Caio Ramos']
|
|
9
|
+
spec.email = ['kaineo@hotmai.l.']
|
|
8
10
|
|
|
9
11
|
spec.summary = 'Api to check the average weather forecast for the next five days'
|
|
10
12
|
spec.description = 'Sumario'
|
|
11
|
-
spec.homepage =
|
|
12
|
-
spec.license =
|
|
13
|
-
spec.required_ruby_version =
|
|
14
|
-
|
|
15
|
-
if spec.respond_to?(:metadata)
|
|
16
|
-
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
|
17
|
-
else
|
|
18
|
-
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
|
19
|
-
end
|
|
13
|
+
spec.homepage = 'https://github.com/k41n3w/weatherfor'
|
|
14
|
+
spec.license = 'MIT'
|
|
15
|
+
spec.required_ruby_version = '>= 2.4.0'
|
|
20
16
|
|
|
21
|
-
spec.metadata[
|
|
17
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
|
22
18
|
|
|
23
19
|
# Specify which files should be added to the gem when it is released.
|
|
24
20
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
25
|
-
spec.files
|
|
21
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
26
22
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
27
23
|
end
|
|
28
|
-
spec.bindir =
|
|
24
|
+
spec.bindir = 'exe'
|
|
29
25
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
30
|
-
spec.require_paths = [
|
|
26
|
+
spec.require_paths = ['lib']
|
|
31
27
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: weatherfor
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Caio Ramos
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2021-04-
|
|
11
|
+
date: 2021-04-19 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Sumario
|
|
14
14
|
email:
|
|
@@ -17,9 +17,10 @@ executables: []
|
|
|
17
17
|
extensions: []
|
|
18
18
|
extra_rdoc_files: []
|
|
19
19
|
files:
|
|
20
|
+
- ".github/workflows/gem-push.yml"
|
|
20
21
|
- ".gitignore"
|
|
21
22
|
- ".rspec"
|
|
22
|
-
- ".
|
|
23
|
+
- ".rubocop.yml"
|
|
23
24
|
- Gemfile
|
|
24
25
|
- Gemfile.lock
|
|
25
26
|
- LICENSE.txt
|
|
@@ -35,7 +36,7 @@ licenses:
|
|
|
35
36
|
- MIT
|
|
36
37
|
metadata:
|
|
37
38
|
homepage_uri: https://github.com/k41n3w/weatherfor
|
|
38
|
-
post_install_message:
|
|
39
|
+
post_install_message:
|
|
39
40
|
rdoc_options: []
|
|
40
41
|
require_paths:
|
|
41
42
|
- lib
|
|
@@ -43,15 +44,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
43
44
|
requirements:
|
|
44
45
|
- - ">="
|
|
45
46
|
- !ruby/object:Gem::Version
|
|
46
|
-
version: 2.
|
|
47
|
+
version: 2.4.0
|
|
47
48
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
48
49
|
requirements:
|
|
49
50
|
- - ">="
|
|
50
51
|
- !ruby/object:Gem::Version
|
|
51
52
|
version: '0'
|
|
52
53
|
requirements: []
|
|
53
|
-
rubygems_version: 3.1
|
|
54
|
-
signing_key:
|
|
54
|
+
rubygems_version: 3.0.3.1
|
|
55
|
+
signing_key:
|
|
55
56
|
specification_version: 4
|
|
56
57
|
summary: Api to check the average weather forecast for the next five days
|
|
57
58
|
test_files: []
|