wdt-skywise-forecast 0.1.1

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: d1788ddc4a5f7b13fcb77ad0994694ce2d452940
4
+ data.tar.gz: 9f5b3cf55858bc73c6c618f00f5e8fb7515fabda
5
+ SHA512:
6
+ metadata.gz: 59a58adfc51eb17bc5c5f20b0861a74121b45c7c7666d29fab097d6c2ec6dc548d01e5e4975c59a68def7d20c48de2b6ca61afb83edaa17b6abd930129700d90
7
+ data.tar.gz: 9588eb1dfb575af3ff88ae8dc4ba3b5ef6834c4bc1cceb64ce3cfecb14a636f6b202cfbbfd323f9d9b2eef21914e5be1ff086b62255480f28161d1a76ad65b64
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /.idea/
11
+ /console
12
+ /Guardfile
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.1
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.13.3
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in wdt-skywise-insight.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'rb-readline'
8
+ gem 'guard'
9
+ gem 'guard-test'
10
+ gem 'guard-minitest'
11
+ gem 'webmock'
12
+ gem 'simplecov', :require => false, :group => :test
13
+ gem 'coveralls', require: false
14
+
15
+ #gem 'activesupport'
16
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 cory
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,85 @@
1
+ # WDT Skywise API
2
+ [![Build Status](https://travis-ci.org/coryp/wdt-skywise-forecast.svg?branch=master)](https://travis-ci.org/coryp/wdt-skywise-forecast)
3
+ [![Coverage Status](https://coveralls.io/repos/github/coryp/wdt-skywise-forecast/badge.svg?branch=master)](https://coveralls.io/github/coryp/wdt-skywise-forecast?branch=master)
4
+
5
+
6
+ Provides an easy-to-use wrapper for the WDT SkyWise Current and Forecast API.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'wdt-skywise-forecast'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install wdt-skywise-forecast
23
+
24
+ ## Usage
25
+
26
+ You will need your API credentials before you start. Sign up for a demo account [here](https://skywise.wdtinc.com/signup?plan_ids[]=2357355853734 "here").
27
+
28
+ First configure your credientials and additional options in `config/initializers/wdt.rb`.
29
+
30
+
31
+ Wdt::Skywise::Forecast::Client.app_id = '<your application id>'
32
+ Wdt::Skywise::Forecast::Client.app_key = '<your application key>'
33
+ Wdt::Skywise::Forecast::Client.units = '<us or all>'
34
+
35
+ Get weather data:
36
+
37
+ wdt_client = Wdt::Skywise::Forecast::Client.new
38
+
39
+ weather_data = wdt_client.weather_for(ZIP: '32128')
40
+
41
+ weather_data.success # returns true
42
+ weather_data.error # returns nil
43
+
44
+ weather_data.response.present? # => true
45
+
46
+ The full structure can be found [here](https://skywise.wdtinc.com/root/mega-docs.html#xml_response "here").
47
+
48
+ ## Example
49
+
50
+ wdt_client = Wdt::Skywise::Forecast::Client.new
51
+ ret = wdt_client.weather_for(ZIP: '32128')
52
+
53
+ if ret.success
54
+ weather_data = ret.response
55
+
56
+ weather_data.language # => "en"
57
+
58
+ # location details
59
+ weather_data.location["@attributes"].city # => "Port Orange"
60
+ weather_data.location["@attributes"].lat # => "29.0905"
61
+
62
+ # current conditions
63
+ weather_data.location.sfc_ob.temp_F # => "78"
64
+ weather_data.location.sfc_ob.wx # => "Mostly clear"
65
+ weather_data.location.sfc_ob.moon_phase # => "Waxing Gibbous Moon"
66
+
67
+ # daily summaries
68
+ weather_data.location.daily_summaries.daily_summary.count # => 10
69
+ weather_data.location.daily_summaries.daily_summary[0].max_temp_F # => "82"
70
+ weather_data.location.daily_summaries.daily_summary[0].wx # => "Partly cloudy"
71
+
72
+ # hourly summaries
73
+ weather_data.location.hourly_summaries.hourly_summary.count # => 240
74
+ weather_data.location.hourly_summaries.hourly_summary[0].temp_F # => "75"
75
+ weather_data.location.hourly_summaries.hourly_summary[0].wx # => "Rain showers"
76
+ else
77
+ puts ret.error
78
+ end
79
+
80
+
81
+
82
+ ## License
83
+
84
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
85
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "wdt/skywise/forecast"
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,7 @@
1
+ module Wdt
2
+ module Skywise
3
+ module Forecast
4
+ VERSION = "0.1.1"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,71 @@
1
+ require "wdt/skywise/forecast/version"
2
+ require 'httparty'
3
+
4
+ module Wdt
5
+ module Skywise
6
+ module Forecast
7
+
8
+ class Response
9
+ attr_accessor :response, :success, :error
10
+
11
+ def initialize(options)
12
+ @response = options[:response]
13
+ @success = options[:success]
14
+ @error = options[:error]
15
+ end
16
+ end
17
+
18
+ class Client
19
+
20
+ include HTTParty
21
+ base_uri "https://skywisefeeds.wdtinc.com"
22
+
23
+ class << self
24
+ attr_accessor :app_id, :app_key, :format, :units
25
+ end
26
+
27
+ def self.base_url
28
+ "https://skywisefeeds.wdtinc.com/feeds/api/mega.php"
29
+ end
30
+
31
+ def weather_for(options)
32
+ # validate parameter combinations
33
+ if options.empty?
34
+ return Wdt::Skywise::Forecast::Response.new({error: "No parameters specified", success: false} )
35
+ end
36
+
37
+ if options.has_key?(:CITY) && ( !options.has_key?(:STATE) && !options.has_key?(:COUNTRY))
38
+ return Wdt::Skywise::Forecast::Response.new({error: "STATE or COUNTRY must be provided with CITY", success: false} )
39
+ end
40
+
41
+ if options.has_key?(:LAT) && !options.has_key?(:LONG)
42
+ return Wdt::Skywise::Forecast::Response.new({error: "LONG must be provided with LAT", success: false} )
43
+ end
44
+
45
+ if options.has_key?(:LONG) && !options.has_key?(:LAT)
46
+ return Wdt::Skywise::Forecast::Response.new({error: "LAT must be provided with LONG", success: false} )
47
+ end
48
+
49
+ # set format and units defaults
50
+ options[:FORMAT] = "json"
51
+ options[:UNITS] = Wdt::Skywise::Forecast::Client.units || "us"
52
+ response = self.class.get("/feeds/api/mega.php", query: options, headers: auth)
53
+
54
+ # make the API call
55
+ if response.code == 200
56
+ response_body = JSON.parse(response.body, object_class: OpenStruct)
57
+ return Wdt::Skywise::Forecast::Response.new({response: response_body, success: true} )
58
+ elsif response.code == 403
59
+ return Wdt::Skywise::Forecast::Response.new({error: "Not Authorized", success: false} )
60
+ end
61
+
62
+ end
63
+
64
+ private
65
+ def auth
66
+ {app_id: Wdt::Skywise::Forecast::Client.app_id, app_key: Wdt::Skywise::Forecast::Client.app_key}
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'wdt/skywise/forecast/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "wdt-skywise-forecast"
8
+ spec.version = Wdt::Skywise::Forecast::VERSION
9
+ spec.authors = ["Cory Patterson"]
10
+ spec.email = ["cory@knockdownoutdoors.com"]
11
+
12
+ spec.summary = %q{Wrapper for the WDT SkyWise Forecast API}
13
+ spec.homepage = "https://github.com/coryp/wdt-skywise-forecast"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against " \
22
+ "public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.13"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "minitest", "~> 5.0"
35
+ spec.add_dependency "httparty", "~> 0.14.0"
36
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wdt-skywise-forecast
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Cory Patterson
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-10-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: httparty
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.14.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.14.0
69
+ description:
70
+ email:
71
+ - cory@knockdownoutdoors.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".ruby-version"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - lib/wdt/skywise/forecast.rb
86
+ - lib/wdt/skywise/forecast/version.rb
87
+ - wdt-skywise-forecast.gemspec
88
+ homepage: https://github.com/coryp/wdt-skywise-forecast
89
+ licenses:
90
+ - MIT
91
+ metadata:
92
+ allowed_push_host: https://rubygems.org
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.5.1
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: Wrapper for the WDT SkyWise Forecast API
113
+ test_files: []