owmo 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +23 -26
- data/lib/owmo.rb +7 -1
- data/lib/owmo/api.rb +15 -17
- data/lib/owmo/version.rb +1 -1
- data/lib/owmo/weather.rb +7 -47
- data/lib/owmo/weather/parameters.rb +48 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4f5a0571e3deeb308b950109d1e2ce5e260e4a6
|
4
|
+
data.tar.gz: aaad5a9604b18c99c0f73c694f83d3ae4ad6ad0f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01267656624f05395af9020be406e7d3bd2b7c09fad5f590a1194b5dfb16d373a0c5e849932945ecc5f89d5c51885fe6d037545b31c62d3684b228dd12534cb0
|
7
|
+
data.tar.gz: 1f35d90931232807f5635038734d117d40c5e39dccebd855b4b72481fbdd36454107186ab51e7bc7c562dcf8f72417259cf2942da055aca83eae0138be4bb3cb
|
data/README.md
CHANGED
@@ -24,7 +24,7 @@ Or install it yourself as:
|
|
24
24
|
|
25
25
|
You'll need and API key from [OpenWeatherMap.org](http://openweathermap.org/appid).
|
26
26
|
|
27
|
-
|
27
|
+
Complete examples can be found under owmo/examples.
|
28
28
|
|
29
29
|
----
|
30
30
|
### Quick Start
|
@@ -32,34 +32,32 @@ Compelete examples can be found under owmo/examples.
|
|
32
32
|
```ruby
|
33
33
|
require 'owmo'
|
34
34
|
api_key = "<api key here>"
|
35
|
-
weather = OWMO::
|
35
|
+
weather = OWMO::weather api_key
|
36
36
|
puts weather.get :current, city_name: "London,UK"
|
37
37
|
```
|
38
38
|
|
39
39
|
```ruby
|
40
40
|
require 'owmo'
|
41
41
|
api_key = "<api key here>"
|
42
|
-
OWMO::weather
|
43
|
-
puts weather.get :forecast, city_name: "London,UK"
|
44
|
-
end
|
42
|
+
OWMO::weather(api_key) { |weather| puts weather.get :current, city_name: "London,UK" }
|
45
43
|
```
|
46
44
|
----
|
47
45
|
### Weather Information
|
48
46
|
#### [Current weather data](http://openweathermap.org/current)
|
49
47
|
```ruby
|
50
|
-
|
48
|
+
weather.get :current, city_name: "London,UK"
|
51
49
|
```
|
52
50
|
[Full example](https://github.com/robb-randall/owmo/blob/master/examples/current.rb)
|
53
51
|
|
54
52
|
#### [5 day weather forecast](http://openweathermap.org/forecast5)
|
55
53
|
```ruby
|
56
|
-
|
54
|
+
weather.get :forecast5, city_name: "London,UK"
|
57
55
|
```
|
58
56
|
[Full example](https://github.com/robb-randall/owmo/blob/master/examples/forecast5.rb)
|
59
57
|
|
60
58
|
#### [16 day weather forecast](http://openweathermap.org/forecast16)
|
61
59
|
```ruby
|
62
|
-
|
60
|
+
weather.get :forecast16, city_name: "London,UK"
|
63
61
|
```
|
64
62
|
[Full example](https://github.com/robb-randall/owmo/blob/master/examples/forecast16.rb)
|
65
63
|
|
@@ -69,46 +67,46 @@ puts weather.get :forecast16, city_name: "London,UK"
|
|
69
67
|
#### Geocode (required)
|
70
68
|
```ruby
|
71
69
|
# Geocode by City ID
|
72
|
-
|
73
|
-
|
70
|
+
weather.get :current, city_id: 5328041
|
71
|
+
weather.get :current, id: 5328041
|
74
72
|
|
75
73
|
# Geocode by City Name
|
76
|
-
|
77
|
-
|
74
|
+
weather.get :current, city_name: "Beverly Hills"
|
75
|
+
weather.get :current, q: "Beverly Hills"
|
78
76
|
|
79
77
|
# Geocode by Zip Code
|
80
|
-
|
81
|
-
|
78
|
+
weather.get :current, zip: 90210
|
79
|
+
weather.get :current, zip_code: 90210
|
82
80
|
|
83
81
|
# Geocode by Coordinance
|
84
|
-
|
82
|
+
weather.get :current, lon: -118.41, lat: 34.09
|
85
83
|
```
|
86
84
|
[Full example](https://github.com/robb-randall/owmo/blob/master/examples/query_geocode.rb)
|
87
85
|
|
88
86
|
#### Mode
|
89
87
|
```ruby
|
90
88
|
# Response in JSON format (default)
|
91
|
-
|
92
|
-
|
89
|
+
weather.get :current, city_name: "London,UK"
|
90
|
+
weather.get :current, city_name: "London,UK", mode: :json
|
93
91
|
|
94
92
|
# Response in XML format
|
95
|
-
|
93
|
+
weather.get :current, city_name: "London,UK", mode: :xml
|
96
94
|
|
97
95
|
# Response in HTML format
|
98
|
-
|
96
|
+
weather.get :current, city_name: "London,UK", mode: :html
|
99
97
|
```
|
100
98
|
[Full example](https://github.com/robb-randall/owmo/blob/master/examples/query_mode.rb)
|
101
99
|
|
102
100
|
#### Units
|
103
101
|
```ruby
|
104
102
|
# Kelvin (default)
|
105
|
-
|
103
|
+
weather.get :current, city_name: "London,UK"
|
106
104
|
|
107
105
|
# Imperial
|
108
|
-
|
106
|
+
weather.get :current, city_name: "London,UK", units: :imperial
|
109
107
|
|
110
108
|
# Metric
|
111
|
-
|
109
|
+
weather.get :current, city_name: "London,UK", units: :metric
|
112
110
|
```
|
113
111
|
[Full example](https://github.com/robb-randall/owmo/blob/master/examples/query_units.rb)
|
114
112
|
|
@@ -121,12 +119,12 @@ query = {
|
|
121
119
|
lang: 'fr'
|
122
120
|
}
|
123
121
|
|
124
|
-
|
122
|
+
weather.get :current, query
|
125
123
|
```
|
126
124
|
[Full example](https://github.com/robb-randall/owmo/blob/master/examples/query_all.rb)
|
127
125
|
|
128
126
|
----
|
129
|
-
###
|
127
|
+
### Working example using Sinatra
|
130
128
|
|
131
129
|
```ruby
|
132
130
|
require 'owmo'
|
@@ -153,10 +151,9 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
153
151
|
|
154
152
|
## Contributing
|
155
153
|
|
156
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
154
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/robb-randall/owmo.
|
157
155
|
|
158
156
|
|
159
157
|
## License
|
160
158
|
|
161
159
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
162
|
-
|
data/lib/owmo.rb
CHANGED
@@ -25,7 +25,13 @@ Yield a weather object for querying weather data
|
|
25
25
|
=end
|
26
26
|
public
|
27
27
|
def self.weather(api_key, **params)
|
28
|
-
|
28
|
+
weather = Weather.new(api_key, params)
|
29
|
+
|
30
|
+
if block_given?
|
31
|
+
yield weather
|
32
|
+
else
|
33
|
+
return weather
|
34
|
+
end
|
29
35
|
end # weather
|
30
36
|
|
31
37
|
end # OWMO
|
data/lib/owmo/api.rb
CHANGED
@@ -10,34 +10,32 @@ Include some weather response info into Net::HTTPResponse
|
|
10
10
|
=end
|
11
11
|
Net::HTTPResponse.include CoreExtensions::Net::HTTPResponse::WeatherResponse
|
12
12
|
|
13
|
-
module OWMO
|
14
13
|
|
15
14
|
=begin rdoc
|
16
15
|
Net module Mixins
|
17
16
|
=end
|
18
|
-
|
19
|
-
|
17
|
+
module WeatherAPI
|
18
|
+
include ApiExceptions
|
20
19
|
|
21
20
|
=begin rdoc
|
22
21
|
Sends the GET request to OpenWeatherMap.org, and returns the response
|
23
22
|
=end
|
24
|
-
|
23
|
+
private
|
24
|
+
def get_weather(uri)
|
25
25
|
|
26
|
-
|
26
|
+
raise "Invalid URI: Expected URI, got #{uri.class}" unless uri.is_a? URI
|
27
27
|
|
28
|
-
|
29
|
-
|
28
|
+
# Send the request
|
29
|
+
request = Net::HTTP::Get.new(uri)
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
response = Net::HTTP.start(uri.hostname, uri.port) do |http|
|
32
|
+
http.request(request)
|
33
|
+
end # response
|
34
34
|
|
35
|
-
|
36
|
-
|
35
|
+
# Check the response
|
36
|
+
raise OWMO::API::WeatherResponseError.new(response) if response.has_error?
|
37
37
|
|
38
|
-
|
38
|
+
return response.weather
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
end # OWMO
|
40
|
+
end # get_weather
|
41
|
+
end # WeatherAPI
|
data/lib/owmo/version.rb
CHANGED
data/lib/owmo/weather.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
+
require 'owmo/api'
|
1
2
|
require 'owmo/weather/exceptions'
|
3
|
+
require 'owmo/weather/parameters'
|
2
4
|
|
3
5
|
require 'set'
|
4
6
|
require 'uri'
|
@@ -18,57 +20,15 @@ A weather class for retrieving current and forecasted weather conditions.
|
|
18
20
|
=end
|
19
21
|
class Weather
|
20
22
|
include WeatherExceptions
|
23
|
+
include WeatherParameters
|
24
|
+
include WeatherAPI
|
21
25
|
|
22
26
|
attr_reader :api_key, :Paths, :Geocodes
|
23
27
|
|
24
|
-
=begin rdoc
|
25
|
-
Access current or forecasted conditions by (required):
|
26
|
-
* +:current+ - {Current weather data}[http://openweathermap.org/current]
|
27
|
-
* +:forecast5+ - {5 day / 3 hour forecast}[http://openweathermap.org/forecast5]
|
28
|
-
* +:forecast16+ - {16 day / daily forecast}[http://openweathermap.org/forecast16]
|
29
|
-
=end
|
30
|
-
Paths = {
|
31
|
-
current: 'weather', # Current weather data
|
32
|
-
forecast5: 'forecast', # 5 day / 3 hour forecast
|
33
|
-
forecast16: 'forecast/daily' # 16 day / daily forecast
|
34
|
-
}
|
35
|
-
|
36
|
-
=begin rdoc
|
37
|
-
{Geocode options (required):}[http://openweathermap.org/current#one]
|
38
|
-
* +q:+ or +city_name:+ - By city name
|
39
|
-
* +id:+ or +city_id:+ - By city ID
|
40
|
-
* +zip:+ or +zip_code:+ - By zip code
|
41
|
-
* +lat:+, +lon:+ or +latitude:+, +longitude:+ - By geographic coordinates
|
42
|
-
=end
|
43
|
-
Geocodes = {
|
44
|
-
"City Name" => {
|
45
|
-
query: :q,
|
46
|
-
options: [:q, :city_name]
|
47
|
-
},
|
48
|
-
"City ID" => {
|
49
|
-
query: :id,
|
50
|
-
options: [:id, :city_id]
|
51
|
-
},
|
52
|
-
"Zip Code" => {
|
53
|
-
query: :zip,
|
54
|
-
options: [:zip, :zip_code]
|
55
|
-
},
|
56
|
-
"Coordinance" => {
|
57
|
-
query: [:lat, :lon],
|
58
|
-
options: [[:lat, :lon], [:lattitude, :longitude]]
|
59
|
-
},
|
60
|
-
"Cities Within a Rectangle Zone" => {
|
61
|
-
query: :bbox,
|
62
|
-
options: [:bbox]
|
63
|
-
},
|
64
|
-
"Cities Within a Circle" => {
|
65
|
-
query: [:lat, :lon, :cnt],
|
66
|
-
options: [[:lat, :lon, :cnt],[:lattitude, :longitude, :cnt]]
|
67
|
-
}
|
68
|
-
}
|
69
|
-
|
70
28
|
def initialize(api_key, **kwargs) #:notnew:
|
71
29
|
@api_key = api_key
|
30
|
+
|
31
|
+
yield self if block_given?
|
72
32
|
end # initialize
|
73
33
|
|
74
34
|
=begin rdoc
|
@@ -94,7 +54,7 @@ A weather class for retrieving current and forecasted weather conditions.
|
|
94
54
|
uri = URI "#{OWMO::URL}/#{Paths[path]}?#{URI.encode_www_form(query)}"
|
95
55
|
|
96
56
|
# Get the weather data
|
97
|
-
|
57
|
+
get_weather(uri)
|
98
58
|
|
99
59
|
end # get
|
100
60
|
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module WeatherParameters
|
2
|
+
=begin rdoc
|
3
|
+
Access current or forecasted conditions by (required):
|
4
|
+
* +:current+ - {Current weather data}[http://openweathermap.org/current]
|
5
|
+
* +:forecast5+ - {5 day / 3 hour forecast}[http://openweathermap.org/forecast5]
|
6
|
+
* +:forecast16+ - {16 day / daily forecast}[http://openweathermap.org/forecast16]
|
7
|
+
=end
|
8
|
+
Paths = {
|
9
|
+
current: 'weather', # Current weather data
|
10
|
+
forecast5: 'forecast', # 5 day / 3 hour forecast
|
11
|
+
forecast16: 'forecast/daily' # 16 day / daily forecast
|
12
|
+
}
|
13
|
+
|
14
|
+
=begin rdoc
|
15
|
+
{Geocode options (required):}[http://openweathermap.org/current#one]
|
16
|
+
* +q:+ or +city_name:+ - By city name
|
17
|
+
* +id:+ or +city_id:+ - By city ID
|
18
|
+
* +zip:+ or +zip_code:+ - By zip code
|
19
|
+
* +lat:+, +lon:+ or +latitude:+, +longitude:+ - By geographic coordinates
|
20
|
+
=end
|
21
|
+
Geocodes = {
|
22
|
+
"City Name" => {
|
23
|
+
query: :q,
|
24
|
+
options: [:q, :city_name]
|
25
|
+
},
|
26
|
+
"City ID" => {
|
27
|
+
query: :id,
|
28
|
+
options: [:id, :city_id]
|
29
|
+
},
|
30
|
+
"Zip Code" => {
|
31
|
+
query: :zip,
|
32
|
+
options: [:zip, :zip_code]
|
33
|
+
},
|
34
|
+
"Coordinance" => {
|
35
|
+
query: [:lat, :lon],
|
36
|
+
options: [[:lat, :lon], [:lattitude, :longitude]]
|
37
|
+
},
|
38
|
+
"Cities Within a Rectangle Zone" => {
|
39
|
+
query: :bbox,
|
40
|
+
options: [:bbox]
|
41
|
+
},
|
42
|
+
"Cities Within a Circle" => {
|
43
|
+
query: [:lat, :lon, :cnt],
|
44
|
+
options: [[:lat, :lon, :cnt],[:lattitude, :longitude, :cnt]]
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
end # WeatherParameters
|
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.1.0
|
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-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- lib/owmo/version.rb
|
86
86
|
- lib/owmo/weather.rb
|
87
87
|
- lib/owmo/weather/exceptions.rb
|
88
|
+
- lib/owmo/weather/parameters.rb
|
88
89
|
- owmo.gemspec
|
89
90
|
homepage: https://github.com/robb-randall/owmo
|
90
91
|
licenses:
|