owmo 1.1.0 → 1.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c4f5a0571e3deeb308b950109d1e2ce5e260e4a6
4
- data.tar.gz: aaad5a9604b18c99c0f73c694f83d3ae4ad6ad0f
3
+ metadata.gz: a412e9d668b31fda079d98755fc42eda2ecb0914
4
+ data.tar.gz: 74ae3e5e9d8069f5c8466f28ba47a271aa72032f
5
5
  SHA512:
6
- metadata.gz: 01267656624f05395af9020be406e7d3bd2b7c09fad5f590a1194b5dfb16d373a0c5e849932945ecc5f89d5c51885fe6d037545b31c62d3684b228dd12534cb0
7
- data.tar.gz: 1f35d90931232807f5635038734d117d40c5e39dccebd855b4b72481fbdd36454107186ab51e7bc7c562dcf8f72417259cf2942da055aca83eae0138be4bb3cb
6
+ metadata.gz: a06e37fd046e4fa840ba9b2e04e8a176ceb8db775575a3c8ad3b673321f103bf161d766202f249b60a4ad1def192a80c7073b618caa97e3d2ae9b98d836d6484
7
+ data.tar.gz: 7bc73c2851eb22dbfc95e7a6f2cb701774dbad74e04972fcc96b7c0bcabb2c060522c07319c68ed6f1be0ae53645aba4f19d03c6213523b25183a4df1b000978
data/README.md CHANGED
@@ -29,6 +29,12 @@ Complete examples can be found under owmo/examples.
29
29
  ----
30
30
  ### Quick Start
31
31
 
32
+ ```ruby
33
+ require 'owmo'
34
+ api_key = "<api key here>"
35
+ puts OWMO::weather(api_key).get :current, city_name: "London,UK"
36
+ ```
37
+
32
38
  ```ruby
33
39
  require 'owmo'
34
40
  api_key = "<api key here>"
@@ -45,19 +51,24 @@ OWMO::weather(api_key) { |weather| puts weather.get :current, city_name: "London
45
51
  ### Weather Information
46
52
  #### [Current weather data](http://openweathermap.org/current)
47
53
  ```ruby
48
- weather.get :current, city_name: "London,UK"
54
+ OWMO::weather(api_key).get :current, city_name: "London,UK"
49
55
  ```
50
56
  [Full example](https://github.com/robb-randall/owmo/blob/master/examples/current.rb)
51
57
 
58
+ ### [Current weather data for multiple cities](http://openweathermap.org/current#severalid)
59
+ ```ruby
60
+ OWMO::weather(api_key).get :group, city_id: [4850751,4887398,2643743,4164138,5368361].join(",")
61
+ ```
62
+
52
63
  #### [5 day weather forecast](http://openweathermap.org/forecast5)
53
64
  ```ruby
54
- weather.get :forecast5, city_name: "London,UK"
65
+ OWMO::weather(api_key).get :forecast5, city_name: "London,UK"
55
66
  ```
56
67
  [Full example](https://github.com/robb-randall/owmo/blob/master/examples/forecast5.rb)
57
68
 
58
69
  #### [16 day weather forecast](http://openweathermap.org/forecast16)
59
70
  ```ruby
60
- weather.get :forecast16, city_name: "London,UK"
71
+ OWMO::weather(api_key).get :forecast16, city_name: "London,UK"
61
72
  ```
62
73
  [Full example](https://github.com/robb-randall/owmo/blob/master/examples/forecast16.rb)
63
74
 
@@ -67,46 +78,46 @@ weather.get :forecast16, city_name: "London,UK"
67
78
  #### Geocode (required)
68
79
  ```ruby
69
80
  # Geocode by City ID
70
- weather.get :current, city_id: 5328041
71
- weather.get :current, id: 5328041
81
+ OWMO::weather(api_key).get :current, city_id: 5328041
82
+ OWMO::weather(api_key).get :current, id: 5328041
72
83
 
73
84
  # Geocode by City Name
74
- weather.get :current, city_name: "Beverly Hills"
75
- weather.get :current, q: "Beverly Hills"
85
+ OWMO::weather(api_key).get :current, city_name: "Beverly Hills"
86
+ OWMO::weather(api_key).get :current, q: "Beverly Hills"
76
87
 
77
88
  # Geocode by Zip Code
78
- weather.get :current, zip: 90210
79
- weather.get :current, zip_code: 90210
89
+ OWMO::weather(api_key).get :current, zip: 90210
90
+ OWMO::weather(api_key).get :current, zip_code: 90210
80
91
 
81
92
  # Geocode by Coordinance
82
- weather.get :current, lon: -118.41, lat: 34.09
93
+ OWMO::weather(api_key).get :current, lon: -118.41, lat: 34.09
83
94
  ```
84
95
  [Full example](https://github.com/robb-randall/owmo/blob/master/examples/query_geocode.rb)
85
96
 
86
97
  #### Mode
87
98
  ```ruby
88
99
  # Response in JSON format (default)
89
- weather.get :current, city_name: "London,UK"
90
- weather.get :current, city_name: "London,UK", mode: :json
100
+ OWMO::weather(api_key).get :current, city_name: "London,UK"
101
+ OWMO::weather(api_key).get :current, city_name: "London,UK", mode: :json
91
102
 
92
103
  # Response in XML format
93
- weather.get :current, city_name: "London,UK", mode: :xml
104
+ OWMO::weather(api_key).get :current, city_name: "London,UK", mode: :xml
94
105
 
95
106
  # Response in HTML format
96
- weather.get :current, city_name: "London,UK", mode: :html
107
+ OWMO::weather(api_key).get :current, city_name: "London,UK", mode: :html
97
108
  ```
98
109
  [Full example](https://github.com/robb-randall/owmo/blob/master/examples/query_mode.rb)
99
110
 
100
111
  #### Units
101
112
  ```ruby
102
113
  # Kelvin (default)
103
- weather.get :current, city_name: "London,UK"
114
+ OWMO::weather(api_key).get :current, city_name: "London,UK"
104
115
 
105
116
  # Imperial
106
- weather.get :current, city_name: "London,UK", units: :imperial
117
+ OWMO::weather(api_key).get :current, city_name: "London,UK", units: :imperial
107
118
 
108
119
  # Metric
109
- weather.get :current, city_name: "London,UK", units: :metric
120
+ OWMO::weather(api_key).get :current, city_name: "London,UK", units: :metric
110
121
  ```
111
122
  [Full example](https://github.com/robb-randall/owmo/blob/master/examples/query_units.rb)
112
123
 
@@ -119,7 +130,7 @@ query = {
119
130
  lang: 'fr'
120
131
  }
121
132
 
122
- weather.get :current, query
133
+ OWMO::weather(api_key).get :current, query
123
134
  ```
124
135
  [Full example](https://github.com/robb-randall/owmo/blob/master/examples/query_all.rb)
125
136
 
@@ -25,7 +25,7 @@ Returns the response code
25
25
  public
26
26
  def weather_code
27
27
  parse_weather
28
- return @weather['cod'].to_i if @weather.is_a? Hash
28
+ return (@weather['cod'] || "200").to_i if @weather.is_a? Hash
29
29
  200
30
30
  end # weather_error
31
31
 
data/lib/owmo/api.rb CHANGED
@@ -33,7 +33,7 @@ Sends the GET request to OpenWeatherMap.org, and returns the response
33
33
  end # response
34
34
 
35
35
  # Check the response
36
- raise OWMO::API::WeatherResponseError.new(response) if response.has_error?
36
+ raise WeatherResponseError.new(response) if response.has_error?
37
37
 
38
38
  return response.weather
39
39
 
data/lib/owmo/version.rb CHANGED
@@ -3,6 +3,6 @@ module OWMO
3
3
  =begin rdoc
4
4
  Gem Version
5
5
  =end
6
- VERSION = "1.1.0"
6
+ VERSION = "1.2.0"
7
7
 
8
8
  end # OWMO
@@ -1,4 +1,6 @@
1
1
  module WeatherParameters
2
+ attr_reader :Paths, :Geocodes
3
+
2
4
  =begin rdoc
3
5
  Access current or forecasted conditions by (required):
4
6
  * +:current+ - {Current weather data}[http://openweathermap.org/current]
@@ -6,6 +8,7 @@ Access current or forecasted conditions by (required):
6
8
  * +:forecast16+ - {16 day / daily forecast}[http://openweathermap.org/forecast16]
7
9
  =end
8
10
  Paths = {
11
+ group: 'group', # Current weather w/multiple IDs
9
12
  current: 'weather', # Current weather data
10
13
  forecast5: 'forecast', # 5 day / 3 hour forecast
11
14
  forecast16: 'forecast/daily' # 16 day / daily forecast
data/lib/owmo/weather.rb CHANGED
@@ -19,11 +19,11 @@ A weather class for retrieving current and forecasted weather conditions.
19
19
 
20
20
  =end
21
21
  class Weather
22
+ include WeatherAPI
22
23
  include WeatherExceptions
23
24
  include WeatherParameters
24
- include WeatherAPI
25
25
 
26
- attr_reader :api_key, :Paths, :Geocodes
26
+ attr_reader :api_key
27
27
 
28
28
  def initialize(api_key, **kwargs) #:notnew:
29
29
  @api_key = api_key
@@ -51,7 +51,7 @@ A weather class for retrieving current and forecasted weather conditions.
51
51
 
52
52
  # Create the uri
53
53
  raise InvalidPathSpecified.new(path) if Paths[path].nil?
54
- uri = URI "#{OWMO::URL}/#{Paths[path]}?#{URI.encode_www_form(query)}"
54
+ uri = URI "#{OWMO::URL}/#{Paths[path]}?#{URI.encode_www_form(query).gsub('%2C', ',')}"
55
55
 
56
56
  # Get the weather data
57
57
  get_weather(uri)
@@ -63,7 +63,7 @@ Ensure appropriate query options are applied to the final URI
63
63
  =end
64
64
  def check_geocodes(**query)
65
65
 
66
- # May never be called since query is required
66
+ # May never be called since query is requiredcity_name
67
67
  raise MissingGeocodes if query.size == 0
68
68
 
69
69
  Geocodes.each do |name, geocodes|
data/lib/owmo.rb CHANGED
@@ -31,7 +31,7 @@ Yield a weather object for querying weather data
31
31
  yield weather
32
32
  else
33
33
  return weather
34
- end
34
+ end # if
35
35
  end # weather
36
36
 
37
37
  end # OWMO
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: owmo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robb