petrel 0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e4ca7d5b33db5c664a43da5f972104140f04dbed3c31b8b1bef9a79d9491e040
4
+ data.tar.gz: 4c5959a769371047b594e022d231d4de299df05ec2ef17f082620e248fbf2cef
5
+ SHA512:
6
+ metadata.gz: 87e5c57a1f86f03a7a61bbfaad34a134155bfa5634024825cfc1e3b45f298abb6763c9e4e791907f39670f33cc62bc7020649c017787acdfd82d053ff1fcf210
7
+ data.tar.gz: a2ec7a64517c0120b2a20f9a3b0b50ef6d32f5c60781586b2507f5d1f6575392e725e26d59e103906b0a3786692795257b2bd29ed277ef75113c31cb10a25d30
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ # Mac nonsense
2
+ .DS_Store
3
+
4
+ # Don't checkin Gemfile.lock
5
+ # See: http://yehudakatz.com/2010/12/16/clarifying-the-roles-of-the-gemspec-and-gemfile/
6
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2020 John Akers
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # Petrel
2
+
3
+ A RubyGem wrapp for [OpenWeatherMap's Free API]((https://openweathermap.org/appid))
4
+
5
+ ### Installation
6
+
7
+ ```rb
8
+ gem install petrel
9
+ ```
10
+
11
+ or in your Gemfile...
12
+
13
+ ```rb
14
+ gem 'petrel'
15
+ ```
16
+
17
+ ### Configuration
18
+
19
+ You will need to set your OpenWeather `api_key` before making requests. You can get one [here](https://home.openweathermap.org/users/sign_up).
20
+
21
+ ```rb
22
+ Petrel.configure do |c|
23
+ c.api_key = 'YOUR_API_KEY'
24
+ end
25
+ ```
26
+
27
+ Alternatively, you can do:
28
+
29
+ ```rb
30
+ Petrel.api_token = 'YOUR_API_TOKEN'
31
+ ```
32
+
33
+ ### Usage / Examples
34
+
35
+ Once configured, you have access to the below methods. They correspond to the available endpoints, listed on OpenWeatherMap's API.
36
+
37
+ ```rb
38
+ # 5 day / 3 hour forecast data
39
+ query = { q: 'San Francisco' }
40
+ Petrel.forecat(query)
41
+
42
+ # One Call
43
+ query = { lat: 37, lon: -122 }
44
+ Petrel.one_call(query)
45
+
46
+ # Current weather
47
+ query = { lat: 37, lon: -122 }
48
+ Petrel.weather(query)
49
+ ```
50
+
51
+ Full documentation on what can be in `query` can be found in OpenWeatherMap's API documentation [here](https://openweathermap.org/api).
@@ -0,0 +1,17 @@
1
+ module Petrel
2
+ module Configuration
3
+ BASE_URL = 'https://api.openweathermap.org/data/2.5'
4
+
5
+ attr_accessor :api_key
6
+
7
+ alias appid api_key
8
+
9
+ def url
10
+ BASE_URL
11
+ end
12
+
13
+ def configure
14
+ yield self
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,7 @@
1
+ module Petrel
2
+ def self.forecast(params)
3
+ weather_url = "#{url}/forecast"
4
+ query = params.merge(appid: appid)
5
+ HTTParty.get(weather_url, query: query)
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Petrel
2
+ def self.one_call(params)
3
+ one_call_url = "#{url}/onecall"
4
+ query = params.merge(appid: appid)
5
+ HTTParty.get(one_call_url, query: query)
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module Petrel
2
+ VERSION = '0.0.2'
3
+ end
@@ -0,0 +1,7 @@
1
+ module Petrel
2
+ def self.weather(params)
3
+ weather_url = "#{url}/weather"
4
+ query = params.merge(appid: appid)
5
+ HTTParty.get(weather_url, query: query)
6
+ end
7
+ end
data/lib/petrel.rb ADDED
@@ -0,0 +1,13 @@
1
+ # files
2
+ require 'petrel/version'
3
+ require 'petrel/configuration'
4
+ require 'petrel/forecast'
5
+ require 'petrel/one_call'
6
+ require 'petrel/weather'
7
+
8
+ # gems
9
+ require 'httparty'
10
+
11
+ module Petrel
12
+ extend Configuration
13
+ end
data/petrel.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ $LOAD_PATH.push(File.expand_path('../lib', __FILE__))
2
+
3
+ require 'petrel/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'petrel'
7
+ s.version = Petrel::VERSION
8
+ s.authors = ['John Akers']
9
+ s.homepage = 'https://github.com/johnakers/petrel'
10
+ s.summary = "RubyGem for OpenWeatherMap's current weather"
11
+ s.description = 'RubyGem wrapper for openweathermap.org'
12
+ s.licenses = ['MIT']
13
+ s.require_paths = ['lib']
14
+
15
+ #
16
+ s.add_dependency('httparty', '~> 0.18.1')
17
+
18
+ #
19
+ s.add_development_dependency('awesome_print', '~> 1.8.0')
20
+ s.add_development_dependency('rspec', '~> 3.9.0')
21
+ s.add_development_dependency('pry', '~> 0.13.1')
22
+
23
+ # files
24
+ s.files = `git ls-files`.split("\n")
25
+
26
+ # Remove this line for no squawking
27
+ s.post_install_message = '*squawk* *squawk* Thanks for using Petrel - John'
28
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Petrel::Configuration do
4
+ describe '.configure' do
5
+ it 'returns the set values' do
6
+ api_key = 'mock_api_key'
7
+
8
+ Petrel.configure do |c|
9
+ c.api_key = api_key
10
+ end
11
+
12
+ expect(Petrel.api_key).to eq(api_key)
13
+ expect(Petrel.appid).to eq(api_key)
14
+ expect(Petrel.url).to eq(
15
+ 'https://api.openweathermap.org/data/2.5'
16
+ )
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,95 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Petrel do
4
+ describe '.forecast' do
5
+ let(:query) do
6
+ {
7
+ lat: 37,
8
+ lon: -122
9
+ }
10
+ end
11
+
12
+ let(:forecast_response) do
13
+ double(
14
+ code: 200,
15
+ parsed_response: {
16
+ 'cod' => '200',
17
+ 'message' => 0,
18
+ 'cnt' => 40,
19
+ 'city' => {
20
+ 'id' => 5339111,
21
+ 'name' => 'Concord',
22
+ 'coord' => {
23
+ 'lat' => 38,
24
+ 'lon' => -122
25
+ },
26
+ 'country' => 'US',
27
+ 'population' => 122067,
28
+ 'timezone' => -25200,
29
+ 'sunrise' => 1601820404,
30
+ 'sunset' => 1601862363
31
+ },
32
+ 'list' => [
33
+ {
34
+ 'dt' => 1601877600,
35
+ 'main' => {
36
+ 'temp' => 293.98,
37
+ 'feels_like' => 292.18,
38
+ 'temp_min' => 293.98,
39
+ 'temp_max' => 296,
40
+ 'pressure' => 1015,
41
+ 'sea_level' => 1015,
42
+ 'grnd_level' => 1012,
43
+ 'humidity' => 46,
44
+ 'temp_kf' => -2.02
45
+ },
46
+ 'weather' => [
47
+ {
48
+ 'id' => 800,
49
+ 'main' => 'Clear',
50
+ 'description' => 'clear
51
+ sky',
52
+ 'icon' => '01n'
53
+ }
54
+ ],
55
+ 'clouds' => {
56
+ 'all' => 1
57
+ },
58
+ 'wind' => {
59
+ 'speed' => 2.18,
60
+ 'deg' => 216
61
+ },
62
+ 'visibility' => 10000,
63
+ 'pop' => 0,
64
+ 'sys' => {
65
+ 'pod' => 'n'
66
+ },
67
+ 'dt_txt' => '2020-10-05 06:00:00'
68
+ }
69
+ ]
70
+ }
71
+ )
72
+ end
73
+
74
+ before do
75
+ allow(HTTParty).to receive(:get).
76
+ and_return(forecast_response)
77
+
78
+ Petrel.configure do |c|
79
+ c.api_key = 'mock_api_key'
80
+ end
81
+ end
82
+
83
+ it 'returns the current weather' do
84
+ expect(HTTParty).to receive(:get).
85
+ with("#{Petrel.url}/forecast", query: {
86
+ lat: 37,
87
+ lon: -122,
88
+ appid: Petrel.appid
89
+ }).
90
+ and_return(forecast_response)
91
+
92
+ Petrel.forecast(query)
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,127 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Petrel do
4
+ describe '.one_call' do
5
+ let(:query) do
6
+ {
7
+ lat: 37,
8
+ lon: -122
9
+ }
10
+ end
11
+
12
+ let(:one_call_response) do
13
+ double(
14
+ code: 200,
15
+ parsed_response: {
16
+ 'lat' => 37,
17
+ 'lon' => -122,
18
+ 'timezone' => 'America/Los_Angeles',
19
+ 'timezone_offset' => -25200,
20
+ 'current' => {
21
+ 'dt' => 1601879386,
22
+ 'sunrise' => 1601820377,
23
+ 'sunset' => 1601862390,
24
+ 'temp' => 290.77,
25
+ 'feels_like' => 292.82,
26
+ 'pressure' => 1016,
27
+ 'humidity' => 100,
28
+ 'dew_point' => 290.77,
29
+ 'uvi' => 5.78,
30
+ 'clouds' => 1,
31
+ 'visibility' => 10000,
32
+ 'wind_speed' => 0.84,
33
+ 'wind_deg' => 358,
34
+ 'weather' => [
35
+ {
36
+ 'id' => 800,
37
+ 'main' => 'Clear',
38
+ 'description' => 'clear sky',
39
+ 'icon' => '01n'
40
+ }
41
+ ]
42
+ },
43
+ 'minutely' => [
44
+ { 'dt'=>1601879400, 'precipitation'=>0 }
45
+ ],
46
+ 'hourly' => [
47
+ {
48
+ 'dt' => 1601877600,
49
+ 'temp' => 290.77,
50
+ 'feels_like' => 292.82,
51
+ 'pressure' => 1016,
52
+ 'humidity' => 100,
53
+ 'dew_point' => 290.77,
54
+ 'clouds' => 1,
55
+ 'visibility' => 10000,
56
+ 'wind_speed' => 0.84,
57
+ 'wind_deg' => 358,
58
+ 'weather' => [
59
+ {
60
+ 'id' => 800,
61
+ 'main' => 'Clear',
62
+ 'description' => 'clear sky',
63
+ 'icon' => '01n'
64
+ }
65
+ ],
66
+ 'pop' => 0
67
+ }
68
+ ],
69
+ 'daily' => [
70
+ {
71
+ 'dt' => 1601838000,
72
+ 'sunrise' => 1601820377,
73
+ 'sunset' => 1601862390,
74
+ 'temp' => {
75
+ 'day' => 299.37,
76
+ 'min' => 290.77,
77
+ 'max' => 302.77,
78
+ 'night' => 290.77,
79
+ 'eve' => 301.85,
80
+ 'morn' => 293.12
81
+ },
82
+ 'feels_like' => {'day' => 297.62,
83
+ 'night' => 292.82,
84
+ 'eve' => 300.06, 'morn' => 291.88},
85
+ 'pressure' => 1016,
86
+ 'humidity' => 29,
87
+ 'dew_point' => 280.09,
88
+ 'wind_speed' => 1.43,
89
+ 'wind_deg' => 264,
90
+ 'weather' => [
91
+ {
92
+ 'id' => 800,
93
+ 'main' => 'Clear',
94
+ 'description' => 'clear sky', 'icon' => '01d'
95
+ }
96
+ ],
97
+ 'clouds' => 0,
98
+ 'pop' => 0,
99
+ 'uvi' => 5.78
100
+ }
101
+ ]
102
+ }
103
+ )
104
+ end
105
+
106
+ before do
107
+ allow(HTTParty).to receive(:get).
108
+ and_return(one_call_response)
109
+
110
+ Petrel.configure do |c|
111
+ c.api_key = 'mock_api_key'
112
+ end
113
+ end
114
+
115
+ it 'returns the current weather' do
116
+ expect(HTTParty).to receive(:get).
117
+ with("#{Petrel.url}/onecall", query: {
118
+ lat: 37,
119
+ lon: -122,
120
+ appid: Petrel.appid
121
+ }).
122
+ and_return(one_call_response)
123
+
124
+ Petrel.one_call(query)
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,80 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Petrel do
4
+ describe '.weather' do
5
+ let(:query) do
6
+ {
7
+ q: 'San Francisco'
8
+ }
9
+ end
10
+
11
+ let(:weather_response) do
12
+ double(
13
+ code: 200,
14
+ parsed_response: {
15
+ 'coord' => {
16
+ 'lon' => -122,
17
+ 'lat' => 37
18
+ },
19
+ 'weather' => [
20
+ {
21
+ 'id' => 801,
22
+ 'main' => 'Clouds',
23
+ 'description' => 'few clouds',
24
+ 'icon' => '02n'
25
+ }
26
+ ],
27
+ 'base' => 'stations',
28
+ 'main' => {
29
+ 'temp' => 288.88,
30
+ 'feels_like' => 286.78,
31
+ 'temp_min' => 286.15,
32
+ 'temp_max' => 290.37,
33
+ 'pressure' => 1014,
34
+ 'humidity' => 93
35
+ },
36
+ 'visibility' => 10000,
37
+ 'wind' => {
38
+ 'speed' => 5.1,
39
+ 'deg' => 300
40
+ },
41
+ 'clouds' => {
42
+ 'all' => 20
43
+ },
44
+ 'dt' => 1601805220,
45
+ 'sys' => {
46
+ 'type' => 1,
47
+ 'id' => 5817,
48
+ 'country' => 'US',
49
+ 'sunrise' => 1601820499,
50
+ 'sunset' => 1601862470
51
+ },
52
+ 'timezone' => -25200,
53
+ 'id' => 5391959,
54
+ 'name' => 'San Francisco',
55
+ 'cod' => 200
56
+ }
57
+ )
58
+ end
59
+
60
+ before do
61
+ allow(HTTParty).to receive(:get).
62
+ and_return(weather_response)
63
+
64
+ Petrel.configure do |c|
65
+ c.api_key = 'mock_api_key'
66
+ end
67
+ end
68
+
69
+ it 'returns the current weather' do
70
+ expect(HTTParty).to receive(:get).
71
+ with("#{Petrel.url}/weather", query: {
72
+ q: 'San Francisco',
73
+ appid: Petrel.appid
74
+ }).
75
+ and_return(weather_response)
76
+
77
+ Petrel.weather(query)
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,14 @@
1
+ require 'pry'
2
+ require 'petrel'
3
+
4
+ RSpec.configure do |config|
5
+ config.expect_with :rspec do |expectations|
6
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
7
+ end
8
+
9
+ config.mock_with :rspec do |mocks|
10
+ mocks.verify_partial_doubles = true
11
+ end
12
+
13
+ config.shared_context_metadata_behavior = :apply_to_host_groups
14
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: petrel
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - John Akers
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-10-06 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.18.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.18.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: awesome_print
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.8.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.8.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: 3.9.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.9.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.13.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.13.1
69
+ description: RubyGem wrapper for openweathermap.org
70
+ email:
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - ".gitignore"
76
+ - ".rspec"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - lib/petrel.rb
81
+ - lib/petrel/configuration.rb
82
+ - lib/petrel/forecast.rb
83
+ - lib/petrel/one_call.rb
84
+ - lib/petrel/version.rb
85
+ - lib/petrel/weather.rb
86
+ - petrel.gemspec
87
+ - spec/petrel/configuration_spec.rb
88
+ - spec/petrel/forecast_spec.rb
89
+ - spec/petrel/one_call_spec.rb
90
+ - spec/petrel/weather_spec.rb
91
+ - spec/spec_helper.rb
92
+ homepage: https://github.com/johnakers/petrel
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message: "*squawk* *squawk* Thanks for using Petrel - John"
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubygems_version: 3.0.3
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: RubyGem for OpenWeatherMap's current weather
115
+ test_files: []