forecast 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MmVhOTY5N2E5MTc3N2Y5NzBlZGIxNGQ5NWJiYjE2MjAwOTM1NWJhNA==
5
- data.tar.gz: !binary |-
6
- ZjFiMjJiMzIwMjQyNzQxNmI5NWNjMWUzYWU1NzExNzVjZGNhNmJkOQ==
2
+ SHA1:
3
+ metadata.gz: 7bedac729e0633e851903429abe9b90e389bf394
4
+ data.tar.gz: 0ee0e0f0ca1791b76cb5e85623b524f3bb3b8d6d
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- ZDBmNjUwYjgzZjQxNjVmNjhhZGZjMGJlOTA3MGUzODZhZWM1OTM3OTQ0ZTYx
10
- OTI0OGJjODA1MTIxNjVlYjgxNDEyZThmZmM4Mzc5NzdhYWRlZTExYTMzNTc5
11
- MzdjNzc2ZmViOTAwY2Q0ODFkZWY0YTdhN2RlMWJjMWUwN2JiMDg=
12
- data.tar.gz: !binary |-
13
- YTJhODdhMTI3OTU2Yzk4ZTY4MjAxNDAxYTRlZDE5ODA4ZTRkZDhlM2JjNTNk
14
- ZmNiNzIxODA0YjlmOTQ3YWE2MzNlMTU5NDQwYjFmYWZiOGY3ODM3NTAwYzM0
15
- MjAyN2FjM2UwMTk3MTg0NjYwZTMwZWY4ZGRiMDA0MDI3NDY5MWM=
6
+ metadata.gz: 10567a96c75d32e09fcc00f6d4ffdefcc8e56ae932b8245f2918473f82c9ca32c39afcd2ea16cf8167e50c3d995a9571c59b2bbcea02db77c8cf3f919abd5c2c
7
+ data.tar.gz: 7ec7db3da9a5faa99e42abe359fab5a8760b3296cbd721e58b128bd6d65d3d0001ee0bba6d386f78dc376df9d4acfeb28f5c0aa47230e5ca8bd106f11ea5bd7f
data/.gitignore CHANGED
@@ -16,4 +16,14 @@ test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
18
  .README.md.html
19
- dump.rdb
19
+ dump.rdb
20
+
21
+ # Eclipse
22
+ .project
23
+
24
+ # GFM Preview
25
+ .README.md.html
26
+ .CHANGELOG.md.html
27
+
28
+ # API Test keys
29
+ api_keys.txt
data/CHANGELOG.md ADDED
@@ -0,0 +1,27 @@
1
+ forecast
2
+ --------
3
+
4
+ > Changelog
5
+
6
+ ## Master
7
+
8
+ ## Enhancements
9
+
10
+ * Basic command line interface
11
+ * Added forecast.io adapter
12
+ * Improved auto-mapping of conditions
13
+
14
+ ## Bugfix
15
+
16
+ * Fixed missing string conversion in average temperature
17
+ * Fixed cache inconsistencies by caching http response instead of results
18
+
19
+ ## Deprecation
20
+
21
+ * Removed option `prefix` from cache
22
+ * Renamed method current to currently
23
+ * Changed default scale to `celsius`
24
+
25
+ ## v0.0.7
26
+
27
+ * Initial release introducing core-functionality
data/README.md CHANGED
@@ -1,19 +1,148 @@
1
1
  forecast
2
2
  ========
3
3
 
4
- A Forecast-Multi-API-Wrapper with a unified model and integrated caching
4
+ > Forecast Multi-API-Wrapper with unified model and integrated caching
5
5
 
6
+ ## API Support
6
7
 
7
- Integrating with rails
8
- ----------------------
8
+ * Open Weather Map
9
+ * Yahoo RSS
10
+ * Forecast.io
11
+ * Wunderground
9
12
 
10
- #### Quick start
11
13
 
12
- Add weather-icons theme to your stylesheets from cdn
14
+ ## Fetch
15
+
16
+ #### Forecast.current( latitude, longitude )
17
+ Get the current weather for a specified location
18
+ ```ruby
19
+ forecast = Forecast.current(54.9999, 9.534)
20
+ ```
21
+
22
+ #### Forecast.hourly( latitude, longitude )
23
+ Get hourly forecasts for a specified location
24
+ ```ruby
25
+ forecasts = Forecast.hourly(54.9999, 9.534)
26
+ ```
27
+
28
+
29
+ #### Forecast.daily( latitude, longitude )
30
+ Get daily forecasts for a specified location
31
+ ```ruby
32
+ forecasts = Forecast.daily(54.9999, 9.534)
33
+ ```
34
+
35
+ ### Collections
36
+
37
+ #### ForecastCollection.select_time( date )
38
+ Fetches forecast for the specified date from a collection.
39
+ ```ruby
40
+ forecast = Forecast.daily(54.9999, 9.534).select_time(Time.now + (24 * 60 * 60) * 2)
41
+ ```
42
+
43
+ ## Model
44
+
45
+ <table>
46
+ <tr>
47
+ <th>Name</th>
48
+ <th>Description</th>
49
+ </tr>
50
+ <tr>
51
+ <td>condition</td>
52
+ <td>Condition string identifier.</td>
53
+ </tr>
54
+ <tr>
55
+ <td>time</td>
56
+ <td>DateTime of the forecast</td>
57
+ </tr>
58
+ <tr>
59
+ <td>icon</td>
60
+ <td>Returns icon identifier</td>
61
+ </tr>
62
+ <tr>
63
+ <td>latitude</td>
64
+ <td>Location coordinate latitude</td>
65
+ </tr>
66
+ <tr>
67
+ <td>longitude</td>
68
+ <td>Location coordinate longitude</td>
69
+ </tr>
70
+ <tr>
71
+ <td>temperature</td>
72
+ <td>Temperature</td>
73
+ </tr>
74
+ <tr>
75
+ <td>temperature_min</td>
76
+ <td>Minimum Temperature</td>
77
+ </tr>
78
+ <tr>
79
+ <td>temperature_max</td>
80
+ <td>Maximum Temperature</td>
81
+ </tr>
82
+ </table>
83
+
84
+
85
+ ## Conditions
86
+
87
+ <table>
88
+ <tr>
89
+ <th>Code</th>
90
+ <th>Name</th>
91
+ </tr>
92
+ <tr>
93
+ <td>100</td>
94
+ <td>Clear</td>
95
+ </tr>
96
+ <tr>
97
+ <td>200</td>
98
+ <td>Partly Cloudy</td>
99
+ </tr>
100
+ <tr>
101
+ <td>210</td>
102
+ <td>Cloudy</td>
103
+ </tr>
104
+ <tr>
105
+ <td>220</td>
106
+ <td>Mostly Cloudy</td>
107
+ </tr>
108
+ <tr>
109
+ <td>300</td>
110
+ <td>Light Rain</td>
111
+ </tr>
112
+ <tr>
113
+ <td>310</td>
114
+ <td>Rain</td>
115
+ </tr>
116
+ <tr>
117
+ <td>320</td>
118
+ <td>Heavy Rain</td>
119
+ </tr>
120
+ <tr>
121
+ <td>400</td>
122
+ <td>Light Snow</td>
123
+ </tr>
124
+ <tr>
125
+ <td>410</td>
126
+ <td>Snow</td>
127
+ </tr>
128
+ <tr>
129
+ <td>500</td>
130
+ <td>Storm</td>
131
+ </tr>
132
+ </table>
133
+
134
+
135
+ ## Themes
136
+ Bundled with the plugin is an icon-mapping for [weather_icons](http://erikflowers.github.io/weather-icons/)
137
+
138
+ ## Rails Integration
139
+
140
+ ##### Add weather-icons theme to your stylesheets
13
141
  ```erb
14
142
  <%= stylesheet_link_tag "http://cdnjs.cloudflare.com/ajax/libs/weather-icons/1.2/css/weather-icons.css", media: "all", "data-turbolinks-track" => true %>
15
143
  ```
16
- Create a forecast-helper
144
+
145
+ ##### Create a forecast-helper
17
146
  ```ruby
18
147
  module ApplicationHelper
19
148
  def forecast(latitude, longitude, date)
@@ -23,10 +152,69 @@ module ApplicationHelper
23
152
  end
24
153
  ```
25
154
 
26
- Create a view
155
+ ##### Create a view
27
156
  ```erb
28
157
  <h1>Forecast Test</h1>
29
158
  <p>
30
159
  The weather of tomorrow in New York: <%= forecast(41.145495, -73.994901, Time.now + 60*60*24) %>
31
160
  </p>
32
- ```
161
+ ```
162
+
163
+ #### Example Configuration
164
+
165
+ ```ruby
166
+ # config/initializers/forecast.rb
167
+ Forecast::configure do |config|
168
+ config.config_file = Rails.root.to_s + "/config/forecast.yml"
169
+ config.cache = {
170
+ expire: 1 * 60 * 60,
171
+ url: "redis://xxx/"
172
+ }
173
+ end
174
+ ```
175
+
176
+ ```yml
177
+ # config/forecast.yml
178
+ forecast:
179
+ temperature: celsius
180
+ theme: custom_theme
181
+ themes:
182
+ custom_theme:
183
+ Clear: 'icon-clear'
184
+ Light Rain: 'icon-rain'
185
+ Rain: 'icon-rain'
186
+ Heavy Rain: 'icon-rain'
187
+ Partly Cloudy: 'icon-cloudy'
188
+ Cloudy: 'icon-cloudy'
189
+ Mostly Cloudy: 'icon-cloudy'
190
+ Light Snow: 'icon-snow'
191
+ Snow: 'icon-snow'
192
+ Heavy Snow: 'icon-snow'
193
+ Thunderstorm: 'icon-thunderstorm'
194
+ ```
195
+
196
+ ## Command Line Interface
197
+
198
+ ```cli
199
+ Usage: forecast COMMAND [OPTIONS]
200
+
201
+ Commands
202
+ current: get current weather
203
+ daily: get daily forecasts
204
+ hourly: get hourly forecasts
205
+
206
+ Options
207
+ -l, --location LAT,LNG Location
208
+ -p, --provider PROVIDER Supported API Providers: forecast_io, open_weather_map, wunderground, yahoo
209
+ -a, --api_key API_KEY Apply an api key if neccessary
210
+ -s, --scale SCALE Scale: one of celsius, fahrenheit or kelvin
211
+ ```
212
+
213
+ ## Run Tests
214
+ To run the tests execute `rspec spec` from the command line
215
+ ```cli
216
+ rspec spec
217
+ ```
218
+
219
+ ## Changelog
220
+ See the [Changelog](CHANGELOG.md) for recent enhancements, bugfixes and deprecations.
data/bin/forecast ADDED
@@ -0,0 +1,94 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
4
+ $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
5
+
6
+ require 'forecast'
7
+ require 'optparse'
8
+ require 'ostruct'
9
+
10
+ # Get Constants
11
+ providers = Dir.glob(lib + '/forecast/adapters/*.*').map{ |f| File.basename(f, '_adapter.rb') };
12
+
13
+ # Parse Arguments
14
+ options = OpenStruct.new
15
+ optparser = OptionParser.new do |opt|
16
+ opt.banner = "Usage: forecast COMMAND [OPTIONS]"
17
+ opt.separator ""
18
+ opt.separator "Commands"
19
+ opt.separator " current: get current weather [default]"
20
+ opt.separator " daily: get daily forecasts"
21
+ opt.separator " hourly: get hourly forecasts"
22
+ opt.separator ""
23
+ opt.separator "Options"
24
+
25
+ opt.on('-l', '--location LAT,LNG', 'Location [required]') { |o| options.location = o }
26
+ opt.on('-p', '--provider PROVIDER', 'Supported API Providers: ' + Forecast::PROVIDERS.join(', ')) { |p| options.provider = p }
27
+ opt.on('-a', '--api_key API_KEY', 'Apply an api key if neccessary') { |a| options.api_key = a }
28
+ opt.on('-s', '--scale SCALE', 'Scale: one of celsius, fahrenheit or kelvin') { |s| options.scale = s }
29
+ opt.on('-h', '--help', 'Displays Help') do
30
+ puts opt
31
+ exit
32
+ end
33
+ end
34
+
35
+ optparse = optparser.parse!
36
+
37
+ # Init command
38
+ command = ARGV.shift
39
+
40
+ # Use current as default command if a location has specified
41
+ if !command && options.location.nil?
42
+ puts optparser.to_s
43
+ exit
44
+ else
45
+ command = 'current'
46
+ end
47
+
48
+ # Show errors on missing mandatory options
49
+ mandatory = [:location]
50
+ mandatory.each{ |param|
51
+ if options[param].nil?
52
+ puts "#{param.capitalize} must be specified"
53
+ exit
54
+ end
55
+ }
56
+
57
+
58
+ # Setup Options
59
+ location = options.location.split(/,\s*/)
60
+ latitude = location[0].to_f
61
+ longitude = location[1].to_f
62
+
63
+ # Configure Forecast
64
+ Forecast.configure do |config|
65
+ config.scale = options.scale.to_sym if options.scale
66
+ config.provider = options.provider.to_sym if options.provider
67
+ if options.api_key
68
+ config.adapters||= {}
69
+ config.adapters[config.provider] = {
70
+ api_key: options.api_key
71
+ }
72
+ end
73
+ end
74
+
75
+ # Get forecasts
76
+ forecasts = []
77
+ case command
78
+ when 'current'
79
+ forecasts = [Forecast.current(latitude, longitude)]
80
+ when 'daily'
81
+ forecasts = Forecast.daily(latitude, longitude)
82
+ when 'hourly'
83
+ forecasts = Forecast.hourly(latitude, longitude)
84
+ else
85
+ end
86
+
87
+ # Output
88
+ forecasts.each do |forecast|
89
+ if forecast != nil
90
+ puts forecast.time.strftime("%F %T") + " | " + forecast.temperature.to_s + "° | " + forecast.condition.to_s
91
+ else
92
+ puts 'nil'
93
+ end
94
+ end
data/forecast.gemspec CHANGED
@@ -8,13 +8,14 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Forecast::VERSION
9
9
  spec.authors = ["Rafael Nowrotek"]
10
10
  spec.email = ["mail@benignware.com"]
11
- spec.summary = %q{A Forecast-Multi-API-Wrapper with a unified model and integrated caching}
12
- spec.description = %q{A Forecast-Multi-API-Wrapper with a unified model and integrated caching}
11
+ spec.summary = %q{Forecast Multi-API-Wrapper with unified model and integrated caching}
12
+ spec.description = %q{Forecast Multi-API-Wrapper with unified model and integrated caching}
13
13
  spec.homepage = ""
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ #spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.executables = ["forecast"]
18
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
20
  spec.require_paths = ["lib"]
20
21