yahoo 1.0.0 → 1.1.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.
@@ -4,4 +4,3 @@ README
4
4
  Rakefile
5
5
  lib/yahoo.rb
6
6
  test/test_yahoo.rb
7
- test/uri_stub.rb
data/Rakefile CHANGED
@@ -8,7 +8,7 @@ $VERBOSE = nil
8
8
 
9
9
  spec = Gem::Specification.new do |s|
10
10
  s.name = 'yahoo'
11
- s.version = '1.0.0'
11
+ s.version = '1.1.0'
12
12
  s.summary = 'Base for Yahoo web services'
13
13
  s.description = 'This library makes it easy to implement Yahoo\'s web services APIs.'
14
14
  s.author = 'Eric Hodel'
@@ -17,6 +17,8 @@ spec = Gem::Specification.new do |s|
17
17
  s.has_rdoc = true
18
18
  s.files = File.read('Manifest.txt').split($/)
19
19
  s.require_path = 'lib'
20
+
21
+ s.add_dependency 'rc-rest', '>= 1.0.0'
20
22
  end
21
23
 
22
24
  desc 'Run tests'
@@ -24,6 +26,7 @@ task :default => [ :test ]
24
26
 
25
27
  Rake::TestTask.new('test') do |t|
26
28
  t.libs << 'test'
29
+ t.libs << '../rc-rest/lib'
27
30
  t.pattern = 'test/test_*.rb'
28
31
  t.verbose = true
29
32
  end
@@ -1,17 +1,16 @@
1
- require 'open-uri'
2
- require 'rexml/document'
1
+ require 'rc_rest'
3
2
 
4
3
  ##
5
4
  # Abstract class for implementing Yahoo APIs.
6
5
  #
7
6
  # http://developer.yahoo.com/
8
7
 
9
- class Yahoo
8
+ class Yahoo < RCRest
10
9
 
11
10
  ##
12
11
  # Yahoo error class.
13
12
 
14
- class Error < RuntimeError; end
13
+ class Error < RCRest::Error; end
15
14
 
16
15
  ##
17
16
  # Web services initializer.
@@ -35,36 +34,13 @@ class Yahoo
35
34
  end
36
35
 
37
36
  ##
38
- # Extracts and raises an error from +obj+. Returns if no error could be
39
- # found.
37
+ # Extracts and raises an error from +xml+, if any.
40
38
 
41
- def check_error(obj)
42
- obj = REXML::Document.new obj.read unless REXML::Document === obj
43
-
44
- err = obj.elements['Error']
39
+ def check_error(xml)
40
+ err = xml.elements['Error']
45
41
  raise Error, err.elements['Message'].text if err
46
42
  end
47
43
 
48
- ##
49
- # Performs a GET request with +params+. Calls the parse_response method on
50
- # the concrete class with an REXML::Document instance and returns its
51
- # result.
52
-
53
- def get(params)
54
- url = make_url params
55
-
56
- url.open do |xml|
57
- res = REXML::Document.new xml.read
58
-
59
- check_error res
60
-
61
- return parse_response(res)
62
- end
63
- rescue OpenURI::HTTPError => e
64
- check_error e.io
65
- raise
66
- end
67
-
68
44
  ##
69
45
  # Creates a URL from the Hash +params+. Automatically adds the appid and
70
46
  # sets the output type to 'xml'.
@@ -73,13 +49,7 @@ class Yahoo
73
49
  params[:appid] = @appid
74
50
  params[:output] = 'xml'
75
51
 
76
- escaped_params = params.sort_by { |k,v| k.to_s }.map do |k,v|
77
- "#{URI.escape k.to_s}=#{URI.escape v.to_s}"
78
- end
79
-
80
- url = @url.dup
81
- url.query = escaped_params.join '&'
82
- return url
52
+ super params
83
53
  end
84
54
 
85
55
  end
@@ -1,5 +1,5 @@
1
1
  require 'test/unit'
2
- require 'test/uri_stub'
2
+ require 'rc_rest/uri_stub'
3
3
  require 'yahoo'
4
4
 
5
5
  class Yahoo::Test < Yahoo
@@ -31,18 +31,7 @@ class TestYahoo < Test::Unit::TestCase
31
31
  @t = Yahoo::Test.new 'APP_ID'
32
32
  end
33
33
 
34
- def test_check_error_IO
35
- io = StringIO.new '<Error><Message>you broked it</Message></Error>'
36
- @t.check_error io
37
-
38
- rescue Yahoo::Error => e
39
- assert_equal 'you broked it', e.message
40
-
41
- else
42
- flunk 'expected an error'
43
- end
44
-
45
- def test_check_error_REXML__Document
34
+ def test_check_error
46
35
  xml = REXML::Document.new '<Error><Message>you broked it</Message></Error>'
47
36
  @t.check_error xml
48
37
 
@@ -53,38 +42,10 @@ class TestYahoo < Test::Unit::TestCase
53
42
  flunk 'expected an error'
54
43
  end
55
44
 
56
- def test_get
57
- xml = '<Result>stuff</Result>'
58
- URI::HTTP.responses << xml
59
-
60
- result = @t.test
61
-
62
- assert_equal xml, result.to_s
63
- end
64
-
65
- def test_get_error
66
- def @t.make_url(*args) # HACK extend uri_stub with error raising ability
67
- u = Object.new
68
- def u.open
69
- xml = '<Error><Message>you did the bad thing</Message></Error>'
70
- raise OpenURI::HTTPError.new('400 Bad Request', StringIO.new(xml))
71
- end
72
- return u
73
- end
74
-
75
- assert_raise Yahoo::Error do @t.test end
76
- end
77
-
78
- def test_initialize
79
- assert_equal 'http://api.test.yahoo.com/TestService/Vtest/test',
80
- @t.instance_variable_get(:@url).to_s
81
- end
82
-
83
45
  def test_make_url
84
- url = @t.make_url :test_param_1 => 'test test',
85
- :test_param_2 => 'tset tset'
46
+ url = @t.make_url :param => 'value'
86
47
 
87
- expected = 'http://api.test.yahoo.com/TestService/Vtest/test?appid=APP_ID&output=xml&test_param_1=test%20test&test_param_2=tset%20tset'
48
+ expected = 'http://api.test.yahoo.com/TestService/Vtest/test?appid=APP_ID&output=xml&param=value'
88
49
 
89
50
  assert_equal expected, url.to_s
90
51
  end
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.11.15
2
+ rubygems_version: 0.8.99
3
3
  specification_version: 1
4
4
  name: yahoo
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.0.0
7
- date: 2006-06-10 00:00:00 -07:00
6
+ version: 1.1.0
7
+ date: 2006-06-16 00:00:00 -07:00
8
8
  summary: Base for Yahoo web services
9
9
  require_paths:
10
10
  - lib
@@ -35,7 +35,6 @@ files:
35
35
  - Rakefile
36
36
  - lib/yahoo.rb
37
37
  - test/test_yahoo.rb
38
- - test/uri_stub.rb
39
38
  test_files: []
40
39
 
41
40
  rdoc_options: []
@@ -48,5 +47,13 @@ extensions: []
48
47
 
49
48
  requirements: []
50
49
 
51
- dependencies: []
52
-
50
+ dependencies:
51
+ - !ruby/object:Gem::Dependency
52
+ name: rc-rest
53
+ version_requirement:
54
+ version_requirements: !ruby/object:Gem::Version::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: 1.0.0
59
+ version:
@@ -1,17 +0,0 @@
1
- require 'open-uri'
2
-
3
- class URI::HTTP
4
-
5
- class << self
6
- attr_accessor :responses, :uris
7
- end
8
-
9
- alias original_open open
10
-
11
- def open
12
- self.class.uris << self.to_s
13
- yield StringIO.new(self.class.responses.shift)
14
- end
15
-
16
- end
17
-