wwo 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fde78b945408af8d30ac20e5f143dd502ce82a05
4
+ data.tar.gz: 7e5592d90c69813fb4528ccb8d4b7b41d9c9bf06
5
+ SHA512:
6
+ metadata.gz: e324fc63f41c1f25776767906520e0a2fdbae799cf419f97976cfc1018aae624e2c3ea8dc323089dfb614faf43cd6ee0da1d956c7a5a14434defdac909111fe1
7
+ data.tar.gz: 8d2f67cfc46b68d1cd8e97ce09027a52e6f972f71498a0dc00f61c600cc4484748aae44c99d49e5c056172ff6cf2d19cca11bdfab6832a22e1046dd3feb370e7
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.2
4
+ before_install: gem install bundler -v 1.11.2
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at ryan@ryanstenhouse.eu. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in wwo.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Ryan Stenhouse for 株式会社アルム ( Allm Inc )
4
+ http://allm.net
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in
14
+ all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # WWO - World Weather Online API Gem
2
+
3
+ This gem provides a (for now) very opinionated interface to [World Weather Online's API][1]. It's based heavily on the
4
+ [forecast-ruby gem](https://github.com/darkskyapp/forecast-ruby) by the wonderful people over at Dark Skies / Forecast.io
5
+ and was bourne out of the need to have a drop in replacemnet for Forecast.io in an application.
6
+
7
+ The plan is to ehance this over time so that it supports more of WWO's API. Right now it supports forecasts and historical
8
+ weather for a lat / long pair of anywhere in the world.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'wwo'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install wwo
25
+
26
+ ## Usage
27
+
28
+
29
+ Basic usage is just like the forecast gem. For example, if you were calling the API from a
30
+ Rails action, you might want to do this:
31
+
32
+ ````ruby
33
+ Wwo.configure do |configuration|
34
+ configuration.api_key = 'this-is-your-api-key'
35
+ configuration.use_premium_api = true # default is false
36
+ end
37
+
38
+ Wwo.connection = Faraday.new do |builder|
39
+ builder.use Faraday::HttpCache, store: Rails.cache, serializer: Marshal
40
+ builder.adapter Faraday.default_adapter
41
+ end
42
+
43
+ weather = Wwo.forecast(latitude, longitude, time: timestamp)
44
+ ````
45
+
46
+ The `forecast` method provides API compatibilty with `forecast-ruby`. We also expose `historic` for any
47
+ past weather and `now_or_future` for any forecasting that is required.
48
+
49
+ We also play around with the response we get back from WWO so that it is in the same structure as the response
50
+ from the Dark Sky API. The main difference is that the icon names will be the actual URLs to icon images served
51
+ from WWO's CDN.
52
+
53
+
54
+ ## Development
55
+
56
+ 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.
57
+
58
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
59
+
60
+ ## Contributing
61
+
62
+ Bug reports and pull requests are welcome on GitHub at https://github.com/sujrd/wwo. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
63
+
64
+
65
+ ## License
66
+
67
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
68
+
69
+
70
+ [1]: https://developer.worldweatheronline.com
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "wwo"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,57 @@
1
+ module Wwo
2
+ module Configuration
3
+ # Default API endpoint
4
+ DEFAULT_FREE_ENDPOINT = 'https://api.worldweatheronline.com/free/v2'
5
+ DEFAULT_PREMIUM_ENDPOINT = 'https://api.worldweatheronline.com/premium/v1'
6
+
7
+ # Forecast API endpoint
8
+ attr_writer :api_endpoint
9
+
10
+ # API key
11
+ attr_writer :api_key
12
+
13
+ # Cache Object
14
+ attr_writer :api_cache_store
15
+
16
+ # Cache Object
17
+ attr_writer :use_premium_api
18
+
19
+ # Default parameters
20
+ attr_accessor :default_params
21
+
22
+ # Example:
23
+ #
24
+ # Wwo.configure do |configuration|
25
+ # configuration.use_peremium_api = true
26
+ # configuration.api_key = 'this-is-your-api-key'
27
+ # end
28
+ def configure
29
+ yield self
30
+ end
31
+
32
+ # API endpoint
33
+ def api_endpoint
34
+ @api_endpoint ||= ( use_premium_api? ? DEFAULT_PREMIUM_ENDPOINT : DEFAULT_FREE_ENDPOINT )
35
+ end
36
+
37
+ # API key
38
+ def api_key
39
+ @api_key
40
+ end
41
+
42
+ def use_premium_api
43
+ @use_premium_api
44
+ end
45
+
46
+ # API Cache Object
47
+ def api_cache_store
48
+ @api_cache_store
49
+ end
50
+
51
+ private
52
+
53
+ def use_premium_api?
54
+ Wwo.use_premium_api == true
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,3 @@
1
+ module Wwo
2
+ VERSION = "0.1.0"
3
+ end
data/lib/wwo.rb ADDED
@@ -0,0 +1,92 @@
1
+ require "wwo/version"
2
+ require "wwo/configuration"
3
+
4
+ require 'hashie'
5
+ require 'multi_json'
6
+ require 'faraday'
7
+ require 'date'
8
+
9
+ module Wwo
10
+ extend Configuration
11
+
12
+ self.default_params = {}
13
+ self.api_cache_store = nil
14
+
15
+ class << self
16
+
17
+ # Provides API compatibility to forecast.io's rubygem - expects the same signature and a
18
+ # Unix Timestamp for :time, it will use the historic / now_or_later methods under the hood
19
+ # to actually do its work.
20
+ #
21
+ def forecast(latitude, longitude, options = {})
22
+ if options[:time]
23
+ date = Time.at(options[:time])
24
+ else
25
+ date = Time.now
26
+ end
27
+
28
+ if date.to_i < Time.now.to_i
29
+ historic(latitude, longitude, date)
30
+ else
31
+ now_or_later(latitude, longitude, date)
32
+ end
33
+ end
34
+
35
+ # Returns historic weather at the provided latitude and longitude coordinates, on a
36
+ # specific date.
37
+ #
38
+ # @param latitude [String] Latitude.
39
+ # @param longitude [String] Longitude.
40
+ # @param date [Date] or [Integer] Date, or Unix Timestamp.
41
+ #
42
+ def historic(latitude, longitude, date_or_timestamp)
43
+ date = date_or_timestamp.is_a?(Numeric) ? Time.at(date_or_timestamp).strftime("%F") : date_or_timestamp.strftime("%F")
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 Hashie::Mash.new(MultiJson.load(api_response.body))
50
+ end
51
+ end
52
+
53
+ # Returns historic weather at the provided latitude and longitude coordinates, on a
54
+ # specific date.
55
+ #
56
+ # @param latitude [String] Latitude.
57
+ # @param longitude [String] Longitude.
58
+ # @param date [Date] or [Integer] Date, or Unix Timestamp.
59
+ #
60
+ def now_or_later(latitude, longitude, date_or_timestamp = Date.today)
61
+ date = date_or_timestamp.is_a?(Numeric) ? Time.at(date_or_timestamp).strftime("%F") : date_or_timestamp.strftime("%F")
62
+ 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 Hashie::Mash.new(MultiJson.load(api_response.body))
68
+ end
69
+ end
70
+
71
+ # Build or get an HTTP connection object.
72
+ def connection
73
+ return @connection if @connection
74
+ @connection = Faraday.new
75
+ end
76
+
77
+ # Set an HTTP connection object.
78
+ #
79
+ # @param connection Connection object to be used.
80
+ def connection=(connection)
81
+ @connection = connection
82
+ end
83
+
84
+ private
85
+
86
+ def get(path, params = {})
87
+ params = Wwo.default_params.merge(params || {})
88
+
89
+ connection.get(path, params)
90
+ end
91
+ end
92
+ end
data/wwo.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'wwo/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "wwo"
8
+ spec.version = Wwo::VERSION
9
+ spec.authors = ["株式会社アルム Allm Inc", "Ryan Stenhouse", "David Czarnecki"]
10
+ spec.email = ["r.stenhouse@allm.net"]
11
+
12
+ spec.summary = %q{Rubygem for accessing the free and premium weather APIs from World Weather Online. Inspired by Dark Sky's Forecast.IO gem.}
13
+ spec.homepage = "https://github.com/sujrd/wwo"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+
22
+ spec.add_dependency('faraday')
23
+ spec.add_dependency('faraday-http-cache')
24
+ spec.add_dependency('multi_json')
25
+ spec.add_dependency('hashie')
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.11"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rspec", "~> 3.0"
30
+ spec.add_development_dependency('vcr')
31
+ spec.add_development_dependency('typhoeus')
32
+ end
metadata ADDED
@@ -0,0 +1,187 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wwo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - "株式会社アルム Allm Inc"
8
+ - Ryan Stenhouse
9
+ - David Czarnecki
10
+ autorequire:
11
+ bindir: exe
12
+ cert_chain: []
13
+ date: 2016-01-05 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: faraday
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: faraday-http-cache
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: multi_json
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ - !ruby/object:Gem::Dependency
58
+ name: hashie
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ type: :runtime
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ - !ruby/object:Gem::Dependency
72
+ name: bundler
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - "~>"
76
+ - !ruby/object:Gem::Version
77
+ version: '1.11'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - "~>"
83
+ - !ruby/object:Gem::Version
84
+ version: '1.11'
85
+ - !ruby/object:Gem::Dependency
86
+ name: rake
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - "~>"
90
+ - !ruby/object:Gem::Version
91
+ version: '10.0'
92
+ type: :development
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - "~>"
97
+ - !ruby/object:Gem::Version
98
+ version: '10.0'
99
+ - !ruby/object:Gem::Dependency
100
+ name: rspec
101
+ requirement: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - "~>"
104
+ - !ruby/object:Gem::Version
105
+ version: '3.0'
106
+ type: :development
107
+ prerelease: false
108
+ version_requirements: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - "~>"
111
+ - !ruby/object:Gem::Version
112
+ version: '3.0'
113
+ - !ruby/object:Gem::Dependency
114
+ name: vcr
115
+ requirement: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ type: :development
121
+ prerelease: false
122
+ version_requirements: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ - !ruby/object:Gem::Dependency
128
+ name: typhoeus
129
+ requirement: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ description:
142
+ email:
143
+ - r.stenhouse@allm.net
144
+ executables: []
145
+ extensions: []
146
+ extra_rdoc_files: []
147
+ files:
148
+ - ".gitignore"
149
+ - ".rspec"
150
+ - ".travis.yml"
151
+ - CODE_OF_CONDUCT.md
152
+ - Gemfile
153
+ - LICENSE.txt
154
+ - README.md
155
+ - Rakefile
156
+ - bin/console
157
+ - bin/setup
158
+ - lib/wwo.rb
159
+ - lib/wwo/configuration.rb
160
+ - lib/wwo/version.rb
161
+ - wwo.gemspec
162
+ homepage: https://github.com/sujrd/wwo
163
+ licenses:
164
+ - MIT
165
+ metadata: {}
166
+ post_install_message:
167
+ rdoc_options: []
168
+ require_paths:
169
+ - lib
170
+ required_ruby_version: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ required_rubygems_version: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - ">="
178
+ - !ruby/object:Gem::Version
179
+ version: '0'
180
+ requirements: []
181
+ rubyforge_project:
182
+ rubygems_version: 2.4.8
183
+ signing_key:
184
+ specification_version: 4
185
+ summary: Rubygem for accessing the free and premium weather APIs from World Weather
186
+ Online. Inspired by Dark Sky's Forecast.IO gem.
187
+ test_files: []