yahoo_site_explorer 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Nathaniel Bibler
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,30 @@
1
+ = Yahoo! Site Explorer
2
+
3
+ The Yahoo! Site Explorer service provides access to Yahoo!'s information about web pages. The service stores information about links between web pages and and can gauge the popularity of a given page.
4
+
5
+ == Installation
6
+
7
+ To install, simply:
8
+
9
+ gem install site-explorer
10
+
11
+
12
+ == Example
13
+
14
+ The following example queries Yahoo! Site Explorer for the number of inlinks (backlinks) for www.google.com:
15
+
16
+ require 'yahoo_site_explorer'
17
+
18
+ service = YahooSiteExplorer.new('myapikey')
19
+ results = service.backlinks('http://www.google.com')
20
+ puts results.total_results #=> 941822
21
+
22
+ == Caveats
23
+
24
+ Currently, this library only implements the inlinksData, totalResultsAvailable, as that is the only data I need. I'll extend this to fully support the API, shortly.
25
+
26
+ == Copyright
27
+
28
+ Yahoo! Site Explorer is owned, operated, and copyrighted (c) by Yahoo Inc.
29
+
30
+ Copyright (c) 2009 Nathaniel Bibler. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,64 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "yahoo_site_explorer"
8
+ gem.summary = %Q{Ruby interface to the Yahoo! Site Explorer REST API}
9
+ gem.email = "gem@nathanielbibler.com"
10
+ gem.homepage = "http://github.com/nbibler/yahoo_site_explorer"
11
+ gem.authors = ["Nathaniel Bibler"]
12
+ gem.rubyforge_project = "site-explorer"
13
+
14
+ gem.add_dependency('relax', '~> 0.1.1')
15
+
16
+ gem.add_development_dependency('jeweler', '~> 0.11.0')
17
+ gem.add_development_dependency('mocha', '~> 0.9.5')
18
+ gem.add_development_dependency('thoughtbot-shoulda', '~> 2.10.1')
19
+ gem.add_development_dependency('fakeweb', '~> 1.2.2')
20
+ end
21
+
22
+ Jeweler::RubyforgeTasks.new
23
+ rescue LoadError
24
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
25
+ end
26
+
27
+ require 'rake/testtask'
28
+ Rake::TestTask.new(:test) do |test|
29
+ test.libs << 'lib' << 'test'
30
+ test.pattern = 'test/**/*_test.rb'
31
+ test.verbose = true
32
+ end
33
+
34
+ begin
35
+ require 'rcov/rcovtask'
36
+ Rcov::RcovTask.new do |test|
37
+ test.libs << 'test'
38
+ test.pattern = 'test/**/*_test.rb'
39
+ test.verbose = true
40
+ end
41
+ rescue LoadError
42
+ task :rcov do
43
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
44
+ end
45
+ end
46
+
47
+
48
+ task :default => :test
49
+
50
+ require 'rake/rdoctask'
51
+ Rake::RDocTask.new do |rdoc|
52
+ if File.exist?('VERSION.yml')
53
+ config = YAML.load(File.read('VERSION.yml'))
54
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
55
+ else
56
+ version = ""
57
+ end
58
+
59
+ rdoc.rdoc_dir = 'rdoc'
60
+ rdoc.title = "yahoo_site_explorer #{version}"
61
+ rdoc.rdoc_files.include('README*')
62
+ rdoc.rdoc_files.include('lib/**/*.rb')
63
+ end
64
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,29 @@
1
+ require 'relax'
2
+ require 'yahoo_site_explorer/api'
3
+ require 'yahoo_site_explorer/backlinks'
4
+
5
+ ##
6
+ #
7
+ #
8
+ class YahooSiteExplorer
9
+
10
+
11
+ def initialize(appid)
12
+ @appid = appid
13
+ end
14
+
15
+
16
+ def backlinks(url, options = {})
17
+ options[:query] ||= url
18
+ Backlinks.new(api.inlink_data(options))
19
+ end
20
+
21
+
22
+ private
23
+
24
+
25
+ def api
26
+ @api ||= API.new(:appid => @appid)
27
+ end
28
+
29
+ end
@@ -0,0 +1,29 @@
1
+ class YahooSiteExplorer
2
+
3
+ class API < Relax::Service #:nodoc:
4
+
5
+ defaults do
6
+ parameter :appid, :required => true
7
+ parameter :query, :required => true
8
+ end
9
+
10
+ endpoint 'http://search.yahooapis.com/SiteExplorerService/V1/' do
11
+
12
+ action :inlink_data, :url => 'inlinkData' do
13
+ parameter :results
14
+ parameter :start
15
+ parameter :entire_site
16
+ parameter :omit_inlinks
17
+ parameter :output
18
+ parameter :callback
19
+
20
+ parser 'ResultSet' do
21
+ element :total_results, :attribute => 'totalResultsAvailable', :xpath => './/@totalResultsAvailable'
22
+ end
23
+ end
24
+
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -0,0 +1,17 @@
1
+ class YahooSiteExplorer
2
+
3
+ class Backlinks #:nodoc:
4
+
5
+ attr_reader :total_results
6
+
7
+ def initialize(backlinks_hash)
8
+ self.total_results = backlinks_hash[:total_results]
9
+ end
10
+
11
+ def total_results=(count)
12
+ @total_results = count ? count.to_i : nil
13
+ end
14
+
15
+ end
16
+
17
+ end
@@ -0,0 +1,34 @@
1
+ require 'test_helper'
2
+
3
+ class YahooSiteExplorerTest < Test::Unit::TestCase
4
+
5
+ context 'YahooSiteExplorer' do
6
+
7
+ context 'backlinks' do
8
+
9
+ setup do
10
+ mock_response_for('http://search.yahooapis.com:80/SiteExplorerService/V1/inlinkData?appid=testid&query=http://www.google.com',
11
+ :response => mock_inlink_data_successful_response)
12
+ end
13
+
14
+ teardown do
15
+ FakeWeb.clean_registry
16
+ end
17
+
18
+ should 'return Backlinks' do
19
+ assert_kind_of YahooSiteExplorer::Backlinks, site_explorer.backlinks('http://www.google.com')
20
+ end
21
+
22
+ should 'return total_results as an integer' do
23
+ assert_equal 941822, site_explorer.backlinks('http://www.google.com').total_results
24
+ end
25
+
26
+ end
27
+
28
+ end
29
+
30
+ def site_explorer
31
+ YahooSiteExplorer.new('testid')
32
+ end
33
+
34
+ end
@@ -0,0 +1,33 @@
1
+ def mock_inlink_data_successful_response
2
+ <<-RESPONSE
3
+ HTTP/1.1 200 OK
4
+ Date: Mon, 08 Jun 2009 18:36:57 GMT
5
+ P3P: policyref="http://info.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE LOC GOV"
6
+ Cache-Control: private
7
+ Connection: close
8
+ Transfer-Encoding: chunked
9
+ Content-Type: text/xml; charset=utf-8
10
+
11
+ <?xml version='1.0' encoding='UTF-8'?>
12
+ <ResultSet
13
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
14
+ xmlns="urn:yahoo:srch"
15
+ xsi:schemaLocation="urn:yahoo:srch http://api.search.yahoo.com/SiteExplorerService/V1/InlinkDataResponse.xsd"
16
+ totalResultsAvailable="941822"
17
+ firstResultPosition="1"
18
+ totalResultsReturned="2">
19
+ <Result>
20
+ <Title>Common Dreams News Center</Title>
21
+ <Url>http://www.commondreams.org/</Url>
22
+ <ClickUrl>http://www.commondreams.org/</ClickUrl>
23
+ </Result>
24
+ <Result>
25
+ <Title>Scrub The Web</Title>
26
+ <Url>http://www.scrubtheweb.com/</Url>
27
+ <ClickUrl>http://www.scrubtheweb.com/</ClickUrl>
28
+ </Result>
29
+ </ResultSet>
30
+ <!-- fe02.sitex.search.ac2.yahoo.com uncompressed/chunked Mon Jun 8 11:36:57 PDT 2009 -->
31
+ <!-- ws01.ydn.re2.yahoo.com uncompressed/chunked Mon Jun 8 11:36:57 PDT 2009 -->
32
+ RESPONSE
33
+ end
@@ -0,0 +1,22 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+ require 'fakeweb'
5
+
6
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
8
+
9
+ Dir[File.dirname(__FILE__) + '/mocks/**/*.rb'].each { |mock| require mock }
10
+
11
+ require 'yahoo_site_explorer'
12
+
13
+ # Disable all unregistered (mocked) network traffic when testing.
14
+ FakeWeb.allow_net_connect = false
15
+
16
+ class Test::Unit::TestCase
17
+
18
+ def mock_response_for(url, response, method = :get)
19
+ FakeWeb.register_uri(method, url, response)
20
+ end
21
+
22
+ end
@@ -0,0 +1,23 @@
1
+ require 'test_helper'
2
+
3
+ class InlinkDataTest < Test::Unit::TestCase
4
+
5
+ context 'YahooSiteExplorer::API.inlink_data' do
6
+
7
+ teardown do
8
+ FakeWeb.clean_registry
9
+ end
10
+
11
+ should 'return the total number of query results' do
12
+ mock_response_for('http://search.yahooapis.com/SiteExplorerService/V1/inlinkData?appid=testid&query=http://www.google.com',
13
+ :response => mock_inlink_data_successful_response)
14
+ assert_equal '941822', inlink_data(:query => 'http://www.google.com')[:total_results]
15
+ end
16
+
17
+ end
18
+
19
+ def inlink_data(options = {})
20
+ YahooSiteExplorer::API.new.inlink_data({:appid => 'testid'}.merge(options))
21
+ end
22
+
23
+ end
@@ -0,0 +1,69 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{yahoo_site_explorer}
5
+ s.version = "0.0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Nathaniel Bibler"]
9
+ s.date = %q{2009-06-08}
10
+ s.email = %q{gem@nathanielbibler.com}
11
+ s.extra_rdoc_files = [
12
+ "LICENSE",
13
+ "README.rdoc"
14
+ ]
15
+ s.files = [
16
+ ".document",
17
+ ".gitignore",
18
+ "LICENSE",
19
+ "README.rdoc",
20
+ "Rakefile",
21
+ "VERSION",
22
+ "lib/yahoo_site_explorer.rb",
23
+ "lib/yahoo_site_explorer/api.rb",
24
+ "lib/yahoo_site_explorer/backlinks.rb",
25
+ "test/integrations/yahoo_site_explorer_test.rb",
26
+ "test/mocks/inlink_data.rb",
27
+ "test/test_helper.rb",
28
+ "test/units/inlink_data_test.rb",
29
+ "yahoo_site_explorer.gemspec"
30
+ ]
31
+ s.has_rdoc = true
32
+ s.homepage = %q{http://github.com/nbibler/yahoo_site_explorer}
33
+ s.rdoc_options = ["--charset=UTF-8"]
34
+ s.require_paths = ["lib"]
35
+ s.rubyforge_project = %q{site-explorer}
36
+ s.rubygems_version = %q{1.3.2}
37
+ s.summary = %q{Ruby interface to the Yahoo! Site Explorer REST API}
38
+ s.test_files = [
39
+ "test/integrations/yahoo_site_explorer_test.rb",
40
+ "test/mocks/inlink_data.rb",
41
+ "test/test_helper.rb",
42
+ "test/units/inlink_data_test.rb"
43
+ ]
44
+
45
+ if s.respond_to? :specification_version then
46
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
50
+ s.add_runtime_dependency(%q<relax>, ["~> 0.1.1"])
51
+ s.add_development_dependency(%q<jeweler>, ["~> 0.11.0"])
52
+ s.add_development_dependency(%q<mocha>, ["~> 0.9.5"])
53
+ s.add_development_dependency(%q<thoughtbot-shoulda>, ["~> 2.10.1"])
54
+ s.add_development_dependency(%q<fakeweb>, ["~> 1.2.2"])
55
+ else
56
+ s.add_dependency(%q<relax>, ["~> 0.1.1"])
57
+ s.add_dependency(%q<jeweler>, ["~> 0.11.0"])
58
+ s.add_dependency(%q<mocha>, ["~> 0.9.5"])
59
+ s.add_dependency(%q<thoughtbot-shoulda>, ["~> 2.10.1"])
60
+ s.add_dependency(%q<fakeweb>, ["~> 1.2.2"])
61
+ end
62
+ else
63
+ s.add_dependency(%q<relax>, ["~> 0.1.1"])
64
+ s.add_dependency(%q<jeweler>, ["~> 0.11.0"])
65
+ s.add_dependency(%q<mocha>, ["~> 0.9.5"])
66
+ s.add_dependency(%q<thoughtbot-shoulda>, ["~> 2.10.1"])
67
+ s.add_dependency(%q<fakeweb>, ["~> 1.2.2"])
68
+ end
69
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yahoo_site_explorer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Nathaniel Bibler
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-06-08 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: relax
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 0.1.1
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: jeweler
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.11.0
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: mocha
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 0.9.5
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: thoughtbot-shoulda
47
+ type: :development
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 2.10.1
54
+ version:
55
+ - !ruby/object:Gem::Dependency
56
+ name: fakeweb
57
+ type: :development
58
+ version_requirement:
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ~>
62
+ - !ruby/object:Gem::Version
63
+ version: 1.2.2
64
+ version:
65
+ description:
66
+ email: gem@nathanielbibler.com
67
+ executables: []
68
+
69
+ extensions: []
70
+
71
+ extra_rdoc_files:
72
+ - LICENSE
73
+ - README.rdoc
74
+ files:
75
+ - .document
76
+ - .gitignore
77
+ - LICENSE
78
+ - README.rdoc
79
+ - Rakefile
80
+ - VERSION
81
+ - lib/yahoo_site_explorer.rb
82
+ - lib/yahoo_site_explorer/api.rb
83
+ - lib/yahoo_site_explorer/backlinks.rb
84
+ - test/integrations/yahoo_site_explorer_test.rb
85
+ - test/mocks/inlink_data.rb
86
+ - test/test_helper.rb
87
+ - test/units/inlink_data_test.rb
88
+ - yahoo_site_explorer.gemspec
89
+ has_rdoc: true
90
+ homepage: http://github.com/nbibler/yahoo_site_explorer
91
+ licenses: []
92
+
93
+ post_install_message:
94
+ rdoc_options:
95
+ - --charset=UTF-8
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: "0"
103
+ version:
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: "0"
109
+ version:
110
+ requirements: []
111
+
112
+ rubyforge_project: site-explorer
113
+ rubygems_version: 1.3.2
114
+ signing_key:
115
+ specification_version: 3
116
+ summary: Ruby interface to the Yahoo! Site Explorer REST API
117
+ test_files:
118
+ - test/integrations/yahoo_site_explorer_test.rb
119
+ - test/mocks/inlink_data.rb
120
+ - test/test_helper.rb
121
+ - test/units/inlink_data_test.rb