bomtempo 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cc6a5fe65288595f5c2a7a905e3bfe09cb55e648ffaae7e6f3e145be1349bbcd
4
+ data.tar.gz: bba7f0901ab2fbb11a3566822280c2bd66cfcac41d86025024dde74692685010
5
+ SHA512:
6
+ metadata.gz: de9567793ea149b976fb5a15e0b695ecf6953319ec13fe3ec6225282e9fdd3a0cab276cd380043b6969354b6d1cc4fe3334ea7b6ec4ba5329add52a6e67eae78
7
+ data.tar.gz: f53ce1f3408c905fa009398a57bdd50a69b6bfd9387570b292ed999053d9f7c369b2da95f8e9b2dad32628536eb4f85acfd9f84660adce3d5f0cca0bdd996c25
data/.DS_Store ADDED
Binary file
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-10-10
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at welitonj.jose@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in bomtempo.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,39 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bomtempo (0.1.0)
5
+ httparty
6
+ webmock
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.8.1)
12
+ public_suffix (>= 2.0.2, < 6.0)
13
+ crack (0.4.5)
14
+ rexml
15
+ hashdiff (1.0.1)
16
+ httparty (0.20.0)
17
+ mime-types (~> 3.0)
18
+ multi_xml (>= 0.5.2)
19
+ mime-types (3.4.1)
20
+ mime-types-data (~> 3.2015)
21
+ mime-types-data (3.2022.0105)
22
+ multi_xml (0.6.0)
23
+ public_suffix (5.0.0)
24
+ rake (13.0.6)
25
+ rexml (3.2.5)
26
+ webmock (3.13.0)
27
+ addressable (>= 2.3.6)
28
+ crack (>= 0.3.2)
29
+ hashdiff (>= 0.4.0, < 2.0.0)
30
+
31
+ PLATFORMS
32
+ x86_64-darwin-20
33
+
34
+ DEPENDENCIES
35
+ bomtempo!
36
+ rake (~> 13.0)
37
+
38
+ BUNDLED WITH
39
+ 2.3.19
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 weliton jose
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # Bomtempo
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/bomtempo`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Install the gem and add to the application's Gemfile by executing:
10
+
11
+ $ bundle add bomtempo
12
+
13
+ If bundler is not being used to manage dependencies, install the gem by executing:
14
+
15
+ $ gem install bomtempo
16
+
17
+ ## Usage
18
+
19
+ TODO: Write usage instructions here
20
+
21
+ ## Development
22
+
23
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
24
+
25
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
26
+
27
+ ## Contributing
28
+
29
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/bomtempo. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/bomtempo/blob/master/CODE_OF_CONDUCT.md).
30
+
31
+ ## License
32
+
33
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
34
+
35
+ ## Code of Conduct
36
+
37
+ Everyone interacting in the Bomtempo project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/bomtempo/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
@@ -0,0 +1,33 @@
1
+ module Bomtempo
2
+ require 'httparty'
3
+
4
+ class Coordenate
5
+ API_GEO='https://api.openweathermap.org/geo/1.0/direct'
6
+
7
+ def initialize(args)
8
+ @city = args[:city]
9
+ @state = args[:state]
10
+ @country = args[:country] || "BR"
11
+ end
12
+
13
+ def get
14
+ return "City is required" unless !@city.nil?
15
+ return "State is required" unless !@state.nil?
16
+
17
+ parameters = I18n.transliterate [@city, @state, @country].join(',')
18
+
19
+ url = "#{API_GEO}?q=#{parameters}&limit=5&appid=#{Class.nesting[-1].get_token}"
20
+ response = JSON.parse(HTTParty.get(url).body)[0]
21
+
22
+ return if response.nil?
23
+
24
+ {
25
+ coordenate: {
26
+ lat: response["lat"],
27
+ lon: response["lon"],
28
+ },
29
+ city: response["name"]
30
+ }
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,44 @@
1
+ module Bomtempo
2
+ require 'httparty'
3
+
4
+ class OneCall
5
+ API_ONE_CALL = "https://api.openweathermap.org/data/3.0/onecall"
6
+
7
+ def initialize(locate)
8
+ @lat = (locate[:coordenate] && locate[:coordenate][:lat])? locate[:coordenate][:lat] : nil
9
+ @lon = (locate[:coordenate] && locate[:coordenate][:lon])? locate[:coordenate][:lon] : nil
10
+ @city = locate[:city]
11
+ end
12
+
13
+ def next_five_days
14
+ return "City is required" unless !@city.nil?
15
+ return "Coordenate is required" unless !@lat.nil? || !@lon.nil?
16
+
17
+ url = "#{API_ONE_CALL}?lat=#{@lat}&lon=#{@lon}" +
18
+ "&appid=#{Class.nesting[-1].get_token}" +
19
+ "&units=metric&lang=pt_BR&exclude=hourly,minutely,alerts"
20
+
21
+ response = JSON.parse(HTTParty.get(url).body)
22
+ generate_body(response["daily"])
23
+ end
24
+
25
+ private
26
+
27
+ def generate_body(args)
28
+ txt = ""
29
+ txt += "#{args[0]["temp"]["day"].ceil}°C #{args[0]["weather"][0]["description"]} em #{@city} em #{Time.at(args[0]["dt"]).strftime('%d/%m')}."
30
+ txt += " Média para os próximos dias:"
31
+
32
+ args.each_with_index do |item, index|
33
+ next if index == 0
34
+ next if index > 5
35
+
36
+ txt += " #{item["temp"]["day"].ceil}°C em "+
37
+ "#{Time.at(item["dt"]).strftime('%d/%m')}"+
38
+ "#{(index == 5)? ".": ","}"
39
+ end
40
+
41
+ txt
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bomtempo
4
+ VERSION = "0.1.0"
5
+ end
data/lib/bomtempo.rb ADDED
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "bomtempo/version"
4
+
5
+ require_relative "bomtempo/coordenate"
6
+ require_relative "bomtempo/one_call"
7
+
8
+ module Bomtempo
9
+ class Error < StandardError; end
10
+
11
+ class << self
12
+ attr_accessor :access_token
13
+
14
+ def config
15
+ yield self
16
+ end
17
+
18
+ def weather_in(args)
19
+ locate = Coordenate.new(args).get
20
+ OneCall.new(locate).next_five_days
21
+ end
22
+
23
+ def get_token
24
+ @access_token
25
+ end
26
+ end
27
+ end
28
+
29
+
30
+ # https://api.openweathermap.org/data/2.5/weather?lat=-15.5986686&lon=-56.0991301&appid=27a54f60a77ebe0a3d6bb5f926753e03
data/sig/bomtempo.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Bomtempo
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bomtempo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - weliton jose
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-10-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: webmock
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Bom Tempo, get a weather forecast for the next few days
42
+ email:
43
+ - welitonj.jose@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".DS_Store"
49
+ - CHANGELOG.md
50
+ - CODE_OF_CONDUCT.md
51
+ - Gemfile
52
+ - Gemfile.lock
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - lib/bomtempo.rb
57
+ - lib/bomtempo/coordenate.rb
58
+ - lib/bomtempo/one_call.rb
59
+ - lib/bomtempo/version.rb
60
+ - sig/bomtempo.rbs
61
+ homepage: https://stowe.com.br
62
+ licenses:
63
+ - MIT
64
+ metadata:
65
+ homepage_uri: https://stowe.com.br
66
+ source_code_uri: https://stowe.com.br
67
+ changelog_uri: https://stowe.com.br
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: 2.6.0
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubygems_version: 3.3.19
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: weather forecast.
87
+ test_files: []