duststorm 0.0.1

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.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +7 -0
  4. data/LICENSE +22 -0
  5. data/README.md +31 -0
  6. data/Rakefile +1 -0
  7. data/duststorm.gemspec +31 -0
  8. data/lib/duststorm/attribute/coordinate.rb +9 -0
  9. data/lib/duststorm/attribute/time.rb +10 -0
  10. data/lib/duststorm/attribute.rb +9 -0
  11. data/lib/duststorm/base.rb +21 -0
  12. data/lib/duststorm/forecast/base.rb +15 -0
  13. data/lib/duststorm/forecast.rb +11 -0
  14. data/lib/duststorm/utils/response_mapper.rb +73 -0
  15. data/lib/duststorm/utils.rb +6 -0
  16. data/lib/duststorm/version.rb +3 -0
  17. data/lib/duststorm/weather/base.rb +11 -0
  18. data/lib/duststorm/weather/current.rb +7 -0
  19. data/lib/duststorm/weather/daily.rb +11 -0
  20. data/lib/duststorm/weather/hourly.rb +9 -0
  21. data/lib/duststorm/weather.rb +11 -0
  22. data/lib/duststorm/weather_api.rb +23 -0
  23. data/lib/duststorm/weather_apis/base.rb +39 -0
  24. data/lib/duststorm/weather_apis/forecast_io.rb +55 -0
  25. data/lib/duststorm/weather_apis/wunderground.rb +6 -0
  26. data/lib/duststorm.rb +25 -0
  27. data/spec/cassettes/forecast_for_forecast_io.yml +1159 -0
  28. data/spec/cassettes/forecast_for_wunderground.yml +581 -0
  29. data/spec/duststorm/base_spec.rb +26 -0
  30. data/spec/duststorm/forecast/base_spec.rb +50 -0
  31. data/spec/duststorm/forecast_spec.rb +18 -0
  32. data/spec/duststorm/version_spec.rb +7 -0
  33. data/spec/duststorm/weather/hourly_spec.rb +28 -0
  34. data/spec/duststorm/weather_api_spec.rb +12 -0
  35. data/spec/duststorm_spec.rb +25 -0
  36. data/spec/features/weather_services_spec.rb +83 -0
  37. data/spec/spec_helper.rb +24 -0
  38. data/spec/support/have_keys.rb +10 -0
  39. data/spec/support/matchers/be_a_forecast_json_matcher.rb +19 -0
  40. metadata +221 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a41814cee804a7e40df4f7076cd15708bca33229
4
+ data.tar.gz: 3d1a0061ae74f585eb2b6b63d3d8cb611817a63f
5
+ SHA512:
6
+ metadata.gz: 47ed72c089c4d8e3f46e243ebd7739d5be00766f899dbf4b467f6fd91f19bde6ff4059b4bd8ab810afc3eb1eb570dd00069086a4a2f6e2338346d151d51f99a3
7
+ data.tar.gz: 7a2a82349c0d4a8d603bbb5a5b600930b834d1e239f32ed3e96b3ac9e77c3043de5256fcbd5a21a245d77baf438ceaf97e740d3ebd13e0fa41acf1635e793f3a
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ tmp
5
+ .DS_Store
6
+ coverage
7
+ rdoc
8
+ pkg
9
+ lib/attic
10
+ coverage
11
+ .rvmrc
12
+ .rspec
13
+ .bundle
14
+ Gemfile.lock
15
+ .ruby-version
16
+ .rbx
17
+ tags
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development, :test do
6
+ gem 'pry'
7
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Kevin McNamee
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # duststorm
2
+ Receive current, daily, and hourly weather forecasts from multiple APIs.
3
+
4
+ ## Installation
5
+
6
+ _*Important: This gem is not yet published*_
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'duststorm'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install duststorm
19
+
20
+ ## Usage
21
+
22
+ TODO: Write usage instructions here
23
+
24
+ ## Contributing
25
+
26
+ 1. Fork it ( http://github.com/kevinmcnamee/duststorm/fork )
27
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
28
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
29
+ 4. Push to the branch (`git push origin my-new-feature`)
30
+ 5. Create new Pull Request
31
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/duststorm"
data/duststorm.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ require 'duststorm/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "duststorm"
8
+ s.version = Duststorm::VERSION
9
+ s.authors = ["Kevin Mcnamee"]
10
+ s.email = ["kevin@frothylabs.com"]
11
+ s.homepage = "https://github.com/kevinmcnamee/duststorm"
12
+ s.summary = %q{Multiple weather API ruby wrapper}
13
+ s.description = %q{Multiple weather API ruby wrapper}
14
+ s.homepage = ""
15
+ s.license = 'MIT'
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- spec/*`.split("\n")
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency 'faraday'
22
+ s.add_dependency 'multi_json'
23
+ s.add_dependency 'virtus'
24
+
25
+ s.add_development_dependency 'rake'
26
+ s.add_development_dependency 'rspec'
27
+ s.add_development_dependency 'vcr'
28
+ s.add_development_dependency 'typhoeus'
29
+ s.add_development_dependency 'bundler', '~> 1.5'
30
+ s.add_development_dependency 'rake'
31
+ end
@@ -0,0 +1,9 @@
1
+ module Duststorm
2
+ module Attribute
3
+ class Coordinate < Virtus::Attribute
4
+ def coerce(value)
5
+ value.to_f
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ module Duststorm
2
+ module Attribute
3
+ class Time < Virtus::Attribute
4
+ def coerce(value)
5
+ return unless value
6
+ ::Time.at(value)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ require 'virtus'
2
+
3
+ module Duststorm
4
+ module Attribute
5
+ end
6
+ end
7
+
8
+ require_relative 'attribute/coordinate'
9
+ require_relative 'attribute/time'
@@ -0,0 +1,21 @@
1
+ module Duststorm
2
+ class Base
3
+ attr_reader :lat, :lng, :options
4
+
5
+ def initialize(lat, lng, options={})
6
+ @lat = lat
7
+ @lng = lng
8
+ @options = options
9
+ end
10
+
11
+ def forecast
12
+ @forecast ||= Forecast.new(weather_data)
13
+ end
14
+
15
+ private
16
+
17
+ def weather_data
18
+ WeatherApi.response(lat,lng,options)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ require 'virtus'
2
+
3
+ module Duststorm
4
+ module Forecast
5
+ class Base
6
+ include Virtus.model
7
+
8
+ attribute :latitude, Duststorm::Attribute::Coordinate
9
+ attribute :longitude, Duststorm::Attribute::Coordinate
10
+ attribute :currently, Duststorm::Weather::Current
11
+ attribute :daily, [Duststorm::Weather::Daily]
12
+ attribute :hourly, [Duststorm::Weather::Hourly]
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ require 'virtus'
2
+
3
+ module Duststorm
4
+ module Forecast
5
+ def self.new(*args)
6
+ Forecast::Base.new(*args)
7
+ end
8
+ end
9
+ end
10
+
11
+ require_relative 'forecast/base'
@@ -0,0 +1,73 @@
1
+ module Duststorm
2
+ module Utils
3
+ module ResponseMapper
4
+ def mapped_response_body
5
+ response = parsed_response_body.dup
6
+
7
+ response[:currently] = currently_response(response).tap do |currently|
8
+ currently[:summary] = currently[summary_key]
9
+ currently[:temperature] = currently[temperature_key]
10
+ currently[:precipitation] = currently[precipitation_key]
11
+ currently[:wind_speed] = currently[wind_speed_key]
12
+ end
13
+
14
+ response[:hourly] = hourly_response(response).each do |hourly|
15
+ hourly[:time] = hourly[time_key]
16
+ hourly[:summary] = hourly[summary_key]
17
+ hourly[:temperature] = hourly[temperature_key]
18
+ hourly[:precipitation] = hourly[precipitation_key]
19
+ hourly[:wind_speed] = hourly[wind_speed_key]
20
+ end
21
+
22
+ response[:daily] = daily_response(response).each do |daily|
23
+ daily[:time] = daily[time_key]
24
+ daily[:summary] = daily[summary_key]
25
+ daily[:low_temperature] = daily[low_temperature_key]
26
+ daily[:high_temperature] = daily[high_temperature_key]
27
+ daily[:precipitation] = daily[precipitation_key]
28
+ daily[:wind_speed] = daily[wind_speed_key]
29
+ daily[:sunrise] = daily[sunrise_key]
30
+ daily[:sunset] = daily[sunset_key]
31
+ end
32
+
33
+ response
34
+ end
35
+
36
+ def time_key
37
+ :time
38
+ end
39
+
40
+ def summary_key
41
+ :summary
42
+ end
43
+
44
+ def sunrise_key
45
+ :sunrise
46
+ end
47
+
48
+ def sunset_key
49
+ :sunset
50
+ end
51
+
52
+ def precipitation_key
53
+ :precipitation
54
+ end
55
+
56
+ def wind_speed_key
57
+ :wind_speed
58
+ end
59
+
60
+ def temperature_key
61
+ :temperature
62
+ end
63
+
64
+ def low_temperature_key
65
+ :low_temperature
66
+ end
67
+
68
+ def high_temperature_key
69
+ :high_temperature
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,6 @@
1
+ module Duststorm
2
+ module Utils
3
+ end
4
+ end
5
+
6
+ require_relative 'utils/response_mapper'
@@ -0,0 +1,3 @@
1
+ module Duststorm
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,11 @@
1
+ module Duststorm
2
+ module Weather
3
+ class Base
4
+ include Virtus.model
5
+
6
+ attribute :summary, String
7
+ attribute :wind_speed, Float
8
+ attribute :precipitation, Float
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ module Duststorm
2
+ module Weather
3
+ class Current < Base
4
+ attribute :temperature, Float
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ module Duststorm
2
+ module Weather
3
+ class Daily < Base
4
+ attribute :sunrise, Duststorm::Attribute::Time
5
+ attribute :sunset, Duststorm::Attribute::Time
6
+ attribute :low_temperature, Float
7
+ attribute :high_temperature, Float
8
+ end
9
+ end
10
+ end
11
+
@@ -0,0 +1,9 @@
1
+ module Duststorm
2
+ module Weather
3
+ class Hourly < Base
4
+ attribute :time, Duststorm::Attribute::Time
5
+ attribute :temperature, Float
6
+ end
7
+ end
8
+ end
9
+
@@ -0,0 +1,11 @@
1
+ require 'virtus'
2
+
3
+ module Duststorm
4
+ module Weather
5
+ end
6
+ end
7
+
8
+ require_relative 'weather/base'
9
+ require_relative 'weather/current'
10
+ require_relative 'weather/daily'
11
+ require_relative 'weather/hourly'
@@ -0,0 +1,23 @@
1
+ module Duststorm
2
+ module WeatherApi
3
+ DEFAULT_FORECAST_URL = 'https://api.forecast.io'
4
+
5
+ def self.response(lat,lng,options)
6
+ WeatherApi::klass.new(lat, lng, options).execute
7
+ end
8
+
9
+ def self.klass
10
+ send(Duststorm.config.keys.first)
11
+ end
12
+
13
+ private
14
+
15
+ def self.forecast_io
16
+ ForecastIo
17
+ end
18
+ end
19
+ end
20
+
21
+ require_relative 'weather_apis/base'
22
+ require_relative 'weather_apis/forecast_io'
23
+ require_relative 'weather_apis/wunderground'
@@ -0,0 +1,39 @@
1
+ module Duststorm
2
+ module WeatherApi
3
+ class Base
4
+ include Utils::ResponseMapper
5
+
6
+ attr_reader :lat, :lng, :options
7
+
8
+ def initialize(lat, lng, options={})
9
+ @lat = lat
10
+ @lng = lng
11
+ @options = options
12
+ end
13
+
14
+ def execute
15
+ if response.success?
16
+ mapped_response_body
17
+ end
18
+ end
19
+
20
+ def response
21
+ @response ||= conn.get(forecast_url, options)
22
+ end
23
+
24
+ def conn
25
+ Faraday.new
26
+ end
27
+
28
+ def forecast_url
29
+ root_url + forecast_path
30
+ end
31
+
32
+ private
33
+
34
+ def parsed_response_body
35
+ MultiJson.load(response.body, :symbolize_keys => true)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,55 @@
1
+ module Duststorm
2
+ module WeatherApi
3
+ class ForecastIo < Base
4
+ def currently_response(response)
5
+ response[:currently]
6
+ end
7
+
8
+ def hourly_response(response)
9
+ response[:hourly][:data]
10
+ end
11
+
12
+ def daily_response(response)
13
+ response[:daily][:data]
14
+ end
15
+
16
+ def sunrise_key
17
+ :sunriseTime
18
+ end
19
+
20
+ def sunset_key
21
+ :sunsetTime
22
+ end
23
+
24
+ def high_temperature_key
25
+ :temperatureMin
26
+ end
27
+
28
+ def low_temperature_key
29
+ :temperatureMax
30
+ end
31
+
32
+ def precipitation_key
33
+ :precipProbability
34
+ end
35
+
36
+ def wind_speed_key
37
+ :windSpeed
38
+ end
39
+
40
+ private
41
+
42
+ def root_url
43
+ 'https://api.forecast.io'
44
+ end
45
+
46
+ def forecast_path
47
+ "/forecast/#{api_key}/#{lat},#{lng}"
48
+ end
49
+
50
+ def api_key
51
+ Duststorm.config[:forecast_io]
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,6 @@
1
+ module Duststorm
2
+ module WeatherApi
3
+ class Wunderground < Base
4
+ end
5
+ end
6
+ end
data/lib/duststorm.rb ADDED
@@ -0,0 +1,25 @@
1
+ require_relative 'duststorm/version'
2
+ require_relative 'duststorm/base'
3
+ require_relative 'duststorm/utils'
4
+ require_relative 'duststorm/attribute'
5
+ require_relative 'duststorm/weather'
6
+ require_relative 'duststorm/forecast'
7
+ require_relative 'duststorm/weather_api'
8
+
9
+ require 'multi_json'
10
+ require 'faraday'
11
+
12
+ module Duststorm
13
+ # Dustorm.config = { forecast_api: :api_key }
14
+ def self.config=(config)
15
+ @@config = config
16
+ end
17
+
18
+ def self.config
19
+ @@config ||= {}
20
+ end
21
+
22
+ def self.new(*args)
23
+ Duststorm::Base.new(*args)
24
+ end
25
+ end