maju 0.0.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 +7 -0
- data/.rspec +2 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +58 -0
- data/LICENSE.txt +21 -0
- data/README.md +69 -0
- data/Rakefile +8 -0
- data/lib/maju/maju.rb +45 -0
- data/lib/maju/support/error.rb +14 -0
- data/lib/maju/support/helpers.rb +54 -0
- data/lib/maju/version.rb +5 -0
- data/lib/maju.rb +5 -0
- data/sig/maju.rbs +4 -0
- metadata +60 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 609dd3f7ad78fddfa86061824a674bce4ef6fecdb821351c2bb6941ee8db8a8b
|
4
|
+
data.tar.gz: 75d72a96ffaab01517bcf44ac480e032b0f0bec5abbfad95aafe7717b03556c1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6cf342cb602f4d070b3110e53ea44bec41ae7ad7d6ee788e11044791bb25cf85b5b0bab0643936a9c662c0d05460770c6473eac98829974a5832edfc7a226e7c
|
7
|
+
data.tar.gz: cdd3e7a4a3881e242aea3cd2a9ec0b99627f0a0c75500dae0bc58c577a7783fe052af7b5eb76d7aa343f491386b999df51bd25c054a8840ba1ff963d2c2de27b
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
maju (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
coderay (1.1.3)
|
10
|
+
diff-lcs (1.5.0)
|
11
|
+
domain_name (0.5.20190701)
|
12
|
+
unf (>= 0.0.5, < 1.0.0)
|
13
|
+
http-accept (1.7.0)
|
14
|
+
http-cookie (1.0.5)
|
15
|
+
domain_name (~> 0.5)
|
16
|
+
method_source (1.0.0)
|
17
|
+
mime-types (3.4.1)
|
18
|
+
mime-types-data (~> 3.2015)
|
19
|
+
mime-types-data (3.2022.0105)
|
20
|
+
netrc (0.11.0)
|
21
|
+
pry (0.14.2)
|
22
|
+
coderay (~> 1.1)
|
23
|
+
method_source (~> 1.0)
|
24
|
+
rake (13.0.6)
|
25
|
+
rest-client (2.1.0)
|
26
|
+
http-accept (>= 1.7.0, < 2.0)
|
27
|
+
http-cookie (>= 1.0.2, < 2.0)
|
28
|
+
mime-types (>= 1.16, < 4.0)
|
29
|
+
netrc (~> 0.8)
|
30
|
+
rspec (3.12.0)
|
31
|
+
rspec-core (~> 3.12.0)
|
32
|
+
rspec-expectations (~> 3.12.0)
|
33
|
+
rspec-mocks (~> 3.12.0)
|
34
|
+
rspec-core (3.12.1)
|
35
|
+
rspec-support (~> 3.12.0)
|
36
|
+
rspec-expectations (3.12.2)
|
37
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
38
|
+
rspec-support (~> 3.12.0)
|
39
|
+
rspec-mocks (3.12.3)
|
40
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
41
|
+
rspec-support (~> 3.12.0)
|
42
|
+
rspec-support (3.12.0)
|
43
|
+
unf (0.1.4)
|
44
|
+
unf_ext
|
45
|
+
unf_ext (0.0.8.2)
|
46
|
+
|
47
|
+
PLATFORMS
|
48
|
+
arm64-darwin-22
|
49
|
+
|
50
|
+
DEPENDENCIES
|
51
|
+
maju!
|
52
|
+
pry
|
53
|
+
rake (~> 13.0)
|
54
|
+
rest-client (~> 2.1)
|
55
|
+
rspec (~> 3.0)
|
56
|
+
|
57
|
+
BUNDLED WITH
|
58
|
+
2.4.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 Raphael Ivan
|
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,69 @@
|
|
1
|
+
# StringHelpers
|
2
|
+
Get weather informations from OpenWeather
|
3
|
+
|
4
|
+
## Install
|
5
|
+
|
6
|
+
```sh
|
7
|
+
gem install maju
|
8
|
+
```
|
9
|
+
or add to your Gemfile
|
10
|
+
|
11
|
+
```sh
|
12
|
+
gem maju
|
13
|
+
```
|
14
|
+
|
15
|
+
## Configuration
|
16
|
+
Before usage, you need to create a account on[Open Weather Site](https://openweathermap.org/) and gerenate a API key. To create an API key, follow the steps in [this tutorial](https://openweathermap.org/guide)
|
17
|
+
|
18
|
+
After get your API KEY, you need to start the client.
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
client = Maju::Client.new(api_token: 'YOUR_API_KEY_HERE')
|
22
|
+
```
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
Get today information about weather. You need to pass city name params
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
client.current(city: 'Monte Santo de Minas')
|
31
|
+
```
|
32
|
+
or to pass lat and long cordinates
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
client.current(lat: '-21.2049202', long: '-47.0943532')
|
36
|
+
```
|
37
|
+
|
38
|
+
## Geocode
|
39
|
+
|
40
|
+
if you need to find out lat and long of some city you can use geocode method
|
41
|
+
```ruby
|
42
|
+
client.geocode(city: 'Monte Santo de Minas')
|
43
|
+
```
|
44
|
+
will returns:
|
45
|
+
|
46
|
+
```json
|
47
|
+
[
|
48
|
+
{
|
49
|
+
"name": "Mococa",
|
50
|
+
"lat": -21.464731,
|
51
|
+
"lon": -47.002405,
|
52
|
+
"country": "BR",
|
53
|
+
"state": "São Paulo"
|
54
|
+
}
|
55
|
+
]
|
56
|
+
```
|
57
|
+
|
58
|
+
## Forecasts
|
59
|
+
To get forecast for the days ahead, you can use the forecast method. If you don't know lat and long informations, use the geocode method.
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
client.current(lat: '-21.2049202', long: '-47.0943532')
|
63
|
+
```
|
64
|
+
|
65
|
+
|
66
|
+
## License
|
67
|
+
StringHelper is available under the MIT license.
|
68
|
+
|
69
|
+
|
data/Rakefile
ADDED
data/lib/maju/maju.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
require_relative 'support/helpers'
|
3
|
+
require_relative 'support/error'
|
4
|
+
|
5
|
+
module Maju
|
6
|
+
class Client
|
7
|
+
include Maju::Helpers
|
8
|
+
|
9
|
+
attr_accessor :token, :lang, :unit
|
10
|
+
|
11
|
+
def initialize(options)
|
12
|
+
@token = options[:api_token]
|
13
|
+
@lang = options[:lang] ? options[:lang] : 'en'
|
14
|
+
@unit = check_metric(options[:unit].to_s)
|
15
|
+
|
16
|
+
Maju::Errors.api_token_blank if !@token || @token.empty?
|
17
|
+
end
|
18
|
+
|
19
|
+
def current(params)
|
20
|
+
Maju::Errors.city_geocode_blank if params[:city].nil? && params[:lat].nil?
|
21
|
+
|
22
|
+
url = api_url_current(params)
|
23
|
+
response = RestClient.get(url, headers)
|
24
|
+
json(response)
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
def forecast(params)
|
29
|
+
Maju::Errors.city_geocode_blank if params[:city].nil? && params[:lat].nil?
|
30
|
+
|
31
|
+
url = api_url_forecast(params)
|
32
|
+
response = RestClient.get(url, headers)
|
33
|
+
json(response)
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
def geocode(params)
|
38
|
+
Maju::Errors.city_name_blank if params[:city].nil? or params[:city].to_s.empty?
|
39
|
+
|
40
|
+
url = api_url_geocode(params)
|
41
|
+
response = RestClient.get(url, headers)
|
42
|
+
json(response).count > 1 ? json(response) : json(response).first
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Maju::Errors
|
2
|
+
def self.api_token_blank
|
3
|
+
raise "API-TOKEN: Need to configure api_token. Use: Maju::Client.new(api_token: <YOUR_API_TOKEN>)"
|
4
|
+
end
|
5
|
+
|
6
|
+
|
7
|
+
def self.city_geocode_blank
|
8
|
+
raise "Provider city or lat log params. Use: {city: 'Mococa', lat: 'xxxxx', long: 'xxxxxx'} "
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.city_name_blank
|
12
|
+
raise "Provider the city name. Use: {city: 'Mococa' } "
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Maju::Helpers
|
4
|
+
def api_url_base
|
5
|
+
"https://api.openweathermap.org"
|
6
|
+
end
|
7
|
+
|
8
|
+
def api_url_current(params)
|
9
|
+
"#{api_url_base}/data/2.5/weather?" + parsed_params(params)
|
10
|
+
end
|
11
|
+
|
12
|
+
def api_url_forecast(params)
|
13
|
+
days_count = (params[:days_count] && params[:days_count] <= 15) ? params[:days_count] : 15
|
14
|
+
|
15
|
+
url = "#{api_url_base}/data/2.5/forecast" + parsed_params(params)
|
16
|
+
url +="&cnt=#{days_count}" if params && params[:days_count]
|
17
|
+
url
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
def api_url_geocode(params)
|
22
|
+
url = "#{api_url_base}/geo/1.0/direct" + parsed_params(params)
|
23
|
+
url
|
24
|
+
end
|
25
|
+
|
26
|
+
def headers
|
27
|
+
{}
|
28
|
+
end
|
29
|
+
|
30
|
+
def parsed_params(params)
|
31
|
+
if params[:city]
|
32
|
+
"?lang=#{@lang}&units=#{@unit}&q=#{params[:city]}&appid=#{@token}"
|
33
|
+
else
|
34
|
+
"?lang=#{@lang}&units=#{@unit}&appid=#{@token}&lat=#{params[:lat]}&lon=#{params[:long]}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def json(json)
|
39
|
+
JSON.parse(json)
|
40
|
+
end
|
41
|
+
|
42
|
+
def check_metric(metric)
|
43
|
+
case metric.downcase
|
44
|
+
when 'celsius'
|
45
|
+
'metric'
|
46
|
+
when 'fahrenheit'
|
47
|
+
'imperial'
|
48
|
+
when 'Kelvin'
|
49
|
+
'standard'
|
50
|
+
else
|
51
|
+
'metric'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/maju/version.rb
ADDED
data/lib/maju.rb
ADDED
data/sig/maju.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: maju
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Raphael Ivan
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-02-13 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Get weather information directly from the console or easily integrate
|
14
|
+
your application with OpenWeather
|
15
|
+
email:
|
16
|
+
- eu@rpha.me
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- ".rspec"
|
22
|
+
- Gemfile
|
23
|
+
- Gemfile.lock
|
24
|
+
- LICENSE.txt
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- lib/maju.rb
|
28
|
+
- lib/maju/maju.rb
|
29
|
+
- lib/maju/support/error.rb
|
30
|
+
- lib/maju/support/helpers.rb
|
31
|
+
- lib/maju/version.rb
|
32
|
+
- sig/maju.rbs
|
33
|
+
homepage: https://rubygems.org/gems/maju
|
34
|
+
licenses:
|
35
|
+
- MIT
|
36
|
+
metadata:
|
37
|
+
allowed_push_host: https://rubygems.org
|
38
|
+
homepage_uri: https://rubygems.org/gems/maju
|
39
|
+
source_code_uri: https://github.com/raphaelivan/maju
|
40
|
+
changelog_uri: https://github.com/raphaelivan/maju
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 2.6.0
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
requirements: []
|
56
|
+
rubygems_version: 3.3.7
|
57
|
+
signing_key:
|
58
|
+
specification_version: 4
|
59
|
+
summary: Get weather informations from OpenWeather
|
60
|
+
test_files: []
|