weatherfor 0.1.0 → 0.2.1

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: ea8a9060ac36004565702627c743ed73d103a703c815291f5bf6d64cb1297060
4
- data.tar.gz: 7aeb1e2caa751f23d69c6687285cbef8170cfcf4513ac786ba5acff29df790ff
3
+ metadata.gz: 883f424e335c37d98240e90f31c7a6d771421baed9868d5ee3d530c20ba8d569
4
+ data.tar.gz: 2a75af9ca384fbdd288f7bc66df31d7d44b02ccb912080ae7f02666b2b84e128
5
5
  SHA512:
6
- metadata.gz: af955872029404fbe4f2c23a56e858e07c055fb10b8fd321106b163a6c6df67d9d744597d8c85b8250b68edabfa1baf75989634769556f5b8675e63d541a520c
7
- data.tar.gz: 2a38d934ee522d7625deacf365f3f13011546ddebf1315d20d1705eee2911a0407a0518d949964c9926e5ef1e9240df4db2e5d7255ab873c25cef2595234e797
6
+ metadata.gz: d65b683e7082546daf93dac8fa29cfbda910f5e235c47f8eaaf84ce97a411413434e01533ca13d11ccc2f0e9ba6188aa6ff3dfd249e7d8088f0d7488cb37e8a2
7
+ data.tar.gz: c6447a0288856b2ff03c66fd7cdbe0a140ac82f048669f51ae01c6038845acf91d32d01ca321a7a06852adc3851a948093584a578bd06ac90e31b2fee29cf543
@@ -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
@@ -0,0 +1,11 @@
1
+ AllCops:
2
+ NewCops: enable
3
+ SuggestExtensions: false
4
+
5
+ Metrics/BlockLength:
6
+ Exclude:
7
+ - 'spec/**/*.rb'
8
+
9
+ Layout/LineLength:
10
+ Exclude:
11
+ - 'spec/**/*.rb'
data/Gemfile CHANGED
@@ -1,8 +1,17 @@
1
- source "https://rubygems.org"
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 "rake", "~> 12.0"
8
- gem "rspec", "~> 3.0"
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.1.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,8 @@
1
1
  # Weatherfor
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/weatherfor`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Welcome to Weatherfor gem!
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ 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
6
 
7
7
  ## Installation
8
8
 
@@ -22,8 +22,29 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- TODO: Write usage instructions here
25
+ After you install the gem you'll have access to this methods:
26
26
 
27
+ To instance the gem class
28
+ ```ruby
29
+ req = Weatherfor::ApiConsultant.new(CityName, OpenWeatherApiKey)
30
+ ```
31
+
32
+ With this initialization you can check the parsed data:
33
+
34
+ Methodo to consult average temperature in days:
35
+ ```ruby
36
+ req.weather_in_days
37
+ ```
38
+
39
+ Method to consult the raw data:
40
+ ```ruby
41
+ req.list
42
+ ```
43
+
44
+ Method to consult the city request data:
45
+ ```ruby
46
+ req.list
47
+ ```
27
48
  ## Development
28
49
 
29
50
  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.
@@ -32,7 +53,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
53
 
33
54
  ## Contributing
34
55
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/weatherfor.
56
+ Bug reports and pull requests are welcome on GitHub at https://github.com/k41n3w/weatherfor.
36
57
 
37
58
 
38
59
  ## License
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task :default => :spec
8
+ task default: :spec
data/bin/console CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "bundler/setup"
4
- require "weatherfor"
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 "irb"
14
+ require 'irb'
14
15
  IRB.start(__FILE__)
data/lib/weatherfor.rb CHANGED
@@ -1,47 +1,79 @@
1
- require "weatherfor/version"
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 = URI("https://api.openweathermap.org/data/2.5/forecast?q=#{city}&appid=#{api_id}&lang=pt_br&units=metric")
11
- res = Net::HTTP.get_response(uri);nil
15
+ uri = url(city, api_id)
16
+ res = Net::HTTP.get_response(uri)
17
+
18
+ @obj = case res.code
19
+ when '200'
20
+ JSON.parse(res.body)
21
+ else
22
+ { error: res.message }
23
+ end
24
+ end
12
25
 
13
- if res.code == '200'
14
- @json = JSON.parse res.body
15
- else
16
- return { 'error' => res.message }
26
+ def weather_in_days
27
+ avg_temp_in_days
28
+
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}"
31
+ end
32
+
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|
36
+ avg_temp = data.sum { |info| info['main']['temp'] }
37
+ avg_temp /= data.count
38
+ @arr << { avg_temp: avg_temp, date: date }
17
39
  end
18
40
  end
19
41
 
20
- def city
21
- @json['city']
42
+ def today_avg_temp
43
+ @obj['list'][0]['main']['temp'].round
22
44
  end
23
45
 
24
- def list
25
- @json['list']
46
+ def city_name
47
+ @obj['city']['name']
26
48
  end
27
49
 
28
- def weather_in_days
29
- arr = []
30
- @json['list'].group_by{ |item| Time.at(item['dt']).strftime("%m-%d-%Y") }.each do |date,data|
31
- avg_temp = data.map { |info| info['main']['temp'] }.reduce(:+)
32
- avg_temp = avg_temp / 8
33
- arr << { avg_temp: avg_temp, date: date }
34
- end
35
- current_temp = @json['list'][0]['main']['temp']
36
- city_name = @json['city']['name']
37
- weather_description = @json['list'][0]['weather'][0]['description']
38
- current_date = arr.first[:date].gsub('-', '/').delete_suffix('/2021')
39
- text = "#{current_temp.round(0)}°C e #{weather_description} em #{city_name} em #{current_date}. Média para os próximos dias: "
40
-
41
- arr.last(4).each do |item|
42
- text += "#{item[:avg_temp].round(0)}°C em #{item[:date].gsub('-', '/').delete_suffix('/2021')}, "
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')
56
+ end
57
+
58
+ private
59
+
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
43
67
  end
44
68
  text
45
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
46
78
  end
47
79
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Weatherfor
2
- VERSION = "0.1.0"
4
+ VERSION = '0.2.1'
3
5
  end
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 = "weatherfor"
6
+ spec.name = 'weatherfor'
5
7
  spec.version = Weatherfor::VERSION
6
- spec.authors = ["Caio Ramos"]
7
- spec.email = ["kaineo@hotmai.l."]
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 = "https://github.com/k41n3w/weatherfor"
12
- spec.license = "MIT"
13
- spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
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["homepage_uri"] = spec.homepage
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 = Dir.chdir(File.expand_path('..', __FILE__)) do
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 = "exe"
24
+ spec.bindir = 'exe'
29
25
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
- spec.require_paths = ["lib"]
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.1.0
4
+ version: 0.2.1
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-10 00:00:00.000000000 Z
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
- - ".travis.yml"
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.3.0
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.2
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: []
data/.travis.yml DELETED
@@ -1,6 +0,0 @@
1
- ---
2
- language: ruby
3
- cache: bundler
4
- rvm:
5
- - 2.7.0
6
- before_install: gem install bundler -v 2.1.2