mlangenberg-googlesearch 0.0.2 → 0.0.3

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.
data/googlesearch.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'googlesearch'
3
- s.version = '0.0.2'
4
- s.date = '2009-01-13'
3
+ s.version = '0.0.3'
4
+ s.date = '2009-01-14'
5
5
  s.platform = Gem::Platform::RUBY
6
6
  s.has_rdoc = false
7
7
  s.summary = 'Google CSE implementation'
@@ -1,5 +1,3 @@
1
- require 'nokogiri'
2
-
3
1
  class SearchResponse
4
2
  def initialize(xml)
5
3
  doc = Nokogiri::XML(xml)
@@ -1,9 +1,11 @@
1
1
  class SearchResult
2
- attr_reader :url, :index, :title, :excerpt
2
+ attr_reader :url, :index, :title, :excerpt, :language, :mime_type
3
3
  def initialize(doc)
4
+ @index = doc.attributes["N"].text.to_i
5
+ @mime_type = doc.attributes["MIME"] ? doc.attributes["MIME"].text : nil
4
6
  @url = doc.xpath('U').text
5
- @index = doc.attributes["N"].to_i
6
7
  @title = doc.xpath('T').text
7
8
  @excerpt = doc.xpath('S').text
9
+ @language = doc.xpath('LANG').text
8
10
  end
9
11
  end
data/lib/googlesearch.rb CHANGED
@@ -1,13 +1,16 @@
1
+ require 'rubygems'
1
2
  require 'googlesearch/search_response'
2
3
  require 'googlesearch/search_result'
3
4
  require 'open-uri'
5
+ require 'nokogiri'
6
+
4
7
 
5
8
  class GoogleSearch
6
9
 
7
10
  attr_reader :response
8
11
 
9
12
  def initialize(options, search_request = SearchRequest.new)
10
- @response = SearchResponse.new search_request.get("http://www.google.com/search?&q=#{options[:q]}&client=google-csbe&output=xml&cx=#{options[:cx]}&cr=lang_#{options[:cr]}")
13
+ @response = SearchResponse.new search_request.get("http://www.google.com/search?&q=#{options[:q]}&client=google-csbe&output=xml&cx=#{options[:cx]}&cr=lang_#{options[:cr]}&lr=lang_#{options[:lr]}")
11
14
  end
12
15
  end
13
16
 
@@ -1,14 +1,14 @@
1
1
  require File.join(File.dirname(__FILE__), 'spec_helper')
2
2
 
3
3
  describe GoogleSearch do
4
- it do
4
+ it "should be able to create a search query" do
5
5
  request_mock = mock('request')
6
6
  request_mock.should_receive(:get).with(
7
- 'http://www.google.com/search?&q=adres&client=google-csbe&output=xml&cx=unique-cse-id&cr=lang_nl'
7
+ 'http://www.google.com/search?&q=adres&client=google-csbe&output=xml&cx=unique-cse-id&cr=lang_nl&lr=lang_nl'
8
8
  ).and_return('wat_xml')
9
9
 
10
10
  SearchResponse.should_receive(:new).with('wat_xml').and_return('search-response-object')
11
- search = GoogleSearch.new({:cx => 'unique-cse-id', :q => 'adres', :cr => 'nl'}, request_mock)
11
+ search = GoogleSearch.new({:cx => 'unique-cse-id', :q => 'adres', :cr => 'nl', :lr => 'nl'}, request_mock)
12
12
  search.response.should == 'search-response-object'
13
13
  end
14
14
  end
@@ -15,19 +15,7 @@ describe SearchResponse do
15
15
  @response.total_number_of_results.should == 5
16
16
  end
17
17
 
18
- it "should be able to return the first URL of the results" do
19
- @response.results.first.url.should == 'http://i3.shop-r.nl/language/nl/pages/39'
20
- end
21
-
22
- it "should be able to return the second index of the results" do
23
- @response.results[1].index.should == 2
24
- end
25
-
26
- it "should be able to return the last title of the results" do
27
- @response.results.last.title.should == 'caesar - more'
28
- end
29
-
30
- it "should be able to return the third text of the results" do
31
- @response.results[2].excerpt.should == %[De &#39;NV <b>Intercodam</b>&#39; is opgericht op 16 september 1919 en handelde in de meest <br> uiteenlopende producten. In 1972 werd deze NV omgezet in een Beheer B.V. <b>...</b>]
18
+ it "should be able to return an array of SearchResult objects" do
19
+ @response.results.map { |r| r.class }.should == [SearchResult]*5
32
20
  end
33
21
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mlangenberg-googlesearch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rene Heino
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-01-13 00:00:00 -08:00
13
+ date: 2009-01-14 00:00:00 -08:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency