owmo 1.0.0 → 1.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 +4 -4
- data/.gitignore +1 -0
- data/README.md +32 -4
- data/examples/sinatra_example.rb +10 -0
- data/lib/core_extensions/net/http_response/weather_response.rb +8 -0
- data/lib/owmo.rb +1 -2
- data/lib/owmo/api.rb +5 -11
- data/lib/owmo/api/exceptions.rb +14 -0
- data/lib/owmo/version.rb +1 -1
- data/lib/owmo/weather.rb +3 -17
- data/lib/owmo/weather/exceptions.rb +20 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ce70a84df088217ce4682019a4815dcab4b1db1
|
4
|
+
data.tar.gz: bde9b9055267c9c7d7a623e87ea579c27fbca1d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d8853935c1daa9c82f76c8b5fd9e4971db71d09f714b489207af6bed0e0ab99c96e1c5aabad7b5a370df8b50179fa4ec060cf70baefa367b56ae728604e0c51
|
7
|
+
data.tar.gz: df115d83e3e1307a5b9aeadc2b026480c5f7bb91d5337743e04d739c49e45c68f086f3bb25473dec0e2e5f2b8601764860e5dfd571bd0de905793c5452bc50af
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -22,7 +22,7 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
You'll need and API key from OpenWeatherMap.org
|
25
|
+
You'll need and API key from [OpenWeatherMap.org](http://openweathermap.org/appid).
|
26
26
|
|
27
27
|
Compelete examples can be found under owmo/examples.
|
28
28
|
|
@@ -45,18 +45,23 @@ end
|
|
45
45
|
```
|
46
46
|
----
|
47
47
|
### Weather Information
|
48
|
-
#### Current weather data
|
48
|
+
#### [Current weather data](http://openweathermap.org/current)
|
49
49
|
```ruby
|
50
50
|
puts weather.get :current, city_name: "London,UK"
|
51
51
|
```
|
52
|
-
|
52
|
+
[Full example](https://github.com/robb-randall/owmo/blob/master/examples/current.rb)
|
53
|
+
|
54
|
+
#### [5 day weather forecast](http://openweathermap.org/forecast5)
|
53
55
|
```ruby
|
54
56
|
puts weather.get :forecast5, city_name: "London,UK"
|
55
57
|
```
|
56
|
-
|
58
|
+
[Full example](https://github.com/robb-randall/owmo/blob/master/examples/forecast5.rb)
|
59
|
+
|
60
|
+
#### [16 day weather forecast](http://openweathermap.org/forecast16)
|
57
61
|
```ruby
|
58
62
|
puts weather.get :forecast16, city_name: "London,UK"
|
59
63
|
```
|
64
|
+
[Full example](https://github.com/robb-randall/owmo/blob/master/examples/forecast16.rb)
|
60
65
|
|
61
66
|
----
|
62
67
|
### Query parameters
|
@@ -78,6 +83,7 @@ puts weather.get :current, zip_code: 90210
|
|
78
83
|
# Geocode by Coordinance
|
79
84
|
puts weather.get :current, lon: -118.41, lat: 34.09
|
80
85
|
```
|
86
|
+
[Full example](https://github.com/robb-randall/owmo/blob/master/examples/query_geocode.rb)
|
81
87
|
|
82
88
|
#### Mode
|
83
89
|
```ruby
|
@@ -91,6 +97,7 @@ puts weather.get :current, city_name: "London,UK", mode: :xml
|
|
91
97
|
# Response in HTML format
|
92
98
|
puts weather.get :current, city_name: "London,UK", mode: :html
|
93
99
|
```
|
100
|
+
[Full example](https://github.com/robb-randall/owmo/blob/master/examples/query_mode.rb)
|
94
101
|
|
95
102
|
#### Units
|
96
103
|
```ruby
|
@@ -103,6 +110,7 @@ puts weather.get :current, city_name: "London,UK", units: :imperial
|
|
103
110
|
# Metric
|
104
111
|
puts weather.get :current, city_name: "London,UK", units: :metric
|
105
112
|
```
|
113
|
+
[Full example](https://github.com/robb-randall/owmo/blob/master/examples/query_units.rb)
|
106
114
|
|
107
115
|
#### All
|
108
116
|
```ruby
|
@@ -115,6 +123,26 @@ query = {
|
|
115
123
|
|
116
124
|
puts weather.get :current, query
|
117
125
|
```
|
126
|
+
[Full example](https://github.com/robb-randall/owmo/blob/master/examples/query_all.rb)
|
127
|
+
|
128
|
+
----
|
129
|
+
### Wroking example using Sinatra
|
130
|
+
|
131
|
+
```ruby
|
132
|
+
require 'owmo'
|
133
|
+
require 'sinatra' # Need to install, not included in gemspec
|
134
|
+
require 'uri'
|
135
|
+
|
136
|
+
get '/current/:name' do
|
137
|
+
api_key = '<API Key>'
|
138
|
+
weather = OWMO::Weather.new api_key
|
139
|
+
weather.get :current, city_name: params[:name], mode: :html
|
140
|
+
end
|
141
|
+
```
|
142
|
+
|
143
|
+
Then navigate to: http://localhost:4567/current/London,UK
|
144
|
+
|
145
|
+
[Full example](https://github.com/robb-randall/owmo/blob/master/examples/sinatra_example.rb)
|
118
146
|
|
119
147
|
----
|
120
148
|
## Development
|
@@ -39,6 +39,14 @@ Returns the response message
|
|
39
39
|
""
|
40
40
|
end # weather_message
|
41
41
|
|
42
|
+
=begin rdoc
|
43
|
+
Returns boolean if the response contains an error or not.
|
44
|
+
=end
|
45
|
+
public
|
46
|
+
def has_error?
|
47
|
+
weather_code != 200
|
48
|
+
end # has_error?
|
49
|
+
|
42
50
|
=begin rdoc
|
43
51
|
Attempts to parse the body to JSON. This is so we don't have to continually
|
44
52
|
parse the raw JSON.
|
data/lib/owmo.rb
CHANGED
data/lib/owmo/api.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'core_extensions/net/http_response/weather_response'
|
2
|
+
require 'owmo/api/exceptions'
|
3
|
+
|
2
4
|
require 'net/http'
|
3
5
|
require 'uri'
|
4
6
|
|
@@ -9,20 +11,12 @@ Include some weather response info into Net::HTTPResponse
|
|
9
11
|
Net::HTTPResponse.include CoreExtensions::Net::HTTPResponse::WeatherResponse
|
10
12
|
|
11
13
|
module OWMO
|
14
|
+
|
12
15
|
=begin rdoc
|
13
16
|
Net module Mixins
|
14
17
|
=end
|
15
18
|
module API
|
16
|
-
|
17
|
-
=begin rdoc
|
18
|
-
Weather response error to handle errors received from OpenWeatherMap.orgs API
|
19
|
-
=end
|
20
|
-
class WeatherResponseError < StandardError
|
21
|
-
def initialize(response)
|
22
|
-
@response = response
|
23
|
-
super("ERROR #{@response.weather_code}: #{@response.weather_message}")
|
24
|
-
end # initialize
|
25
|
-
end # WeatherResponseError
|
19
|
+
include ApiExceptions
|
26
20
|
|
27
21
|
=begin rdoc
|
28
22
|
Sends the GET request to OpenWeatherMap.org, and returns the response
|
@@ -39,7 +33,7 @@ Sends the GET request to OpenWeatherMap.org, and returns the response
|
|
39
33
|
end # response
|
40
34
|
|
41
35
|
# Check the response
|
42
|
-
raise OWMO::API::WeatherResponseError.new(response)
|
36
|
+
raise OWMO::API::WeatherResponseError.new(response) if response.has_error?
|
43
37
|
|
44
38
|
return response.weather
|
45
39
|
|
@@ -0,0 +1,14 @@
|
|
1
|
+
|
2
|
+
module ApiExceptions
|
3
|
+
|
4
|
+
=begin rdoc
|
5
|
+
Weather response error to handle errors received from OpenWeatherMap.orgs API
|
6
|
+
=end
|
7
|
+
class WeatherResponseError < StandardError
|
8
|
+
def initialize(response)
|
9
|
+
@response = response
|
10
|
+
super("ERROR #{@response.weather_code}: #{@response.weather_message}")
|
11
|
+
end # initialize
|
12
|
+
end # WeatherResponseError
|
13
|
+
|
14
|
+
end # ApiExceptions
|
data/lib/owmo/version.rb
CHANGED
data/lib/owmo/weather.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'owmo/weather/exceptions'
|
2
|
+
|
1
3
|
require 'set'
|
2
4
|
require 'uri'
|
3
5
|
|
@@ -15,6 +17,7 @@ A weather class for retrieving current and forecasted weather conditions.
|
|
15
17
|
|
16
18
|
=end
|
17
19
|
class Weather
|
20
|
+
include WeatherExceptions
|
18
21
|
|
19
22
|
attr_reader :api_key, :Paths, :Geocodes
|
20
23
|
|
@@ -64,23 +67,6 @@ Access current or forecasted conditions by (required):
|
|
64
67
|
}
|
65
68
|
}
|
66
69
|
|
67
|
-
=begin rdoc
|
68
|
-
Invalid path specified
|
69
|
-
=end
|
70
|
-
class InvalidPathSpecified < StandardError
|
71
|
-
def initialize(path=nil)
|
72
|
-
@path = path
|
73
|
-
super("Invalid path specified: Got: '#{@path}', expected one of: #{Paths.keys}")
|
74
|
-
end # initialize
|
75
|
-
end # NoGeocodeSpecified
|
76
|
-
|
77
|
-
=begin rdoc
|
78
|
-
Missing Geocode from query
|
79
|
-
=end
|
80
|
-
class MissingGeocodes < StandardError
|
81
|
-
end # MissingGeocodes
|
82
|
-
|
83
|
-
|
84
70
|
def initialize(api_key, **kwargs) #:notnew:
|
85
71
|
@api_key = api_key
|
86
72
|
end # initialize
|
@@ -0,0 +1,20 @@
|
|
1
|
+
|
2
|
+
module WeatherExceptions
|
3
|
+
|
4
|
+
=begin rdoc
|
5
|
+
Invalid path specified
|
6
|
+
=end
|
7
|
+
class InvalidPathSpecified < StandardError
|
8
|
+
def initialize(path=nil)
|
9
|
+
@path = path
|
10
|
+
super("Invalid path specified: Got: '#{@path}', expected one of: #{Paths.keys}")
|
11
|
+
end # initialize
|
12
|
+
end # NoGeocodeSpecified
|
13
|
+
|
14
|
+
=begin rdoc
|
15
|
+
Missing Geocode from query
|
16
|
+
=end
|
17
|
+
class MissingGeocodes < StandardError
|
18
|
+
end # MissingGeocodes
|
19
|
+
|
20
|
+
end # WeatherExceptions
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: owmo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robb
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -76,12 +76,15 @@ files:
|
|
76
76
|
- examples/query_geocode.rb
|
77
77
|
- examples/query_mode.rb
|
78
78
|
- examples/query_units.rb
|
79
|
+
- examples/sinatra_example.rb
|
79
80
|
- lib/core_extensions/core_extensions.rb
|
80
81
|
- lib/core_extensions/net/http_response/weather_response.rb
|
81
82
|
- lib/owmo.rb
|
82
83
|
- lib/owmo/api.rb
|
84
|
+
- lib/owmo/api/exceptions.rb
|
83
85
|
- lib/owmo/version.rb
|
84
86
|
- lib/owmo/weather.rb
|
87
|
+
- lib/owmo/weather/exceptions.rb
|
85
88
|
- owmo.gemspec
|
86
89
|
homepage: https://github.com/robb-randall/owmo
|
87
90
|
licenses:
|