powered_wunderground 0.0.2

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bb2668ca0a35f6f0f670ca6db9f6ca8315e8cc27
4
+ data.tar.gz: d24585de0a8b25a48df6336f3bdd0ca2b8cbd820
5
+ SHA512:
6
+ metadata.gz: 449f8cc9df8c3ab1932a73bf3ce054c60564eca5bcff5dd21e247ec8ddf9e0c707c1e76c711a4a11bb9e9b967c6d4351d9209f896052d03fdd7003782d9f595c
7
+ data.tar.gz: 79028eeb10d2efcc211ae1efb3a0966a50a6c42b175a71a66d960f13eff685995526e07e56b9e8ce97e21c70ea6a65effa6e030c0188c0f32775acfbbdcd2b43
@@ -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
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in powered_wunderground.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Daniel Carneiro
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
+
@@ -0,0 +1,68 @@
1
+ # PoweredWunderground
2
+
3
+ This gem is based on wnadeau wunderlust gem: https://github.com/wnadeau/wunderground. Since I had different needs for the API (tts friendly forecast descriptions) that would change the scope of the wunderlust gem. I decided to create this one.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'powered_wunderground'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install powered_wunderground
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ PoweredWunderground.new(api_key: 'your_api_key', language: 'pt').forecast('pt', 'porto')
25
+ => "Nublado. Máxima de 21°C. Ventos O a 10 a 15 km/h."
26
+ PoweredWunderground.new(api_key: '84ba182600b17c03', language: 'fr').forecast('pt', 'porto')
27
+ => "Nuageux. Maximales : 21 ºC. Vents O soufflant de 10 à 15 km/h."
28
+ ```
29
+
30
+ next steps: buff the forecast reply
31
+
32
+ ## Development
33
+
34
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
35
+
36
+ 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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
37
+
38
+ ## Contributing
39
+
40
+ 1. Fork it ( https://github.com/dcarneiro/powered_wunderground/fork )
41
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
42
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
43
+ 4. Push to the branch (`git push origin my-new-feature`)
44
+ 5. Create a new Pull Request
45
+
46
+ ## LICENSE:
47
+
48
+ The MIT License (MIT)
49
+
50
+ Copyright (c) 2015 Daniel Carneiro
51
+
52
+ Permission is hereby granted, free of charge, to any person obtaining a copy
53
+ of this software and associated documentation files (the "Software"), to deal
54
+ in the Software without restriction, including without limitation the rights
55
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
56
+ copies of the Software, and to permit persons to whom the Software is
57
+ furnished to do so, subject to the following conditions:
58
+
59
+ The above copyright notice and this permission notice shall be included in all
60
+ copies or substantial portions of the Software.
61
+
62
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
63
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
64
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
65
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
66
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
67
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
68
+ SOFTWARE.
@@ -0,0 +1,8 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.test_files = FileList['test/**/*_test.rb']
6
+ end
7
+
8
+ task default: :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'powered_wunderground'
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
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
1
+ require 'powered_wunderground/version'
2
+ require 'powered_wunderground/connection'
3
+
4
+ module PoweredWunderground
5
+ class << self
6
+
7
+ def new(args)
8
+ extra_params = {}
9
+
10
+ if args.is_a?(String)
11
+ start_conection_by_api_key(args)
12
+ else
13
+ start_conection_by_hash(args)
14
+ end
15
+ end
16
+
17
+ def start_conection_by_api_key(api_key)
18
+ PoweredWunderground::Connection.new(api_key)
19
+ end
20
+
21
+ def start_conection_by_hash(hash)
22
+ api_key = hash[:api_key]
23
+ fail "invalid api key #{api_key}" if api_key.nil?
24
+ conn = PoweredWunderground::Connection.new(api_key)
25
+ conn.language = hash[:language] if hash[:language]
26
+ conn
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,40 @@
1
+ require 'powered_wunderground/language_mapper'
2
+
3
+ module PoweredWunderground
4
+ class Connection
5
+ include LanguageMapper
6
+
7
+ attr_reader :api_key
8
+ attr_accessor :language
9
+
10
+ def initialize(api_key)
11
+ @api_key = api_key
12
+ @language = 'en'
13
+ end
14
+
15
+ def base_api_url
16
+ "http://api.wunderground.com/api/#{api_key}/"
17
+ end
18
+
19
+ def forecast(country, city)
20
+ wunderground_response = wunderground_forecast(country, city)
21
+ wunderground_response['forecast']['txt_forecast']['forecastday'].first['fcttext_metric']
22
+ end
23
+
24
+ def language
25
+ @language || 'EN'
26
+ end
27
+
28
+ def language=(code)
29
+ @language = fetch_language(code)
30
+ end
31
+
32
+ private
33
+
34
+ def wunderground_forecast(country, city)
35
+ conn = Faraday.new(url: base_api_url)
36
+ response = conn.get "forecast/lang:#{language}/q/#{country}/#{city}.json"
37
+ JSON.parse response.body
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,13 @@
1
+ module PoweredWunderground
2
+ module LanguageMapper
3
+ def fetch_language(code)
4
+ language_map[code.upcase] || code.upcase
5
+ end
6
+
7
+ def language_map
8
+ {
9
+ 'PT' => 'BR', # this makes me sad
10
+ }
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module PoweredWunderground
2
+ VERSION = '0.0.2'
3
+ end
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'powered_wunderground/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'powered_wunderground'
8
+ s.version = PoweredWunderground::VERSION
9
+ s.authors = ['Daniel Carneiro']
10
+ s.email = ['danielrcarneiro@gmail.com']
11
+
12
+ s.summary = 'Wunderground API wrapper on steroids'
13
+ s.homepage = 'https://github.com/dcarneiro/powered_wunderground'
14
+
15
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
16
+ # delete this section to allow pushing this gem to any host.
17
+ # if s.respond_to?(:metadata)
18
+ # s.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
19
+ # else
20
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
21
+ # end
22
+
23
+ s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ s.bindir = 'exe'
25
+ s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ s.require_paths = ['lib']
27
+
28
+ s.add_development_dependency 'minitest'
29
+ s.add_development_dependency 'minitest-reporters'
30
+
31
+ s.add_development_dependency 'bundler', '~> 1.9'
32
+ s.add_development_dependency 'rake', '~> 10.0'
33
+ s.add_development_dependency 'pry-byebug'
34
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: powered_wunderground
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Carneiro
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-06-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest-reporters
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.9'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.9'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - danielrcarneiro@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - LICENSE
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - lib/powered_wunderground.rb
100
+ - lib/powered_wunderground/connection.rb
101
+ - lib/powered_wunderground/language_mapper.rb
102
+ - lib/powered_wunderground/version.rb
103
+ - powered_wunderground.gemspec
104
+ homepage: https://github.com/dcarneiro/powered_wunderground
105
+ licenses: []
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.4.8
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Wunderground API wrapper on steroids
127
+ test_files: []