yahoo-se 1.0.7 → 1.0.8

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.
@@ -1,6 +1,12 @@
1
1
  module Yahoo
2
2
  module SE
3
3
  class ApplicationIDNotSet < RuntimeError; end
4
- class RateLimitExceeded < RuntimeError; end
4
+ class ResponseError < RuntimeError
5
+ def initialize(errors)
6
+ title = errors["Title"]
7
+ message = errors["Message"]
8
+ puts "#{title} : #{message}"
9
+ end
10
+ end
5
11
  end
6
12
  end
@@ -3,7 +3,6 @@ module Yahoo
3
3
  class Response
4
4
  def initialize(response_body)
5
5
  @body = response_body
6
- raise RateLimitExceeded unless @body.to_json["Error"].nil?
7
6
  end
8
7
 
9
8
  # The number of URLs returned. This may be lower than the number of results requested if there were fewer total results available.
@@ -18,7 +17,7 @@ module Yahoo
18
17
 
19
18
  # The result objects returned from the request
20
19
  def results
21
- begin
20
+ unless errors
22
21
  if total_results_available == 1
23
22
  [Yahoo::SE::Result.new(self.to_json["ResultSet"]["Result"])]
24
23
  else
@@ -26,8 +25,13 @@ module Yahoo
26
25
  Yahoo::SE::Result.new(result_hash)
27
26
  end
28
27
  end
29
- rescue
30
- []
28
+ end
29
+ end
30
+
31
+ def errors
32
+ @errors = self.to_json["Error"]
33
+ if @errors
34
+ raise ResponseError, @errors
31
35
  end
32
36
  end
33
37
 
@@ -1,5 +1,5 @@
1
1
  module Yahoo
2
2
  module SE
3
- VERSION = "1.0.7" unless defined?(Yahoo::SE::VERSION)
3
+ VERSION = "1.0.8" unless defined?(Yahoo::SE::VERSION)
4
4
  end
5
5
  end
@@ -0,0 +1 @@
1
+ {"Error":{"Title":"The following errors were detected:","Message":["invalid value: request exceeds position 1000"]}}
@@ -1 +1 @@
1
- {"Error":{"Message":"limit exceeded"}}
1
+ {"Error":{"Title":"The following errors were detected:","Message":["limit exceeded"]}}
@@ -10,6 +10,7 @@ describe Yahoo::SE::Request do
10
10
  describe "instances" do
11
11
  before do
12
12
  Yahoo::SE.application_id = "123"
13
+ Yahoo::SE::Request.stub!(:hash_to_query).and_return("appid=123&query=http://erbmicha.com&output=json")
13
14
  @result = mock(Yahoo::SE::Result)
14
15
  @il_request = Yahoo::SE::Request.new(Yahoo::SE::Inlinks::SERVICE_PATH, :query => "http://erbmicha.com")
15
16
  @pages_request = Yahoo::SE::Request.new(Yahoo::SE::Pages::SERVICE_PATH, :query => "http://erbmicha.com")
@@ -28,23 +29,23 @@ describe Yahoo::SE::Request do
28
29
 
29
30
  it "should form a valid request to inlink data" do
30
31
  Yahoo::SE::Result.should_receive(:new).exactly(100).times.and_return(@result)
31
- @il_request.should_receive("open").with("http://search.yahooapis.com/SiteExplorerService/V1/inlinkData?appid=123&query=http://erbmicha.com&output=json").and_return(@json_bl_file)
32
+ @il_request.should_receive("open").with("http://search.yahooapis.com/SiteExplorerService/V1/inlinkData?appid=123&query=http://erbmicha.com&output=json", {"User-Agent"=>"Ruby/Yahoo Site Explorer Gem vV1"}).and_return(@json_bl_file)
32
33
  @il_request.results.size.should == 100
33
34
  end
34
35
 
35
36
  it "should form a valid request to page data" do
36
37
  Yahoo::SE::Result.should_receive(:new).exactly(50).times.and_return(@result)
37
- @pages_request.should_receive("open").with("http://search.yahooapis.com/SiteExplorerService/V1/pageData?appid=123&query=http://erbmicha.com&output=json").and_return(@json_pages_file)
38
+ @pages_request.should_receive("open").with("http://search.yahooapis.com/SiteExplorerService/V1/pageData?appid=123&query=http://erbmicha.com&output=json", {"User-Agent"=>"Ruby/Yahoo Site Explorer Gem vV1"}).and_return(@json_pages_file)
38
39
  @pages_request.results.size.should == 50
39
40
  end
40
41
 
41
42
  it "should form a valid request to ping a site" do
42
- @ping_request.should_receive("open").with("http://search.yahooapis.com/SiteExplorerService/V1/ping?appid=123&sitemap=http://erbmicha.com&output=json").and_return(@json_ping_file)
43
+ @ping_request.should_receive("open").with("http://search.yahooapis.com/SiteExplorerService/V1/ping?appid=123&query=http://erbmicha.com&output=json", {"User-Agent"=>"Ruby/Yahoo Site Explorer Gem vV1"}).and_return(@json_ping_file)
43
44
  @ping_request.response
44
45
  end
45
46
 
46
47
  it "should form a valid request to the update notification service" do
47
- @update_notification_request.should_receive("open").with("http://search.yahooapis.com/SiteExplorerService/V1/updateNotification?appid=123&url=http://erbmicha.com&output=json").and_return(@json_ping_file)
48
+ @update_notification_request.should_receive("open").with("http://search.yahooapis.com/SiteExplorerService/V1/updateNotification?appid=123&query=http://erbmicha.com&output=json", {"User-Agent"=>"Ruby/Yahoo Site Explorer Gem vV1"}).and_return(@json_ping_file)
48
49
  @update_notification_request.response
49
50
  end
50
51
  end
@@ -17,7 +17,10 @@ describe Yahoo::SE::Response do
17
17
  @response.total_results_available.should == 328
18
18
  end
19
19
 
20
- it "should raise RateLimitExceeded when there are too many requests" do
21
- lambda {Yahoo::SE::Response.new(fixture("rate_limit_exceeded.json"))}.should raise_error(Yahoo::SE::RateLimitExceeded)
20
+ describe "Errors" do
21
+ it "should raise an exception if the response is a exceed error" do
22
+ @response = Yahoo::SE::Response.new(fixture("exceed_error.json"))
23
+ lambda { @response.results }.should raise_error(Yahoo::SE::ResponseError)
24
+ end
22
25
  end
23
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yahoo-se
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
4
+ version: 1.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lance Carlson
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-04 00:00:00 -05:00
12
+ date: 2008-12-08 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -59,6 +59,7 @@ files:
59
59
  - spec/fixtures/erbmicha.com_backlinks.json
60
60
  - spec/fixtures/erbmicha.com_pages.json
61
61
  - spec/fixtures/erbmicha.com_ping.json
62
+ - spec/fixtures/exceed_error.json
62
63
  - spec/fixtures/rate_limit_exceeded.json
63
64
  - spec/spec.opts
64
65
  - spec/spec_helper.rb