wwo 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +16 -0
- data/.rubocop.yml +1168 -0
- data/.travis.yml +3 -0
- data/Gemfile +3 -0
- data/README.md +11 -3
- data/lib/wwo.rb +17 -17
- data/lib/wwo/configuration.rb +2 -2
- data/lib/wwo/version.rb +1 -1
- metadata +4 -2
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,11 +1,19 @@
|
|
1
1
|
# WWO - World Weather Online API Gem
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/wwo.svg)](https://badge.fury.io/rb/wwo) [![Build Status](https://travis-ci.org/sujrd/wwo.svg?branch=master)](https://travis-ci.org/sujrd/wwo) [![Join the chat at https://gitter.im/sujrd/wwo](https://badges.gitter.im/sujrd/wwo.svg)](https://gitter.im/sujrd/wwo?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Code Climate](https://codeclimate.com/github/sujrd/wwo/badges/gpa.svg)](https://codeclimate.com/github/sujrd/wwo) [![Test Coverage](https://codeclimate.com/github/sujrd/wwo/badges/coverage.svg)](https://codeclimate.com/github/sujrd/wwo/coverage) [![License](http://img.shields.io/:license-mit-blue.svg)](http://sujrd.mit-license.org)
|
4
|
+
|
3
5
|
This gem provides a (for now) very opinionated interface to [World Weather Online's API][1]. It's based heavily on the
|
4
6
|
[forecast-ruby gem](https://github.com/darkskyapp/forecast-ruby) by the wonderful people over at Dark Skies / Forecast.io
|
5
7
|
and was bourne out of the need to have a drop in replacemnet for Forecast.io in an application.
|
6
8
|
|
7
|
-
The plan is to
|
8
|
-
|
9
|
+
The plan is to enhance this over time so that it supports more of WWO's API and is a bit more developer friendly. Right now,
|
10
|
+
however, there are the following assumptions / options that you need to be aware of:
|
11
|
+
|
12
|
+
* Temperatures are always returned in **degrees celcius**.
|
13
|
+
* For now we only expect requests for one day at a time, as per the way forecast-ruby works
|
14
|
+
* We only pull in **daily snapshot** information, that is, the predomanant weather over the 24h period of the day in question.
|
15
|
+
* We futz around with the response back, so it is in the same shape of JSON as you get back from `forecast.io`. This is intentional -
|
16
|
+
remember that we intend this to be (for now), a drop-in replacement for forecast.io.
|
9
17
|
|
10
18
|
## Installation
|
11
19
|
|
@@ -67,4 +75,4 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/sujrd/
|
|
67
75
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
68
76
|
|
69
77
|
|
70
|
-
[1]: https://developer.worldweatheronline.com
|
78
|
+
[1]: https://developer.worldweatheronline.com
|
data/lib/wwo.rb
CHANGED
@@ -26,9 +26,9 @@ module Wwo
|
|
26
26
|
end
|
27
27
|
|
28
28
|
if date.to_i < Time.now.to_i
|
29
|
-
historic(latitude, longitude, date)
|
29
|
+
make_into_forecast_response(historic(latitude, longitude, date))
|
30
30
|
else
|
31
|
-
now_or_later(latitude, longitude, date)
|
31
|
+
make_into_forecast_response(now_or_later(latitude, longitude, date))
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
@@ -42,12 +42,7 @@ module Wwo
|
|
42
42
|
def historic(latitude, longitude, date_or_timestamp)
|
43
43
|
date = date_or_timestamp.is_a?(Numeric) ? Time.at(date_or_timestamp).strftime("%F") : date_or_timestamp.strftime("%F")
|
44
44
|
uri = "#{Wwo.api_endpoint}/past-weather.ashx?q=#{latitude},#{longitude}&date=#{date}&tp=24&format=json&key=#{Wwo.api_key}"
|
45
|
-
|
46
|
-
api_response = get(uri)
|
47
|
-
|
48
|
-
if api_response.success?
|
49
|
-
return parse_response(Hashie::Mash.new(MultiJson.load(api_response.body)))
|
50
|
-
end
|
45
|
+
api_call(uri)
|
51
46
|
end
|
52
47
|
|
53
48
|
# Returns historic weather at the provided latitude and longitude coordinates, on a
|
@@ -60,14 +55,10 @@ module Wwo
|
|
60
55
|
def now_or_later(latitude, longitude, date_or_timestamp = Date.today)
|
61
56
|
date = date_or_timestamp.is_a?(Numeric) ? Time.at(date_or_timestamp).strftime("%F") : date_or_timestamp.strftime("%F")
|
62
57
|
uri = "#{Wwo.api_endpoint}/weather.ashx?q=#{latitude},#{longitude}&date=#{date}&num_of_days=1&tp=24&format=json&key=#{Wwo.api_key}"
|
63
|
-
|
64
|
-
api_response = get(uri)
|
65
|
-
|
66
|
-
if api_response.success?
|
67
|
-
return parse_response(Hashie::Mash.new(MultiJson.load(api_response.body)))
|
68
|
-
end
|
58
|
+
api_call(uri)
|
69
59
|
end
|
70
60
|
|
61
|
+
|
71
62
|
# Build or get an HTTP connection object.
|
72
63
|
def connection
|
73
64
|
return @connection if @connection
|
@@ -83,6 +74,15 @@ module Wwo
|
|
83
74
|
|
84
75
|
private
|
85
76
|
|
77
|
+
def api_call(uri)
|
78
|
+
api_response = get(uri)
|
79
|
+
if api_response.success?
|
80
|
+
return Hashie::Mash.new(MultiJson.load(api_response.body))
|
81
|
+
else
|
82
|
+
return {}
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
86
|
def get(path, params = {})
|
87
87
|
params = Wwo.default_params.merge(params || {})
|
88
88
|
connection.get(path, params)
|
@@ -90,12 +90,12 @@ module Wwo
|
|
90
90
|
|
91
91
|
# Munges the repsonse into one like what we would expect from Forecast.io
|
92
92
|
#
|
93
|
-
def
|
94
|
-
data = { daily: { data: [ { icon: '', 'temperatureMax' => 0, 'temperatureMin' => 0 } ] } }
|
93
|
+
def make_into_forecast_response(response)
|
94
|
+
data = { daily: { data: [ { icon: '', 'temperatureMax' => 0, 'temperatureMin' => 0 } ] }, alerts: nil }
|
95
95
|
data[:daily][:data][0][:icon] = response.data.weather.first.hourly.first.weatherIconUrl.first.value
|
96
96
|
data[:daily][:data][0]['temperatureMax'] = response.data.weather.first.maxtempC
|
97
97
|
data[:daily][:data][0]['temperatureMin'] = response.data.weather.first.mintempC
|
98
|
-
data
|
98
|
+
Hashie::Mash.new(data)
|
99
99
|
end
|
100
100
|
end
|
101
101
|
end
|
data/lib/wwo/configuration.rb
CHANGED
@@ -31,7 +31,7 @@ module Wwo
|
|
31
31
|
|
32
32
|
# API endpoint
|
33
33
|
def api_endpoint
|
34
|
-
|
34
|
+
( use_premium_api? ? DEFAULT_PREMIUM_ENDPOINT : DEFAULT_FREE_ENDPOINT )
|
35
35
|
end
|
36
36
|
|
37
37
|
# API key
|
@@ -51,7 +51,7 @@ module Wwo
|
|
51
51
|
private
|
52
52
|
|
53
53
|
def use_premium_api?
|
54
|
-
|
54
|
+
use_premium_api == true
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
data/lib/wwo/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wwo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "株式会社アルム Allm Inc"
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2016-01-
|
13
|
+
date: 2016-01-06 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: faraday
|
@@ -145,8 +145,10 @@ executables: []
|
|
145
145
|
extensions: []
|
146
146
|
extra_rdoc_files: []
|
147
147
|
files:
|
148
|
+
- ".codeclimate.yml"
|
148
149
|
- ".gitignore"
|
149
150
|
- ".rspec"
|
151
|
+
- ".rubocop.yml"
|
150
152
|
- ".travis.yml"
|
151
153
|
- CODE_OF_CONDUCT.md
|
152
154
|
- Gemfile
|