yahoo_weatherman 1.2.0 → 1.2.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.
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
|
3
|
+
module Weatherman
|
4
|
+
class WoeidLookup
|
5
|
+
|
6
|
+
def initialize(app_id)
|
7
|
+
@app_id = app_id
|
8
|
+
end
|
9
|
+
|
10
|
+
def get_woeid(location)
|
11
|
+
raw = get query_string(location)
|
12
|
+
Nokogiri::HTML(raw).at_xpath('.//woeid').content
|
13
|
+
rescue
|
14
|
+
nil
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def query_string(location)
|
20
|
+
"http://where.yahooapis.com/v1/places.q('#{::CGI.escape(location)}')?appid=#{@app_id}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def get(url)
|
24
|
+
open(url).read
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
data/lib/yahoo_weatherman.rb
CHANGED
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
Dir[File.dirname(__FILE__) + '/directory/*.rb'].each {|file| require file }
|
3
|
+
|
4
|
+
describe Weatherman::WoeidLookup do
|
5
|
+
describe "example with test_api_id and 66061" do
|
6
|
+
before do
|
7
|
+
@app_id = 'test_api_id'
|
8
|
+
@location = '66061'
|
9
|
+
@lookup = Weatherman::WoeidLookup.new(@app_id)
|
10
|
+
|
11
|
+
xml_result = WoeidHelper.open_test_file('woeid_result_that_returns_12786745')
|
12
|
+
WoeidHelper.register_this_woeid_lookup_result(xml_result, @app_id, @location)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should retrieve the woeid" do
|
16
|
+
response = @lookup.get_woeid(@location)
|
17
|
+
response.should == "12786745"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "example with another_api and 90210" do
|
22
|
+
before do
|
23
|
+
@app_id = 'another_api'
|
24
|
+
@location = '90210'
|
25
|
+
@lookup = Weatherman::WoeidLookup.new(@app_id)
|
26
|
+
|
27
|
+
xml_result = WoeidHelper.open_test_file('woeid_result_that_returns_4729347')
|
28
|
+
WoeidHelper.register_this_woeid_lookup_result(xml_result, @app_id, @location)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should retrieve the woeid" do
|
32
|
+
response = @lookup.get_woeid(@location)
|
33
|
+
response.should == "4729347"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "invalid api key" do
|
38
|
+
before do
|
39
|
+
@app_id = 'invalid_api'
|
40
|
+
@location = '12345'
|
41
|
+
@lookup = Weatherman::WoeidLookup.new(@app_id)
|
42
|
+
|
43
|
+
xml_result = WoeidHelper.open_test_file('woeid_result_for_invalid_app_id')
|
44
|
+
WoeidHelper.register_this_woeid_lookup_result(xml_result, @app_id, @location)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should return nil" do
|
48
|
+
response = @lookup.get_woeid(@location)
|
49
|
+
response.should == nil
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "failed net request" do
|
54
|
+
before do
|
55
|
+
@app_id = 'net_failure'
|
56
|
+
@location = '78902'
|
57
|
+
@lookup = Weatherman::WoeidLookup.new(@app_id)
|
58
|
+
WoeidHelper.register_this_woeid_lookup_to_fail @app_id, @location
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should return nil" do
|
62
|
+
response = @lookup.get_woeid(@location)
|
63
|
+
response.should == nil
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "request with spaces" do
|
68
|
+
before do
|
69
|
+
@app_id = 'test_api_id'
|
70
|
+
@lookup = Weatherman::WoeidLookup.new(@app_id)
|
71
|
+
|
72
|
+
xml_result = WoeidHelper.open_test_file('woeid_result_that_returns_12786745')
|
73
|
+
WoeidHelper.register_this_woeid_lookup_result(xml_result, @app_id, "San+Francisco%2C+CA")
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should retrieve the woeid" do
|
77
|
+
response = @lookup.get_woeid("San Francisco, CA")
|
78
|
+
response.should == "12786745"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
data/yahoo_weatherman.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |gem|
|
2
2
|
gem.name = "yahoo_weatherman"
|
3
|
-
gem.version = "1.2.
|
3
|
+
gem.version = "1.2.1"
|
4
4
|
gem.authors = ["Dalto Curvelano Junior"]
|
5
5
|
gem.description = "A ruby wrapper to the Yahoo! Weather feed with i18n support."
|
6
6
|
gem.summary = "A ruby wrapper to the Yahoo! Weather feed with i18n support."
|
@@ -9,6 +9,7 @@ Gem::Specification.new do |gem|
|
|
9
9
|
"lib/yahoo_weatherman/image.rb",
|
10
10
|
"lib/yahoo_weatherman/response.rb",
|
11
11
|
"lib/yahoo_weatherman/i18n.rb",
|
12
|
+
"lib/yahoo_weatherman/woeid_lookup.rb",
|
12
13
|
"lib/yahoo_weatherman.rb",
|
13
14
|
"i18n/pt-br.yml",
|
14
15
|
"i18n/ru.yml",
|
@@ -17,7 +18,8 @@ Gem::Specification.new do |gem|
|
|
17
18
|
"spec/spec_helper.rb",
|
18
19
|
"spec/yahoo_weatherman/response_spec.rb",
|
19
20
|
"spec/yahoo_weatherman/yahoo_weatherman_spec.rb",
|
20
|
-
"spec/yahoo_weatherman/i18n_spec.rb"
|
21
|
+
"spec/yahoo_weatherman/i18n_spec.rb",
|
22
|
+
"spec/yahoo_weatherman/woeid_lookup_spec.rb"
|
21
23
|
]
|
22
24
|
gem.homepage = "http://github.com/dlt/yahoo_weatherman"
|
23
25
|
gem.add_dependency "nokogiri"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yahoo_weatherman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
@@ -69,6 +69,7 @@ files:
|
|
69
69
|
- lib/yahoo_weatherman/image.rb
|
70
70
|
- lib/yahoo_weatherman/response.rb
|
71
71
|
- lib/yahoo_weatherman/i18n.rb
|
72
|
+
- lib/yahoo_weatherman/woeid_lookup.rb
|
72
73
|
- lib/yahoo_weatherman.rb
|
73
74
|
- i18n/pt-br.yml
|
74
75
|
- i18n/ru.yml
|
@@ -78,6 +79,7 @@ files:
|
|
78
79
|
- spec/yahoo_weatherman/response_spec.rb
|
79
80
|
- spec/yahoo_weatherman/yahoo_weatherman_spec.rb
|
80
81
|
- spec/yahoo_weatherman/i18n_spec.rb
|
82
|
+
- spec/yahoo_weatherman/woeid_lookup_spec.rb
|
81
83
|
homepage: http://github.com/dlt/yahoo_weatherman
|
82
84
|
licenses: []
|
83
85
|
post_install_message:
|