owmo 0.2.0 → 1.0.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: e14ca9d0e7400dc1e9acd4d318c1f223837eae89
4
- data.tar.gz: ab5302d6ef868d2723d10a8d24d4f9a1e0b4d8be
3
+ metadata.gz: 76cf3aad7eed6385b91969ab9e129367ce8e7b40
4
+ data.tar.gz: 4604435004a67f5e01bba1c0c789b1823351bafc
5
5
  SHA512:
6
- metadata.gz: 2f82d1d1e265163514a0b24d0f1dd5e8e318b3905375d3eef8399df26eef91c1101b72f8836065b822d05360978414586d80e886f00cb510f5e60f54baef7b5b
7
- data.tar.gz: a798ccfdc3f3482c244c5e8a474ba26d6a653831d85580d6ef652f7476c2a30353af2a6324b4594cbd3417c789fe55a444ff1bbbc308a0202828a4fade0651c2
6
+ metadata.gz: 6a5c8504dde37e3b907e57cfa71cec9f3e8a9c1008ba38421d90be8b4131d67de3bf478af4f79650a3d69d18079ae3355e584a584b7973892cfad72ed1980e17
7
+ data.tar.gz: 67ab4aa60a944b7141ba01e85b47454600c72042ac4fa4536501182fd252c36eaebeabe6b24298c46746b3793ce7c967f84a1047fd709b50d8a80c295045f599
data/Gemfile CHANGED
@@ -1,4 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in owmo.gemspec
4
3
  gemspec
data/README.md CHANGED
@@ -32,55 +32,91 @@ 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::Weather.new api_key: api_key
36
- puts weather.get :current, zip: 52402
35
+ weather = OWMO::Weather.new api_key
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 api_key: api_key do |weather|
43
- puts weather.get :forecast, zip: 52402
42
+ OWMO::weather api_key do |weather|
43
+ puts weather.get :forecast, city_name: "London,UK"
44
44
  end
45
45
  ```
46
46
  ----
47
+ ### Weather Information
48
+ #### Current weather data (http://openweathermap.org/current)
49
+ ```ruby
50
+ puts weather.get :current, city_name: "London,UK"
51
+ ```
52
+ #### 5 day weather forecast (http://openweathermap.org/forecast5)
53
+ ```ruby
54
+ puts weather.get :forecast5, city_name: "London,UK"
55
+ ```
56
+ #### 16 day weather forecast (http://openweathermap.org/forecast16)
57
+ ```ruby
58
+ puts weather.get :forecast16, city_name: "London,UK"
59
+ ```
60
+
61
+ ----
62
+ ### Query parameters
63
+
64
+ #### Geocode (required)
65
+ ```ruby
66
+ # Geocode by City ID
67
+ puts weather.get :current, city_id: 5328041
68
+ puts weather.get :current, id: 5328041
69
+
70
+ # Geocode by City Name
71
+ puts weather.get :current, city_name: "Beverly Hills"
72
+ puts weather.get :current, q: "Beverly Hills"
73
+
74
+ # Geocode by Zip Code
75
+ puts weather.get :current, zip: 90210
76
+ puts weather.get :current, zip_code: 90210
77
+
78
+ # Geocode by Coordinance
79
+ puts weather.get :current, lon: -118.41, lat: 34.09
80
+ ```
47
81
 
48
- ### Current weather data (http://openweathermap.org/current)
82
+ #### Mode
49
83
  ```ruby
50
- params = {
51
- city_name: "London,uk", # [city_name, city_id, zip, lat/lon]
52
- mode: 'json', # [json, xml, html] Not required, but an option
53
- units: 'imperial', # [imperial, metric] Not required, but an option
54
- lang: 'en_US' # Not required, but an option
55
- }
84
+ # Response in JSON format (default)
85
+ puts weather.get :current, city_name: "London,UK"
86
+ puts weather.get :current, city_name: "London,UK", mode: :json
56
87
 
57
- puts weather.get :current, params
88
+ # Response in XML format
89
+ puts weather.get :current, city_name: "London,UK", mode: :xml
58
90
 
91
+ # Response in HTML format
92
+ puts weather.get :current, city_name: "London,UK", mode: :html
59
93
  ```
60
- ### 5 day weather forecast (http://openweathermap.org/forecast5)
94
+
95
+ #### Units
61
96
  ```ruby
62
- params = {
63
- zip: "90210", # [city_name, city_id, zip, lat/lon]
64
- mode: 'json', # [json, xml, html] Not required, but an option
65
- units: 'imperial', # [imperial, metric] Not required, but an option
66
- lang: 'en_US' # Not required, but an option
67
- }
68
-
69
- puts weather.get :forecast, params
97
+ # Kelvin (default)
98
+ puts weather.get :current, city_name: "London,UK"
99
+
100
+ # Imperial
101
+ puts weather.get :current, city_name: "London,UK", units: :imperial
102
+
103
+ # Metric
104
+ puts weather.get :current, city_name: "London,UK", units: :metric
70
105
  ```
71
106
 
72
- ### 16 day weather forecast (http://openweathermap.org/forecast16)
107
+ #### All
73
108
  ```ruby
74
- params = {
75
- lat: "40.7128", lon: "74.0059", # [city_name, city_id, zip, lat/lon]
76
- mode: 'json', # [json, xml, html] Not required, but an option
77
- units: 'imperial', # [imperial, metric] Not required, but an option
78
- lang: 'en_US' # Not required, but an option
79
- }
80
-
81
- puts weather.get :extended, params
109
+ query = {
110
+ city_name: "London,UK",
111
+ mode: 'json',
112
+ units: 'imperial',
113
+ lang: 'fr'
114
+ }
115
+
116
+ puts weather.get :current, query
82
117
  ```
83
118
 
119
+ ----
84
120
  ## Development
85
121
 
86
122
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -0,0 +1,13 @@
1
+ require 'owmo'
2
+
3
+ =begin rdoc
4
+ An example on how to get current conditions and use the different parameters.
5
+ =end
6
+ api_key = ""
7
+
8
+ weather = OWMO::Weather.new api_key
9
+
10
+ # http://openweathermap.org/current#data
11
+ current = weather.get :current, city_name: "London,UK"
12
+
13
+ puts current
@@ -0,0 +1,14 @@
1
+ require 'owmo'
2
+
3
+
4
+ =begin rdoc
5
+ An example on how to get the weather forcast and use the different parameters.
6
+ =end
7
+ api_key = ""
8
+
9
+ weather = OWMO::Weather.new api_key
10
+
11
+ # http://openweathermap.org/forecast16
12
+ forecast16 = weather.get :forecast16, city_name: "London,UK"
13
+
14
+ puts forecast16
@@ -0,0 +1,14 @@
1
+ require 'owmo'
2
+
3
+
4
+ =begin rdoc
5
+ An example on how to get the extended forcast and use the different parameters.
6
+ =end
7
+ api_key = ""
8
+
9
+ weather = OWMO::Weather.new api_key
10
+
11
+ # http://openweathermap.org/forecast5
12
+ forecast5 = weather.get :forecast5, city_name: "London,UK"
13
+
14
+ puts forecast5
@@ -0,0 +1,16 @@
1
+ require 'owmo'
2
+
3
+ api_key = ""
4
+
5
+ weather = OWMO::Weather.new api_key
6
+
7
+ query = {
8
+ city_name: "London,UK", # Geolocation, required
9
+ mode: 'json', # Return data [json (defaul), xml, html]
10
+ units: 'imperial', # [imperial, metric, or blank (Default, Kelvin)]
11
+ lang: 'fr' # Language support
12
+ }
13
+
14
+ current = weather.get :current, query
15
+
16
+ puts current
@@ -0,0 +1,20 @@
1
+ require 'owmo'
2
+
3
+ api_key = ""
4
+
5
+ weather = OWMO::Weather.new api_key
6
+
7
+ # Geocode by City ID
8
+ puts weather.get :current, city_id: 5328041
9
+ puts weather.get :current, id: 5328041
10
+
11
+ # Geocode by City Name
12
+ puts weather.get :current, city_name: "Beverly Hills"
13
+ puts weather.get :current, q: "Beverly Hills"
14
+
15
+ # Geocode by Zip Code
16
+ puts weather.get :current, zip: 90210
17
+ puts weather.get :current, zip_code: 90210
18
+
19
+ # Geocode by Coordinance
20
+ puts weather.get :current, lon: -118.41, lat: 34.09
@@ -0,0 +1,15 @@
1
+ require 'owmo'
2
+
3
+ api_key = ""
4
+
5
+ weather = OWMO::Weather.new api_key
6
+
7
+ # Response in JSON format
8
+ puts weather.get :current, city_name: "London,UK"
9
+ puts weather.get :current, city_name: "London,UK", mode: :json
10
+
11
+ # Response in XML format
12
+ puts weather.get :current, city_name: "London,UK", mode: :xml
13
+
14
+ # Response in HTML format
15
+ puts weather.get :current, city_name: "London,UK", mode: :html
@@ -0,0 +1,14 @@
1
+ require 'owmo'
2
+
3
+ api_key = ""
4
+
5
+ weather = OWMO::Weather.new api_key
6
+
7
+ # Kelvin
8
+ puts weather.get :current, city_name: "London,UK"
9
+
10
+ # Imperial
11
+ puts weather.get :current, city_name: "London,UK", units: :imperial
12
+
13
+ # Metric
14
+ puts weather.get :current, city_name: "London,UK", units: :metric
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 = "0.2.0"
6
+ VERSION = "1.0.0"
7
7
 
8
8
  end # OWMO
data/lib/owmo/weather.rb CHANGED
@@ -16,14 +16,53 @@ A weather class for retrieving current and forecasted weather conditions.
16
16
  =end
17
17
  class Weather
18
18
 
19
+ attr_reader :api_key, :Paths, :Geocodes
20
+
19
21
  =begin rdoc
20
- Raised when missing OpenWeatherMap.org API key
22
+ Access current or forecasted conditions by (required):
23
+ * +:current+ - {Current weather data}[http://openweathermap.org/current]
24
+ * +:forecast5+ - {5 day / 3 hour forecast}[http://openweathermap.org/forecast5]
25
+ * +:forecast16+ - {16 day / daily forecast}[http://openweathermap.org/forecast16]
21
26
  =end
22
- class MissingApiKey < StandardError
23
- def initialize()
24
- super("Missing OpenWeatherMap.org API key, please register for one here -> http://openweathermap.org/appid")
25
- end # initialize
26
- end # MissingApiKey
27
+ Paths = {
28
+ current: 'weather', # Current weather data
29
+ forecast5: 'forecast', # 5 day / 3 hour forecast
30
+ forecast16: 'forecast/daily' # 16 day / daily forecast
31
+ }
32
+
33
+ =begin rdoc
34
+ {Geocode options (required):}[http://openweathermap.org/current#one]
35
+ * +q:+ or +city_name:+ - By city name
36
+ * +id:+ or +city_id:+ - By city ID
37
+ * +zip:+ or +zip_code:+ - By zip code
38
+ * +lat:+, +lon:+ or +latitude:+, +longitude:+ - By geographic coordinates
39
+ =end
40
+ Geocodes = {
41
+ "City Name" => {
42
+ query: :q,
43
+ options: [:q, :city_name]
44
+ },
45
+ "City ID" => {
46
+ query: :id,
47
+ options: [:id, :city_id]
48
+ },
49
+ "Zip Code" => {
50
+ query: :zip,
51
+ options: [:zip, :zip_code]
52
+ },
53
+ "Coordinance" => {
54
+ query: [:lat, :lon],
55
+ options: [[:lat, :lon], [:lattitude, :longitude]]
56
+ },
57
+ "Cities Within a Rectangle Zone" => {
58
+ query: :bbox,
59
+ options: [:bbox]
60
+ },
61
+ "Cities Within a Circle" => {
62
+ query: [:lat, :lon, :cnt],
63
+ options: [[:lat, :lon, :cnt],[:lattitude, :longitude, :cnt]]
64
+ }
65
+ }
27
66
 
28
67
  =begin rdoc
29
68
  Invalid path specified
@@ -31,7 +70,7 @@ Invalid path specified
31
70
  class InvalidPathSpecified < StandardError
32
71
  def initialize(path=nil)
33
72
  @path = path
34
- super("Invalid path specified: Got: '#{@path}', expected one of: #{OWMO::PATHS.keys}")
73
+ super("Invalid path specified: Got: '#{@path}', expected one of: #{Paths.keys}")
35
74
  end # initialize
36
75
  end # NoGeocodeSpecified
37
76
 
@@ -41,20 +80,15 @@ Missing Geocode from query
41
80
  class MissingGeocodes < StandardError
42
81
  end # MissingGeocodes
43
82
 
44
- =begin rdoc
45
- {OpenWeatherMap.org API key}[http://openweathermap.org/appid]
46
- =end
47
- attr_reader :api_key
48
83
 
49
- def initialize(**kwargs) #:notnew:
50
- raise MissingApiKey if kwargs[:api_key].nil?
51
- @api_key = kwargs[:api_key]
84
+ def initialize(api_key, **kwargs) #:notnew:
85
+ @api_key = api_key
52
86
  end # initialize
53
87
 
54
88
  =begin rdoc
55
89
  A weather class for retrieving current and forecasted weather conditions.
56
90
  ==== Attributes
57
- * +path+ - OWMO::PATH parameter
91
+ * +path+ - OWMO::Wether.Path parameter
58
92
  * +query+ - Hash of query options (Geocode, response format, units, etc.)
59
93
  ==== Examples
60
94
  api_key = "<My API Key>"
@@ -67,11 +101,11 @@ A weather class for retrieving current and forecasted weather conditions.
67
101
  query = check_geocodes query
68
102
 
69
103
  # Add the api key
70
- query[:APPID] = @api_key if query[:APPID].nil?
104
+ query[:APPID] = @api_key
71
105
 
72
106
  # Create the uri
73
- raise InvalidPathSpecified.new(path) if OWMO::PATHS[path].nil?
74
- uri = URI "#{OWMO::URL}/#{OWMO::PATHS[path]}?#{URI.encode_www_form(query)}"
107
+ raise InvalidPathSpecified.new(path) if Paths[path].nil?
108
+ uri = URI "#{OWMO::URL}/#{Paths[path]}?#{URI.encode_www_form(query)}"
75
109
 
76
110
  # Get the weather data
77
111
  OWMO::API.get(uri)
@@ -86,7 +120,7 @@ Ensure appropriate query options are applied to the final URI
86
120
  # May never be called since query is required
87
121
  raise MissingGeocodes if query.size == 0
88
122
 
89
- GEOCODES.each do |name, geocodes|
123
+ Geocodes.each do |name, geocodes|
90
124
 
91
125
  # Get the common keys
92
126
  intersect = geocodes[:options].flatten & query.keys
data/lib/owmo.rb CHANGED
@@ -13,52 +13,6 @@ Openweathermap.org URL
13
13
  =end
14
14
  URL = 'http://api.openweathermap.org/data/2.5'
15
15
 
16
- =begin rdoc
17
- Access current or forecasted conditions by (required):
18
- * +:current+ - {Current weather data}[http://openweathermap.org/current]
19
- * +:forecast+ - {5 day / 3 hour forecast}[http://openweathermap.org/forecast5]
20
- * +:extended+ - {16 day / daily forecast}[http://openweathermap.org/forecast16]
21
- =end
22
- PATHS = {
23
- current: 'weather', # Current weather data
24
- forecast: 'forecast', # 5 day / 3 hour forecast
25
- extended: 'forecast/daily' # 16 day / daily forecast
26
- }
27
-
28
- =begin rdoc
29
- {Geocode options (required):}[http://openweathermap.org/current#one]
30
- * +q:+ or +city_name:+ - By city name
31
- * +id:+ or +city_id:+ - By city ID
32
- * +zip:+ or +zip_code:+ - By zip code
33
- * +lat:+, +lon:+ or +latitude:+, +longitude:+ - By geographic coordinates
34
- =end
35
- GEOCODES = {
36
- "City Name" => {
37
- query: :q,
38
- options: [:q, :city_name]
39
- },
40
- "City ID" => {
41
- query: :id,
42
- options: [:id, :city_id]
43
- },
44
- "Zip Code" => {
45
- query: :zip,
46
- options: [:zip, :zip_code]
47
- },
48
- "Coordinance" => {
49
- query: [:lat, :lon],
50
- options: [[:lat, :lon], [:lattitude, :longitude]]
51
- },
52
- "Cities Within a Rectangle Zone" => {
53
- query: :bbox,
54
- options: [:bbox]
55
- },
56
- "Cities Within a Circle" => {
57
- query: [:lat, :lon, :cnt],
58
- options: [[:lat, :lon, :cnt],[:lattitude, :longitude, :cnt]]
59
- }
60
- }
61
-
62
16
  =begin rdoc
63
17
  Yield a weather object for querying weather data
64
18
  ==== Attributes
@@ -70,9 +24,9 @@ Yield a weather object for querying weather data
70
24
  end
71
25
  =end
72
26
  public
73
- def self.weather(**params)
74
- w = Weather.new params
75
- yield w
27
+ def self.weather(api_key, **params)
28
+ weather = Weather.new api_key, params
29
+ yield weather
76
30
  end # weather
77
31
 
78
32
  end # OWMO
data/owmo.gemspec CHANGED
@@ -14,15 +14,6 @@ Gem::Specification.new do |spec|
14
14
  spec.homepage = "https://github.com/robb-randall/owmo"
15
15
  spec.license = "MIT"
16
16
 
17
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
- # to allow pushing to a single host or delete this section to allow pushing to any host.
19
- # if spec.respond_to?(:metadata)
20
- # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
- # else
22
- # raise "RubyGems 2.0 or newer is required to protect against " \
23
- # "public gem pushes."
24
- # end
25
-
26
17
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
18
  f.match(%r{^(test|spec|features)/})
28
19
  end
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: 0.2.0
4
+ version: 1.0.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 00:00:00.000000000 Z
11
+ date: 2017-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -69,9 +69,13 @@ files:
69
69
  - _config.yml
70
70
  - bin/console
71
71
  - bin/setup
72
- - examples/current_conditions.rb
73
- - examples/extended.rb
74
- - examples/forecast.rb
72
+ - examples/current.rb
73
+ - examples/forecast16.rb
74
+ - examples/forecast5.rb
75
+ - examples/query_all.rb
76
+ - examples/query_geocode.rb
77
+ - examples/query_mode.rb
78
+ - examples/query_units.rb
75
79
  - lib/core_extensions/core_extensions.rb
76
80
  - lib/core_extensions/net/http_response/weather_response.rb
77
81
  - lib/owmo.rb
@@ -1,21 +0,0 @@
1
- require 'owmo'
2
-
3
- =begin rdoc
4
- An example on how to get current conditions and use the different parameters.
5
- =end
6
- api_key = ""
7
-
8
- OWMO::weather api_key: api_key do |weather|
9
-
10
- # http://openweathermap.org/current#data
11
- query = {
12
- city_name: "London,uk", # [city_name, city_id, zip, lat/lon]
13
- mode: 'json', # [json, xml, html] Not required, but an option
14
- units: 'imperial', # [imperial, metric] Not required, but an option
15
- lang: 'en_US' # Not required, but an option
16
- }
17
-
18
- current_condition = weather.get :current, query
19
-
20
- puts current_condition
21
- end
data/examples/extended.rb DELETED
@@ -1,22 +0,0 @@
1
- require 'owmo'
2
-
3
-
4
- =begin rdoc
5
- An example on how to get the weather forcast and use the different parameters.
6
- =end
7
- api_key = ""
8
-
9
- OWMO::weather api_key: api_key do |weather|
10
-
11
- # http://openweathermap.org/forecast16
12
- query = {
13
- lat: "40.7128", lon: "74.0059", # [city_name, city_id, zip, lat/lon]
14
- mode: 'json', # [json, xml, html] Not required, but an option
15
- units: 'imperial', # [imperial, metric] Not required, but an option
16
- lang: 'en_US' # Not required, but an option
17
- }
18
-
19
- extended = weather.get :extended, query
20
-
21
- puts extended
22
- end
data/examples/forecast.rb DELETED
@@ -1,22 +0,0 @@
1
- require 'owmo'
2
-
3
-
4
- =begin rdoc
5
- An example on how to get the extended forcast and use the different parameters.
6
- =end
7
- api_key = ""
8
-
9
- OWMO::weather api_key: api_key do |weather|
10
-
11
- # http://openweathermap.org/forecast5
12
- query = {
13
- zip: "90210", # [city_name, city_id, zip, lat/lon]
14
- mode: 'json', # [json, xml, html] Not required, but an option
15
- units: 'imperial', # [imperial, metric] Not required, but an option
16
- lang: 'en_US' # Not required, but an option
17
- }
18
-
19
- forecast = weather.get :forecast, query
20
-
21
- puts forecast
22
- end