weatherfor 0.1.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8b4b91285f13701c20571438e8512fd6ae2a5f8eb622e7a7be34503bff366aed
4
- data.tar.gz: 77651d9a2851a1c7ddf2d0ef31b63fa39f48ccec82f94ba050246a46f956250b
3
+ metadata.gz: 387939db3d543012921d2565f2daba90b705598917d81d85b6aa9f76c148e3b8
4
+ data.tar.gz: 8619e049fdb32c5c4445c9d303d2563a81030975b832ea714dc73f1912a1ecb5
5
5
  SHA512:
6
- metadata.gz: 47099721577ff9a0ce10a1baa1beb3cdb9f9f54684d9dfa920a5c454e680923e9acc4a064861baef308ae14663cf6c42da465d87bd9811b33c97c728dcf14254
7
- data.tar.gz: de57fa381901230b6a056b0879ec4d36374a76cc1c8dc88caad73b977f26b7f6ac5a257fb42a90241c69fc3fed4a81de09fdb9f624247c431fc8f96b7d324b2e
6
+ metadata.gz: 5cec5dbcb435df7efd9d6e0db1406e1dcc70bfde2a08f9f9a0a133f6158d2b9533d509e0f16527ecb8540b853a675209f633612e545a73bee1a423445a47ad0c
7
+ data.tar.gz: 064fce463177f69a4a4f77df75f76b9c8c9d074c81df5e18f1837802fc87cad663065f70fe685f4b8e64e008e6c9e4128cbb7b41592c9eb69da773dd9e8a98bd
@@ -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 CHANGED
@@ -1,2 +1,7 @@
1
1
  AllCops:
2
2
  NewCops: enable
3
+ SuggestExtensions: false
4
+
5
+ Metrics/BlockLength:
6
+ Exclude:
7
+ - 'spec/**/*.rb'
data/Gemfile CHANGED
@@ -9,3 +9,9 @@ gemspec
9
9
  gem 'rake', '~> 12.0'
10
10
  gem 'rspec', '~> 3.0'
11
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,16 +1,23 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- weatherfor (0.1.2)
4
+ weatherfor (0.2.3)
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)
9
11
  ast (2.4.2)
12
+ crack (0.4.5)
13
+ rexml
10
14
  diff-lcs (1.4.4)
15
+ docile (1.3.5)
16
+ hashdiff (1.0.1)
11
17
  parallel (1.20.1)
12
18
  parser (3.0.1.0)
13
19
  ast (~> 2.4.1)
20
+ public_suffix (4.0.6)
14
21
  rainbow (3.0.0)
15
22
  rake (12.3.3)
16
23
  regexp_parser (2.1.1)
@@ -40,7 +47,18 @@ GEM
40
47
  rubocop-ast (1.4.1)
41
48
  parser (>= 2.7.1.5)
42
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)
43
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)
44
62
 
45
63
  PLATFORMS
46
64
  ruby
@@ -49,7 +67,10 @@ DEPENDENCIES
49
67
  rake (~> 12.0)
50
68
  rspec (~> 3.0)
51
69
  rubocop
70
+ simplecov
71
+ vcr
52
72
  weatherfor!
73
+ webmock
53
74
 
54
75
  BUNDLED WITH
55
76
  2.1.2
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Weatherfor
2
2
 
3
+ [![Ruby Gem](https://github.com/k41n3w/weatherfor/actions/workflows/gem-push.yml/badge.svg)](https://github.com/k41n3w/weatherfor/actions/workflows/gem-push.yml) <a href="https://codeclimate.com/github/k41n3w/weatherfor/maintainability"><img src="https://api.codeclimate.com/v1/badges/11442e37d318544985fe/maintainability" /></a>
4
+
3
5
  Welcome to Weatherfor gem!
4
6
 
5
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.
@@ -36,15 +38,10 @@ Methodo to consult average temperature in days:
36
38
  req.weather_in_days
37
39
  ```
38
40
 
39
- Method to consult the raw data:
40
- ```ruby
41
- req.list
42
- ```
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.
43
44
 
44
- Method to consult the city request data:
45
- ```ruby
46
- req.list
47
- ```
48
45
  ## Development
49
46
 
50
47
  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.
data/lib/weatherfor.rb CHANGED
@@ -9,16 +9,18 @@ module Weatherfor
9
9
 
10
10
  # Make the API request and parse data
11
11
  class ApiConsultant
12
+ attr_reader :obj
13
+
12
14
  def initialize(city, api_id)
13
15
  uri = url(city, api_id)
14
16
  res = Net::HTTP.get_response(uri)
15
17
 
16
- @data = case res.code
17
- when '200'
18
- JSON.parse(res.body)
19
- else
20
- { error: res.message }
21
- end
18
+ @obj = case res.code
19
+ when '200'
20
+ JSON.parse(res.body)
21
+ else
22
+ { error: res.message }
23
+ end
22
24
  end
23
25
 
24
26
  def weather_in_days
@@ -30,7 +32,7 @@ module Weatherfor
30
32
 
31
33
  def avg_temp_in_days
32
34
  @arr = []
33
- @json['list'].group_by { |item| Time.at(item['dt']).strftime('%m-%d-%Y') }.each do |date, data|
35
+ obj['list'].group_by { |item| Time.at(item['dt']).strftime('%m-%d-%Y') }.each do |date, data|
34
36
  avg_temp = data.sum { |info| info['main']['temp'] }
35
37
  avg_temp /= data.count
36
38
  @arr << { avg_temp: avg_temp, date: date }
@@ -38,38 +40,34 @@ module Weatherfor
38
40
  end
39
41
 
40
42
  def today_avg_temp
41
- @arr.first[:avg_temp].round(0)
43
+ obj['list'][0]['main']['temp'].round
42
44
  end
43
45
 
44
46
  def city_name
45
- @json['city']['name']
47
+ obj['city']['name']
46
48
  end
47
49
 
48
50
  def current_temp_desc
49
- @json['list'][0]['weather'][0]['description']
51
+ obj['list'][0]['weather'][0]['description']
50
52
  end
51
53
 
52
54
  def current_date
53
55
  Time.now.strftime('%d/%m')
54
56
  end
55
57
 
58
+ private
59
+
56
60
  def parse_avg_text
57
61
  text = ''
58
- @arr.last(4).each_with_index do |item, index|
62
+ @arr.last(5).each_with_index do |item, index|
59
63
  text += "#{item[:avg_temp].round(0)}°C em #{parse_date(item[:date])}"
60
- text += index < 3 ? ', ' : '.'
64
+ text += ', ' if index <= 2
65
+ text += ' e ' if index == 3
66
+ text += '.' if index == 4
61
67
  end
62
68
  text
63
69
  end
64
70
 
65
- def city
66
- @json['city']
67
- end
68
-
69
- def list
70
- @json['list']
71
- end
72
-
73
71
  def parse_date(date)
74
72
  date.gsub('-', '/').delete_suffix('/2021')
75
73
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Weatherfor
4
- VERSION = '0.1.2'
4
+ VERSION = '0.2.3'
5
5
  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.2
4
+ version: 0.2.3
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-17 00:00:00.000000000 Z
11
+ date: 2021-04-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Sumario
14
14
  email:
@@ -17,10 +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
- - ".travis.yml"
24
24
  - Gemfile
25
25
  - Gemfile.lock
26
26
  - LICENSE.txt
@@ -36,7 +36,7 @@ licenses:
36
36
  - MIT
37
37
  metadata:
38
38
  homepage_uri: https://github.com/k41n3w/weatherfor
39
- post_install_message:
39
+ post_install_message:
40
40
  rdoc_options: []
41
41
  require_paths:
42
42
  - lib
@@ -51,8 +51,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
51
  - !ruby/object:Gem::Version
52
52
  version: '0'
53
53
  requirements: []
54
- rubygems_version: 3.1.2
55
- signing_key:
54
+ rubygems_version: 3.0.3.1
55
+ signing_key:
56
56
  specification_version: 4
57
57
  summary: Api to check the average weather forecast for the next five days
58
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