yahoo_weatherman 1.1.5 → 1.2.0

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.
@@ -8,11 +8,12 @@ require 'nokogiri'
8
8
 
9
9
  require 'yahoo_weatherman/i18n'
10
10
  require 'yahoo_weatherman/image'
11
+ require 'yahoo_weatherman/woeid_lookup'
11
12
  require 'yahoo_weatherman/response'
12
13
 
13
14
  module Weatherman
14
15
 
15
- VERSION = '1.1.5'
16
+ VERSION = '1.2.0'
16
17
 
17
18
  URI = 'http://weather.yahooapis.com/forecastrss'
18
19
 
@@ -34,19 +35,31 @@ module Weatherman
34
35
  #
35
36
  # +lang+: the language used in the response
36
37
  #
38
+ # +app_id+: your yahoo app id (necessary for searching by location).
39
+ #
37
40
  def initialize(options = {})
38
41
  @options = options
39
42
  @uri = options[:url] || URI
43
+ @app_id = options[:app_id]
40
44
  end
41
45
 
42
46
  #
43
- # Just pass in a +woeid+ and it will return a Weatherman::Response object:w
47
+ # Looks up weather by woeid.
44
48
  #
45
49
  def lookup_by_woeid(woeid)
46
50
  raw = get request_url(woeid)
47
51
  Response.new(raw, options[:lang])
48
52
  end
49
53
 
54
+ #
55
+ # Looks up weather by location.
56
+ #
57
+ def lookup_by_location(location)
58
+ lookup = WoeidLookup.new(@app_id)
59
+ woeid = lookup.get_woeid(location)
60
+ lookup_by_woeid(woeid)
61
+ end
62
+
50
63
  private
51
64
  def request_url(woeid)
52
65
  @uri + query_string(woeid)
data/spec/spec_helper.rb CHANGED
@@ -19,6 +19,9 @@ end
19
19
  FakeWeb.allow_net_connect = false
20
20
  FakeWeb.register_uri(:get, "http://weather.yahooapis.com/forecastrss?w=455821&u=c", :body => celsius_fixture)
21
21
  FakeWeb.register_uri(:get, "http://weather.yahooapis.com/forecastrss?w=455821&u=f", :body => fahrenheight_fixture)
22
+ FakeWeb.register_uri(:get, "http://weather.yahooapis.com/forecastrss?w=123456&u=f", :body => celsius_fixture)
23
+ FakeWeb.register_uri(:get, "http://weather.yahooapis.com/forecastrss?w=4729347&u=c", :body => celsius_fixture)
24
+ FakeWeb.register_uri(:get, "http://weather.yahooapis.com/forecastrss?w=12786745&u=c", :body => celsius_fixture)
22
25
 
23
26
  module YAML
24
27
  class << self
@@ -34,3 +37,17 @@ module YAML
34
37
 
35
38
  end
36
39
  end
40
+
41
+ module WoeidHelper
42
+ def self.open_test_file(file)
43
+ File.open(File.dirname(__FILE__) + "/files/#{file}.xml").read
44
+ end
45
+
46
+ def self.register_this_woeid_lookup_result(result, app_id, location)
47
+ FakeWeb.register_uri(:get, "http://where.yahooapis.com/v1/places.q('#{location}')?appid=#{app_id}", :body => result)
48
+ end
49
+
50
+ def self.register_this_woeid_lookup_to_fail(app_id, location)
51
+ FakeWeb.register_uri(:get, "http://where.yahooapis.com/v1/places.q('#{location}')?appid=#{app_id}", :exception => Net::HTTPError)
52
+ end
53
+ end
@@ -1,13 +1,47 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Weatherman::Client do
4
- before do
5
- @client = Weatherman::Client.new
4
+ describe "#lookup_by_woeid" do
5
+ before do
6
+ @client = Weatherman::Client.new
7
+ end
8
+
9
+ it 'should lookup by woeid' do
10
+ response = @client.lookup_by_woeid 455821
11
+ response.should be_instance_of(Weatherman::Response)
12
+ end
6
13
  end
7
14
 
8
- it 'should lookup by woeid' do
9
- response = @client.lookup_by_woeid 455821
10
- response.should be_instance_of(Weatherman::Response)
15
+ describe "#lookup_by_location" do
16
+ describe "4729347 example" do
17
+ it "should lookup by location" do
18
+ app_id = 'test_id'
19
+ location = '78923'
20
+
21
+ xml_result = WoeidHelper.open_test_file 'woeid_result_that_returns_4729347'
22
+ WoeidHelper.register_this_woeid_lookup_result xml_result, app_id, location
23
+
24
+ @client = Weatherman::Client.new( { :app_id => app_id } )
25
+ response = @client.lookup_by_location location
26
+
27
+ response.should be_instance_of(Weatherman::Response)
28
+ end
29
+ end
30
+
31
+ describe "12786745 example" do
32
+ it "should lookup by location" do
33
+ app_id = 'apple'
34
+ location = 'orange'
35
+
36
+ xml_result = WoeidHelper.open_test_file 'woeid_result_that_returns_12786745'
37
+ WoeidHelper.register_this_woeid_lookup_result xml_result, app_id, location
38
+
39
+ @client = Weatherman::Client.new( { :app_id => app_id } )
40
+ response = @client.lookup_by_location location
41
+
42
+ response.should be_instance_of(Weatherman::Response)
43
+ end
44
+ end
11
45
  end
12
46
 
13
47
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = "yahoo_weatherman"
3
- gem.version = "1.1.5"
3
+ gem.version = "1.2.0"
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."
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.1.5
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-28 00:00:00.000000000 Z
12
+ date: 2012-10-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
16
- requirement: &20671160 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *20671160
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: rspec
27
- requirement: &20670580 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '0'
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *20670580
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: fakeweb
38
- requirement: &20670040 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,7 +53,12 @@ dependencies:
43
53
  version: '0'
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *20670040
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  description: A ruby wrapper to the Yahoo! Weather feed with i18n support.
48
63
  email:
49
64
  executables: []
@@ -83,8 +98,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
98
  version: '0'
84
99
  requirements: []
85
100
  rubyforge_project:
86
- rubygems_version: 1.8.17
101
+ rubygems_version: 1.8.23
87
102
  signing_key:
88
103
  specification_version: 3
89
104
  summary: A ruby wrapper to the Yahoo! Weather feed with i18n support.
90
105
  test_files: []
106
+ has_rdoc: