wwo 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 69ed0093900d5a3ce6ddca9f38329258f8acaf3f
4
- data.tar.gz: 959747ab557362b50420fcb0e5644d157e7df0fe
3
+ metadata.gz: 5ae33e5981b99fefd36ecdb1fbe07b00af621a18
4
+ data.tar.gz: ac031c224fbecacae3ac6c6f834abfac4be2ef45
5
5
  SHA512:
6
- metadata.gz: 6f67b4b63ed61559d448956030e954629b2213e76c65170e7cad786d98061330f0e40641de4087e11ead8e967339bec594763924dfba09a29633df37f6d11ac9
7
- data.tar.gz: 87c718c2af4384a54761056d44fa32510834038dabcd16f784ffa98327c1500bb25f0c799685e6e56ca5591ad5ad7ae1949ef4870981da40bd75a97525c9c936
6
+ metadata.gz: b7b59c7c8fb1df6f0055e3d27b99a9be3b4c2dc0aaf73f646eeeb7f5485b641dcde92e006daa98a967f921167ccc124ac4c706c22e234127615e08731f25ab3b
7
+ data.tar.gz: a2e756f02fa2ae3761c256108ae97a75a71342f3b332ea6fd032d85f73ffd35d13ce25eafd284e9b0485f36a24d2d50e9e02feaf2bd1666d37d3ebf0e6365336
data/Gemfile CHANGED
@@ -2,6 +2,3 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in wwo.gemspec
4
4
  gemspec
5
-
6
- gem "simplecov", group: :test, require: false
7
- gem "codeclimate-test-reporter", group: :test, require: false
data/README.md CHANGED
@@ -1,10 +1,10 @@
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)
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) [![Badges](http://img.shields.io/:badges-6/6-ff6799.svg)](https://github.com/badges/badgerbadgerbadger)
4
4
 
5
5
  This gem provides a (for now) very opinionated interface to [World Weather Online's API][1]. It's based heavily on the
6
- [forecast-ruby gem](https://github.com/darkskyapp/forecast-ruby) by the wonderful people over at Dark Skies / Forecast.io
7
- and was bourne out of the need to have a drop in replacemnet for Forecast.io in an application.
6
+ [forecast-ruby gem](https://github.com/darkskyapp/forecast-ruby) by David Czarnecki and was bourne out of the need to have a
7
+ drop in replacemnet for Forecast.io in an application.
8
8
 
9
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
10
  however, there are the following assumptions / options that you need to be aware of:
data/lib/wwo.rb CHANGED
@@ -14,6 +14,32 @@ module Wwo
14
14
 
15
15
  class << self
16
16
 
17
+ # Returns a daily breakdown for weather for the provided start and end data at the
18
+ # specified location.
19
+ #
20
+ def date_range(start_date, end_date, latitude, longitude, forecast_compat = false)
21
+ starting = start_date.strftime('%F')
22
+ ending = end_date.strftime('%F')
23
+
24
+ uri = "#{Wwo.api_endpoint}/past-weather.ashx?q=#{latitude},#{longitude}&format=json&extra=utcDateTime&date=#{starting}&enddate=#{ending}&show_comments=no&tp=24&key=#{Wwo.api_key}&mca=false&show_comments=false"
25
+
26
+ if forecast_compat
27
+ make_into_forecast_response(api_call(uri))
28
+ else
29
+ api_call(uri)
30
+ end
31
+ end
32
+
33
+ # Returns an hourly breakdown for the weather "today" at the given location. We get
34
+ # the current time and then turn it into UTC. Returns a Hashie Mash with every hour of
35
+ # weather broken down.
36
+ #
37
+ def today(latitude, longitude)
38
+ date = Time.now.utc.strftime("%F")
39
+ uri = "#{Wwo.api_endpoint}/weather.ashx?q=#{latitude},#{longitude}&date=today&num_of_days=1&tp=1&format=json&key=#{Wwo.api_key}&mca=false&show_comments=false"
40
+ api_call(uri)
41
+ end
42
+
17
43
  # Provides API compatibility to forecast.io's rubygem - expects the same signature and a
18
44
  # Unix Timestamp for :time, it will use the historic / now_or_later methods under the hood
19
45
  # to actually do its work.
@@ -91,10 +117,22 @@ module Wwo
91
117
  # Munges the repsonse into one like what we would expect from Forecast.io
92
118
  #
93
119
  def make_into_forecast_response(response)
94
- data = { daily: { data: [ { icon: '', 'temperatureMax' => 0, 'temperatureMin' => 0 } ] }, alerts: nil }
95
- data[:daily][:data][0][:icon] = response.data.weather.first.hourly.first.weatherIconUrl.first.value
96
- data[:daily][:data][0]['temperatureMax'] = response.data.weather.first.maxtempC
97
- data[:daily][:data][0]['temperatureMin'] = response.data.weather.first.mintempC
120
+ if ! response.data.weather.nil? && response.data.weather.any? && response.data.weather.size > 1
121
+ data = { daily: { data: [] } }
122
+ response.data.weather.each do |weather|
123
+ icon = weather.hourly.first.weatherIconUrl.first.value
124
+ maxTemp = weather.maxtempC
125
+ minTemp = weather.mintempC
126
+ date = Time.parse("#{weather.date} 12:00:00")
127
+
128
+ data[:daily][:data] << { icon: icon, "temperatureMax" => maxTemp, "temperatureMin" => minTemp, date: date }
129
+ end
130
+ else
131
+ data = { daily: { data: [ { icon: '', 'temperatureMax' => 0, 'temperatureMin' => 0 } ] }, alerts: nil }
132
+ data[:daily][:data][0][:icon] = response.data.weather.first.hourly.first.weatherIconUrl.first.value
133
+ data[:daily][:data][0]['temperatureMax'] = response.data.weather.first.maxtempC
134
+ data[:daily][:data][0]['temperatureMin'] = response.data.weather.first.mintempC
135
+ end
98
136
  Hashie::Mash.new(data)
99
137
  end
100
138
  end
@@ -31,7 +31,7 @@ module Wwo
31
31
 
32
32
  # API endpoint
33
33
  def api_endpoint
34
- ( use_premium_api? ? DEFAULT_PREMIUM_ENDPOINT : DEFAULT_FREE_ENDPOINT )
34
+ @api_endpoint.nil? ? ( use_premium_api? ? DEFAULT_PREMIUM_ENDPOINT : DEFAULT_FREE_ENDPOINT ) : @api_endpoint
35
35
  end
36
36
 
37
37
  # API key
@@ -1,3 +1,3 @@
1
1
  module Wwo
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -29,4 +29,7 @@ Gem::Specification.new do |spec|
29
29
  spec.add_development_dependency "rspec", "~> 3.0"
30
30
  spec.add_development_dependency('vcr')
31
31
  spec.add_development_dependency('typhoeus')
32
+
33
+ spec.add_development_dependency("simplecov")
34
+ spec.add_development_dependency("codeclimate-test-reporter")
32
35
  end
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.2
4
+ version: 0.2.0
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-06 00:00:00.000000000 Z
13
+ date: 2016-02-22 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: faraday
@@ -138,6 +138,34 @@ dependencies:
138
138
  - - ">="
139
139
  - !ruby/object:Gem::Version
140
140
  version: '0'
141
+ - !ruby/object:Gem::Dependency
142
+ name: simplecov
143
+ requirement: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ type: :development
149
+ prerelease: false
150
+ version_requirements: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ - !ruby/object:Gem::Dependency
156
+ name: codeclimate-test-reporter
157
+ requirement: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ type: :development
163
+ prerelease: false
164
+ version_requirements: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
141
169
  description:
142
170
  email:
143
171
  - r.stenhouse@allm.net