open_weather_sdk 1.0.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 +7 -0
- data/.github/workflows/linters.yml +19 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +61 -0
- data/CHANGELOG.md +10 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +50 -0
- data/LICENSE.txt +21 -0
- data/README.md +96 -0
- data/Rakefile +12 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/open_weather.rb +19 -0
- data/lib/open_weather/Configuration.rb +10 -0
- data/lib/open_weather/current_weather.rb +30 -0
- data/lib/open_weather/helpers/helpers.rb +43 -0
- data/lib/open_weather/hourly_forecast.rb +36 -0
- data/lib/open_weather/network_request.rb +107 -0
- data/lib/open_weather/version.rb +3 -0
- data/open_weather.gemspec +37 -0
- metadata +108 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c46f5a62b58f8cc71e974c3565d722c2fd4e9658fe4047b0b364524a3cad3eca
|
4
|
+
data.tar.gz: e6395bc83b03c45b0b250958b7016213377de16ccca6166d1b18601cd762de0f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 338395764a07c9089a08e431bf7ab6239dc4db51d10bb5ac6561789054a5b3be44e386bb26c77a82b57868de1abcff3444282c5d4746d01aae49288852df05f2
|
7
|
+
data.tar.gz: d0a852e921816bb7461bd1dee82e775bd21a3458292fb3ad2bced7f306b14181435d05128f18b7fb162fba8e6f2f2a188f28f594830c0967d447c4b9ad9bd28c
|
@@ -0,0 +1,19 @@
|
|
1
|
+
name: Linters
|
2
|
+
|
3
|
+
on: pull_request
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
rubocop:
|
7
|
+
name: Rubocop
|
8
|
+
runs-on: ubuntu-18.04
|
9
|
+
steps:
|
10
|
+
- uses: actions/checkout@v2
|
11
|
+
- uses: actions/setup-ruby@v1
|
12
|
+
with:
|
13
|
+
ruby-version: 2.5.x
|
14
|
+
- name: Setup Rubocop
|
15
|
+
run: |
|
16
|
+
gem install --no-document rubocop:'~>1.7'
|
17
|
+
[ -f .rubocop.yml ] || .rubocop.yml
|
18
|
+
- name: Rubocop Report
|
19
|
+
run: rubocop --color
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
AllCops:
|
2
|
+
NewCops: enable
|
3
|
+
Exclude:
|
4
|
+
- "Guardfile"
|
5
|
+
- "Rakefile"
|
6
|
+
- "node_modules/**/*"
|
7
|
+
|
8
|
+
DisplayCopNames: true
|
9
|
+
TargetRubyVersion: "2.5"
|
10
|
+
Layout/LineLength:
|
11
|
+
Max: 120
|
12
|
+
Metrics/MethodLength:
|
13
|
+
Max: 20
|
14
|
+
Metrics/AbcSize:
|
15
|
+
Max: 50
|
16
|
+
Metrics/ClassLength:
|
17
|
+
Max: 150
|
18
|
+
Metrics/ParameterLists:
|
19
|
+
Max: 10
|
20
|
+
Metrics/BlockLength:
|
21
|
+
IgnoredMethods: ["describe"]
|
22
|
+
Max: 30
|
23
|
+
|
24
|
+
Style/Documentation:
|
25
|
+
Enabled: false
|
26
|
+
Style/ClassAndModuleChildren:
|
27
|
+
Enabled: false
|
28
|
+
Style/EachForSimpleLoop:
|
29
|
+
Enabled: false
|
30
|
+
Style/AndOr:
|
31
|
+
Enabled: false
|
32
|
+
Style/DefWithParentheses:
|
33
|
+
Enabled: false
|
34
|
+
Style/FrozenStringLiteralComment:
|
35
|
+
EnforcedStyle: never
|
36
|
+
|
37
|
+
Layout/HashAlignment:
|
38
|
+
EnforcedColonStyle: key
|
39
|
+
Layout/ExtraSpacing:
|
40
|
+
AllowForAlignment: false
|
41
|
+
Layout/MultilineMethodCallIndentation:
|
42
|
+
Enabled: true
|
43
|
+
EnforcedStyle: indented
|
44
|
+
Lint/RaiseException:
|
45
|
+
Enabled: true
|
46
|
+
Lint/StructNewOverride:
|
47
|
+
Enabled: false
|
48
|
+
Naming/FileName:
|
49
|
+
Enabled: false
|
50
|
+
Lint/UselessAssignment:
|
51
|
+
Enabled: false
|
52
|
+
Lint/DuplicateMethods:
|
53
|
+
Enabled: false
|
54
|
+
Style/HashEachMethods:
|
55
|
+
Enabled: false
|
56
|
+
Style/HashTransformKeys:
|
57
|
+
Enabled: false
|
58
|
+
Style/HashTransformValues:
|
59
|
+
Enabled: false
|
60
|
+
Style/HashLikeCase:
|
61
|
+
Enabled: false
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
## [Todo]
|
2
|
+
|
3
|
+
- [ _ ] Add support for `One Call API`
|
4
|
+
- [ _ ] Add support for `Daily Forecast 16 days`
|
5
|
+
- [ _ ] Add support for `Climatic Forecast 30 days`
|
6
|
+
- [ _ ] Add support for `Bulk Downloading`
|
7
|
+
- [ _ ] Add support for `Solar Radiation API`
|
8
|
+
- [ _ ] Add support for `Global Weather Alerts Push notifications`
|
9
|
+
- [ _ ] Add support for `5 Day / 3 Hour Forecast`
|
10
|
+
- [ _ ] Add support for `Road Risk API`
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
open_weather (0.1.0)
|
5
|
+
httparty
|
6
|
+
json
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
ast (2.4.2)
|
12
|
+
httparty (0.18.1)
|
13
|
+
mime-types (~> 3.0)
|
14
|
+
multi_xml (>= 0.5.2)
|
15
|
+
json (2.5.1)
|
16
|
+
mime-types (3.3.1)
|
17
|
+
mime-types-data (~> 3.2015)
|
18
|
+
mime-types-data (3.2021.0704)
|
19
|
+
multi_xml (0.6.0)
|
20
|
+
parallel (1.20.1)
|
21
|
+
parser (3.0.2.0)
|
22
|
+
ast (~> 2.4.1)
|
23
|
+
rainbow (3.0.0)
|
24
|
+
rake (13.0.6)
|
25
|
+
regexp_parser (2.1.1)
|
26
|
+
rexml (3.2.5)
|
27
|
+
rubocop (1.19.0)
|
28
|
+
parallel (~> 1.10)
|
29
|
+
parser (>= 3.0.0.0)
|
30
|
+
rainbow (>= 2.2.2, < 4.0)
|
31
|
+
regexp_parser (>= 1.8, < 3.0)
|
32
|
+
rexml
|
33
|
+
rubocop-ast (>= 1.9.1, < 2.0)
|
34
|
+
ruby-progressbar (~> 1.7)
|
35
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
36
|
+
rubocop-ast (1.10.0)
|
37
|
+
parser (>= 3.0.1.1)
|
38
|
+
ruby-progressbar (1.11.0)
|
39
|
+
unicode-display_width (2.0.0)
|
40
|
+
|
41
|
+
PLATFORMS
|
42
|
+
x86_64-darwin-20
|
43
|
+
|
44
|
+
DEPENDENCIES
|
45
|
+
open_weather!
|
46
|
+
rake (~> 13.0)
|
47
|
+
rubocop (~> 1.7)
|
48
|
+
|
49
|
+
BUNDLED WITH
|
50
|
+
2.2.23
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 code salley
|
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,96 @@
|
|
1
|
+
# OpenWeather
|
2
|
+
|
3
|
+
Open Weather Gem, A wrapper around open weather API, makes working with weather fun.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'open_weather'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install open_weather
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
### Configuration
|
24
|
+
|
25
|
+
Create a config file in initializers and add an API key `config/initializers/open_weather.rb`
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
OpenWeather.config do |config|
|
29
|
+
config.api_key = 'your key'
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
## Current Weather Data
|
34
|
+
|
35
|
+
Params Overview
|
36
|
+
|
37
|
+
```h
|
38
|
+
||- name -> string
|
39
|
+
||- id -> string || integer, read more about city id's on https://openweathermap.org/current#cityid
|
40
|
+
||- coords -> array [lon, lat]
|
41
|
+
||- zipcode -> string || integer
|
42
|
+
||- country -> string: country code eg: GH -> Ghana
|
43
|
+
|[optional]|- lang -> string: eg: en -> english, fr -> french
|
44
|
+
|[optional]|- units -> string: eg: standard, metric, imperial
|
45
|
+
|
46
|
+
```
|
47
|
+
|
48
|
+
### Get weather by city name
|
49
|
+
|
50
|
+
- ```ruby
|
51
|
+
OpenWeather::CurrentWeather.by_city(name: "london") #params: name -> "london", lang -> 'en', units -> "standard"
|
52
|
+
return => {"coord"=>{"lon"=>-0.1257, "lat"=>51.5085}, "weather"=>[{"id"=>804, "main"=>"Clouds", "description"=>"overcast clouds", "icon"=>"04n"}], "base"=>"stations", "main"=>{"temp"=>291.69, "feels_like"=>291.66, "temp_min"=>289.32, "temp_max"=>293.05, "pressure"=>1022, "humidity"=>79}, "visibility"=>10000, "wind"=>{"speed"=>3.6, "deg"=>220}, "clouds"=>{"all"=>97}, "dt"=>1628885709, "sys"=>{"type"=>2, "id"=>2019646, "country"=>"GB", "sunrise"=>1628829784, "sunset"=>1628882870}, "timezone"=>3600, "id"=>2643743, "name"=>"London", "cod"=>200}
|
53
|
+
```
|
54
|
+
|
55
|
+
### Get weather by zipcode and country code. more info -> [openweathermap.org](https://openweathermap.org/current#zip)
|
56
|
+
|
57
|
+
- ```ruby
|
58
|
+
OpenWeather::CurrentWeather.by_zip(zipcode: 94040, country: "us")
|
59
|
+
#params: zipcode -> 94040, lang -> 'en', units -> "standard"
|
60
|
+
```
|
61
|
+
|
62
|
+
### Get weather by geographic coordinates[lon, lat]. more info -> [openweathermap.org](https://openweathermap.org/current#geo)
|
63
|
+
|
64
|
+
- ```ruby
|
65
|
+
OpenWeather::CurrentWeather.by_coords(coords: [-0.8393, 9.40078])
|
66
|
+
#params: corods -> [lon, lat], lang -> 'en', units -> "standard"
|
67
|
+
```
|
68
|
+
|
69
|
+
### Get weather by city id. more info -> [openweathermap.org](https://openweathermap.org/current#cityid)
|
70
|
+
|
71
|
+
- ```ruby
|
72
|
+
OpenWeather::CurrentWeather.by_city_id(id: 2294877)
|
73
|
+
#params: id -> 2294877, lang -> 'en', units -> "standard"
|
74
|
+
```
|
75
|
+
|
76
|
+
## Hourly Forecast 4 days [Requires Pro Api]
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
OpenWeather::HourlyForecast.by_city(# name, units, lang)
|
80
|
+
OpenWeather::HourlyForecast.by_city_id(# id, units, lang)
|
81
|
+
OpenWeather::HourlyForecast.by_coords(# [lon lat], units, lang)
|
82
|
+
OpenWeather::HourlyForecast.by_find(# [lon, lat], count, units, lang)
|
83
|
+
OpenWeather::HourlyForecast.by_zip(# zipcode, units, lang)
|
84
|
+
```
|
85
|
+
|
86
|
+
## Follow me √
|
87
|
+
|
88
|
+
[Twitter ≈> \_\_salley](https://twitter.com/__salley)
|
89
|
+
|
90
|
+
## Contributing
|
91
|
+
|
92
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/codesalley/openweather.
|
93
|
+
|
94
|
+
## License
|
95
|
+
|
96
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'open_weather'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/open_weather.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'open_weather/Configuration'
|
2
|
+
require 'open_weather/version'
|
3
|
+
require 'open_weather/current_weather'
|
4
|
+
require 'open_weather/hourly_forecast'
|
5
|
+
require 'open_weather/network_request'
|
6
|
+
|
7
|
+
module OpenWeather
|
8
|
+
class << self
|
9
|
+
attr_accessor :configuration
|
10
|
+
|
11
|
+
def configuration
|
12
|
+
@configuration ||= Configuration.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def config
|
16
|
+
yield(configuration)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'json'
|
3
|
+
require_relative 'helpers/helpers'
|
4
|
+
require 'logger'
|
5
|
+
|
6
|
+
module OpenWeather
|
7
|
+
class CurrentWeather
|
8
|
+
# helper params to return defferent urls "current_wether", "hourly"
|
9
|
+
@helper = Helpers.new
|
10
|
+
def self.by_city(name: '', units: 'standard', lang: 'en')
|
11
|
+
OpenWeather.configuration.weather_base_uri = @helper.swtich_url('current_wether')
|
12
|
+
OpenWeather::NetworkRequest.by_city(name: name, units: units, lang: lang)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.by_city_id(id: '', units: 'standard', lang: 'en')
|
16
|
+
OpenWeather.configuration.weather_base_uri = @helper.swtich_url('current_wether')
|
17
|
+
OpenWeather::NetworkRequest.by_city_id(id: id, units: units, lang: lang)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.by_coords(coords: [], units: 'standard', lang: 'en')
|
21
|
+
OpenWeather.configuration.weather_base_uri = @helper.swtich_url('current_wether')
|
22
|
+
OpenWeather::NetworkRequest.by_coords(coords: coords, units: units, lang: lang)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.by_zip(zipcode: '', country: '', units: 'standard', lang: 'en')
|
26
|
+
OpenWeather.configuration.weather_base_uri = @helper.swtich_url('current_wether')
|
27
|
+
OpenWeather::NetworkRequest.by_zip(zipcode: zipcode, country: country, units: units, lang: lang)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'open_weather'
|
3
|
+
|
4
|
+
class Helpers
|
5
|
+
def to_json(data)
|
6
|
+
unless data
|
7
|
+
tmp = {}
|
8
|
+
return JSON.parse(tmp)
|
9
|
+
end
|
10
|
+
JSON.parse data
|
11
|
+
end
|
12
|
+
|
13
|
+
def swtich_url(method)
|
14
|
+
case method
|
15
|
+
when 'current_wether'
|
16
|
+
'https://api.openweathermap.org/data/2.5/weather?'
|
17
|
+
when 'hourly'
|
18
|
+
'pro.openweathermap.org/data/2.5/forecast/hourly?'
|
19
|
+
when 'find'
|
20
|
+
'api.openweathermap.org/data/2.5/find?'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def name_to_url(url, name, api_key, units, lang)
|
25
|
+
"#{url}q=#{name}&appid=#{api_key}&lang=#{lang}&units=#{units}"
|
26
|
+
end
|
27
|
+
|
28
|
+
def id_to_url(url, name, api_key, units, lang)
|
29
|
+
"#{url}id=#{name}&appid=#{api_key}&lang=#{lang}&units=#{units}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def cords_to_url(url, coords, api_key, units, lang)
|
33
|
+
"#{url}lat=#{coords[1]}&lon=#{coords[0]}&appid=#{api_key}&lang=#{lang}&units=#{units}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def zipcode_to_url(url, zip, country, api_key, units, lang)
|
37
|
+
"#{url}zip=#{zip},#{country}&appid=#{api_key}&lang=#{lang}&units=#{units}"
|
38
|
+
end
|
39
|
+
|
40
|
+
def find_to_url(url, coords, count, api_key, units, lang)
|
41
|
+
"#{url}lat=#{coords[1]}&lon=#{coords[0]}&appid=#{api_key}&cnt=#{count}&lang=#{lang}&units=#{units}"
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'open_weather'
|
3
|
+
require 'json'
|
4
|
+
require_relative 'helpers/helpers'
|
5
|
+
require 'logger'
|
6
|
+
|
7
|
+
module OpenWeather
|
8
|
+
class HourlyForecast
|
9
|
+
@helper = Helpers.new
|
10
|
+
# helper params to return defferent urls "current_wether", "hourly"
|
11
|
+
def self.by_city(name: '', units: 'standard', lang: 'en')
|
12
|
+
OpenWeather.configuration.weather_base_uri = @helper.swtich_url('hourly')
|
13
|
+
OpenWeather::NetworkRequest.by_city(name: name, units: units, lang: lang)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.by_city_id(id: '', units: 'standard', lang: 'en')
|
17
|
+
OpenWeather.configuration.weather_base_uri = @helper.swtich_url('hourly')
|
18
|
+
OpenWeather::NetworkRequest.by_city_id(id: id, units: units, lang: lang)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.by_coords(coords: [], units: 'standard', lang: 'en')
|
22
|
+
OpenWeather.configuration.weather_base_uri = @helper.swtich_url('hourly')
|
23
|
+
OpenWeather::NetworkRequest.by_coords(coords: coords, units: units, lang: lang)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.by_find(coords: [], count: 3, units: 'standard', lang: 'en')
|
27
|
+
OpenWeather.configuration.weather_base_uri = @helper.swtich_url('hourly')
|
28
|
+
OpenWeather::NetworkRequest.by_coords(coords: coords, count: count, units: units, lang: lang)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.by_zip(zipcode: '', country: '', units: 'standard', lang: 'en')
|
32
|
+
OpenWeather.configuration.weather_base_uri = @helper.swtich_url('hourly')
|
33
|
+
OpenWeather::NetworkRequest.by_zip(zipcode: zipcode, country: country, units: units, lang: lang)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'open_weather'
|
3
|
+
require 'json'
|
4
|
+
require_relative 'helpers/helpers'
|
5
|
+
require 'logger'
|
6
|
+
|
7
|
+
module OpenWeather
|
8
|
+
class NetworkRequest
|
9
|
+
@helper = Helpers.new
|
10
|
+
def self.by_city(name: '', units: 'standard', lang: 'en')
|
11
|
+
url = OpenWeather.configuration.weather_base_uri
|
12
|
+
api_key = OpenWeather.configuration.api_key
|
13
|
+
uri = @helper.name_to_url(url, name, api_key, units, lang)
|
14
|
+
begin
|
15
|
+
@response = HTTParty.get(uri)
|
16
|
+
rescue StandardError => e
|
17
|
+
logger = Logger.new($stdout)
|
18
|
+
logger.error('Network is required')
|
19
|
+
return []
|
20
|
+
end
|
21
|
+
if @response.message == 'Unauthorized' || @response.code == 404
|
22
|
+
logger = Logger.new($stdout)
|
23
|
+
logger.error('Api Key is required')
|
24
|
+
return []
|
25
|
+
end
|
26
|
+
@helper.to_json(@response.body)
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.by_city_id(id: '', units: 'standard', lang: 'en')
|
30
|
+
url = OpenWeather.configuration.weather_base_uri
|
31
|
+
api_key = OpenWeather.configuration.api_key
|
32
|
+
uri = @helper.id_to_url(url, id, api_key, units, lang)
|
33
|
+
begin
|
34
|
+
@response = HTTParty.get(uri)
|
35
|
+
rescue StandardError => e
|
36
|
+
logger = Logger.new($stdout)
|
37
|
+
logger.error('Network is required')
|
38
|
+
return []
|
39
|
+
end
|
40
|
+
if @response.message == 'Unauthorized' || @response.code == 404
|
41
|
+
logger = Logger.new($stdout)
|
42
|
+
logger.error('Api Key is required')
|
43
|
+
return []
|
44
|
+
end
|
45
|
+
@helper.to_json(@response.body)
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.by_coords(coords: [], units: 'standard', lang: 'en')
|
49
|
+
api_key = OpenWeather.configuration.api_key
|
50
|
+
url = OpenWeather.configuration.weather_base_uri
|
51
|
+
uri = @helper.cords_to_url(url, coords, api_key, units, lang)
|
52
|
+
|
53
|
+
begin
|
54
|
+
@response = HTTParty.get(uri)
|
55
|
+
rescue StandardError => e
|
56
|
+
logger = Logger.new($stdout)
|
57
|
+
logger.error('Network is required')
|
58
|
+
return []
|
59
|
+
end
|
60
|
+
if @response.message == 'Unauthorized' || @response.code == 404
|
61
|
+
logger = Logger.new($stdout)
|
62
|
+
logger.error('Api Key is required')
|
63
|
+
return []
|
64
|
+
end
|
65
|
+
@helper.to_json(@response.body)
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.by_zip(zipcode: '', country: '', units: 'standard', lang: 'en')
|
69
|
+
api_key = OpenWeather.configuration.api_key
|
70
|
+
url = OpenWeather.configuration.weather_base_uri
|
71
|
+
uri = @helper.zipcode_to_url(url, zipcode, country, api_key, units, lang)
|
72
|
+
begin
|
73
|
+
@response = HTTParty.get(uri)
|
74
|
+
rescue StandardError => e
|
75
|
+
logger = Logger.new($stdout)
|
76
|
+
logger.error('Network is required')
|
77
|
+
return []
|
78
|
+
end
|
79
|
+
if @response.message == 'Unauthorized' || @response.code == 404
|
80
|
+
logger = Logger.new($stdout)
|
81
|
+
logger.error('Api Key is required')
|
82
|
+
return []
|
83
|
+
end
|
84
|
+
@helper.to_json(@response.body)
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.by_find(coords: [], count: '', units: 'standard', lang: 'en')
|
88
|
+
api_key = OpenWeather.configuration.api_key
|
89
|
+
url = OpenWeather.configuration.weather_base_uri
|
90
|
+
uri = @helper.find_to_url(url, coords, count, api_key, units, lang)
|
91
|
+
|
92
|
+
begin
|
93
|
+
@response = HTTParty.get(uri)
|
94
|
+
rescue StandardError => e
|
95
|
+
logger = Logger.new($stdout)
|
96
|
+
logger.error('Network is required')
|
97
|
+
return []
|
98
|
+
end
|
99
|
+
if @response.message == 'Unauthorized' || @response.code == 404
|
100
|
+
logger = Logger.new($stdout)
|
101
|
+
logger.error('Api Key is required')
|
102
|
+
return []
|
103
|
+
end
|
104
|
+
@helper.to_json(@response.body)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require_relative "lib/open_weather/version"
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "open_weather_sdk"
|
5
|
+
spec.version = OpenWeather::VERSION
|
6
|
+
spec.authors = ["code salley"]
|
7
|
+
spec.email = ["codesalley@gmail.com"]
|
8
|
+
|
9
|
+
spec.summary = "Openweather gem, getting weather made simple"
|
10
|
+
spec.description = "A wrapper around openwather api"
|
11
|
+
spec.homepage = "https://github.com/codesalley/openweather/blob/main/README.md"
|
12
|
+
spec.license = "MIT"
|
13
|
+
spec.required_ruby_version = ">= 2.5.0"
|
14
|
+
|
15
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'https://mygemserver.com'"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = "https://github.com/codesalley/openweather/blob/main/README.md"
|
19
|
+
spec.metadata["changelog_uri"] = "https://github.com/codesalley/openweather/blob/main/CHANGELOG.md"
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
25
|
+
end
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
# Uncomment to register a new dependency of your gem
|
31
|
+
spec.add_dependency "httparty"
|
32
|
+
spec.add_dependency "json"
|
33
|
+
spec.add_development_dependency "rspec"
|
34
|
+
|
35
|
+
# For more information and examples about making a new gem, checkout our
|
36
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: open_weather_sdk
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- code salley
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-08-15 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: json
|
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
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: A wrapper around openwather api
|
56
|
+
email:
|
57
|
+
- codesalley@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".github/workflows/linters.yml"
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- ".rubocop.yml"
|
66
|
+
- CHANGELOG.md
|
67
|
+
- Gemfile
|
68
|
+
- Gemfile.lock
|
69
|
+
- LICENSE.txt
|
70
|
+
- README.md
|
71
|
+
- Rakefile
|
72
|
+
- bin/console
|
73
|
+
- bin/setup
|
74
|
+
- lib/open_weather.rb
|
75
|
+
- lib/open_weather/Configuration.rb
|
76
|
+
- lib/open_weather/current_weather.rb
|
77
|
+
- lib/open_weather/helpers/helpers.rb
|
78
|
+
- lib/open_weather/hourly_forecast.rb
|
79
|
+
- lib/open_weather/network_request.rb
|
80
|
+
- lib/open_weather/version.rb
|
81
|
+
- open_weather.gemspec
|
82
|
+
homepage: https://github.com/codesalley/openweather/blob/main/README.md
|
83
|
+
licenses:
|
84
|
+
- MIT
|
85
|
+
metadata:
|
86
|
+
homepage_uri: https://github.com/codesalley/openweather/blob/main/README.md
|
87
|
+
source_code_uri: https://github.com/codesalley/openweather/blob/main/README.md
|
88
|
+
changelog_uri: https://github.com/codesalley/openweather/blob/main/CHANGELOG.md
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 2.5.0
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
requirements: []
|
104
|
+
rubygems_version: 3.2.3
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: Openweather gem, getting weather made simple
|
108
|
+
test_files: []
|