yahoo_web_api 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
@@ -36,8 +36,12 @@ class ImageSearchService
|
|
36
36
|
def image_search(params)
|
37
37
|
params = @parameters.merge(params)
|
38
38
|
res = post(params)
|
39
|
-
|
40
|
-
|
39
|
+
if res.code == '200'
|
40
|
+
results = self.class.parse(res.body.to_s)
|
41
|
+
return results
|
42
|
+
else
|
43
|
+
raise Exception, Nokogiri::XML(res.body).css('Error Message').inner_text
|
44
|
+
end
|
41
45
|
end
|
42
46
|
|
43
47
|
private
|
@@ -14,7 +14,7 @@ describe ImageSearchService do
|
|
14
14
|
File.dirname(__FILE__), 'image_search_sample.xml'))
|
15
15
|
body = nil
|
16
16
|
File.open(path, 'r') {|f| body = f.read }
|
17
|
-
response = mock(Object.new, :body => body)
|
17
|
+
response = mock(Object.new, :code => '200', :body => body)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
subject {@image_search_service.image_search(:query => '沖縄')}
|
@@ -26,6 +26,45 @@ describe ImageSearchService do
|
|
26
26
|
subject {@image_search_service.image_search(:query => '沖縄')[0]}
|
27
27
|
its(:url) { should eql 'http://photohito.com/uploads/photo3/user2168/17b2408c4590448d93f59b95336f8ecb/17b2408c4590448d93f59b95336f8ecb_l.jpg'}
|
28
28
|
its(:referer_url) { should eql 'http://photohito.com/photo/229218/' }
|
29
|
+
|
30
|
+
context "for Object containing thumbnail information" do
|
31
|
+
before do
|
32
|
+
@result = @image_search_service.image_search(:query => '沖縄')[0]
|
33
|
+
end
|
34
|
+
subject {@result.thumbnail}
|
35
|
+
its(:url) { should eql 'http://isearch.c.yimg.jp/image?id=1e86b3e062dd1dc8dbb2f228c49e10cd'}
|
36
|
+
its(:width) { should eql '127' }
|
37
|
+
its(:height) { should eql '170' }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context "When #image_search received an error response" do
|
43
|
+
before do
|
44
|
+
@image_search_service = ImageSearchService.new(
|
45
|
+
:appid => 'test_appid')
|
46
|
+
error_response = mock(Object.new,
|
47
|
+
:code => '400',
|
48
|
+
:body => <<-BODY)
|
49
|
+
<?xml version="1.0" encoding="utf-8"?>
|
50
|
+
<Error>
|
51
|
+
<Message>error message</Message>
|
52
|
+
</Error>
|
53
|
+
BODY
|
54
|
+
@image_search_service.stub!(:post).and_return do
|
55
|
+
mock(Object.new, :code => '400',
|
56
|
+
:body => <<-BODY)
|
57
|
+
<?xml version="1.0" encoding="utf-8"?>
|
58
|
+
<Error>
|
59
|
+
<Message>error message</Message>
|
60
|
+
</Error>
|
61
|
+
BODY
|
62
|
+
end
|
63
|
+
end
|
64
|
+
it do
|
65
|
+
lambda do
|
66
|
+
@image_search_service.image_search(:query => 'hoge')
|
67
|
+
end.should raise_error(Exception, 'error message')
|
29
68
|
end
|
30
69
|
end
|
31
70
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: yahoo_web_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Tatsuya Sato
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-02-
|
13
|
+
date: 2011-02-17 00:00:00 +09:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|
@@ -44,7 +44,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 1.
|
47
|
+
version: 1.8.7
|
48
48
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|