mlangenberg-googlesearch 0.3.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/googlesearch.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'googlesearch'
3
- s.version = '0.3.0'
4
- s.date = '2009-01-21'
3
+ s.version = '1.0.0'
4
+ s.date = '2009-02-04'
5
5
  s.platform = Gem::Platform::RUBY
6
6
  s.has_rdoc = false
7
7
  s.summary = 'Google CSE implementation'
data/lib/googlesearch.rb CHANGED
@@ -10,6 +10,7 @@ require 'nokogiri'
10
10
  class GoogleSearch
11
11
 
12
12
  attr_reader :response
13
+ attr_reader :url
13
14
 
14
15
  def initialize(o = {}, search_request = SearchRequest.new)
15
16
 
@@ -90,15 +91,15 @@ class GoogleSearch
90
91
  # Optional. The c2coff parameter enables or disables the Simplified and Traditional Chinese Search feature.
91
92
 
92
93
 
93
- o[:client] ||= "google-csbe"
94
+ #o[:client] ||= "google-csbe"
94
95
  # Required!!! The client parameter must be set to google-csbe if you use Google Custom Search Service.
95
96
 
96
97
 
97
- o[:cr] = "lang_#{o[:cr]}" if o[:cr]
98
+ #o[:cr] = "country#{o[:cr].upcase}" if o[:cr]
98
99
  # Optional. The cr parameter restricts search results to documents originating in a particular country.
99
100
 
100
101
 
101
- o[:cx] ||= ""
102
+ #o[:cx] ||= ""
102
103
  # Required!!! The cx parameter specifies a unique code that identifies a custom search engine. You must specify a Custom Search Engine using the cx parameter to retrieve search results from that CSE.
103
104
 
104
105
 
@@ -117,11 +118,11 @@ class GoogleSearch
117
118
  #o[:ie] ||= "utf8"
118
119
  # Optional. The ie parameter sets the character encoding scheme that should be used to interpret the query string. The default ie value is latin1.
119
120
 
120
- o[:lr] = "lang_#{o[:lr]}" if o[:lr]
121
+ #o[:lr] = "lang_#{o[:lr].downcase}" if o[:lr]
121
122
  # Optional. The lr (language restrict) parameter restricts search results to documents written in a particular language.
122
123
 
123
124
 
124
- o[:num] ||= 10
125
+ #o[:num] ||= 10
125
126
  # Optional. The num parameter identifies the number of search results to return. The default num value is 10, and the maximum value is 20. If you request more than 20 results, only 20 results will be returned.
126
127
 
127
128
 
@@ -132,11 +133,11 @@ class GoogleSearch
132
133
  #o[:oe] ||= "utf8"
133
134
  # Optional. The oe parameter sets the character encoding scheme that should be used to decode the XML result. The default oe value is latin1.
134
135
 
135
- o[:output] ||= "xml_no_dtd"
136
+ #o[:output] ||= "xml_no_dtd"
136
137
  # Required. The output parameter specifies the format of the XML results. The only valid values for this parameter are xml and xml_no_dtd. The chart below explains how these parameter values differ.
137
138
 
138
139
 
139
- o[:q] ||= ""
140
+ #o[:q] ||= ""
140
141
  # Optional. The q parameter specifies the search query entered by the user. Even though this parameter is optional, you must specify a value for at least one of the query parameters (as_epq, as_lq, as_oq, as_q, as_rq) to get search results.
141
142
 
142
143
 
@@ -144,7 +145,7 @@ class GoogleSearch
144
145
  # Optional. The safe parameter indicates how search results should be filtered for adult and pornographic content. The default value for the safe parameter is off. Valid parameter values are: off, medium or high
145
146
 
146
147
 
147
- o[:start] ||= 10
148
+ #o[:start] ||= 10
148
149
  # Optional. The start parameter indicates the first matching result that should be included in the search results. The start parameter uses a zero-based index, meaning the first result is 0, the second result is 1 and so forth.
149
150
 
150
151
 
@@ -162,9 +163,8 @@ class GoogleSearch
162
163
 
163
164
 
164
165
  # And finally:
165
- @response = SearchResponse.new(
166
- search_request.get("http://www.google.com/search?" + o.map {|key, value| "#{key}=#{value}"}.join('&')), o[:num], o[:start]
167
- )
166
+ @url = "http://www.google.com/search?" + o.map {|key, value| "#{key}=#{value}"}.join('&')
167
+ @response = SearchResponse.new(search_request.get(url))
168
168
 
169
169
  end
170
170
  end
@@ -173,4 +173,4 @@ class SearchRequest
173
173
  def get(uri)
174
174
  open(uri)
175
175
  end
176
- end
176
+ end
@@ -3,12 +3,10 @@ require File.join(File.dirname(__FILE__), 'spec_helper')
3
3
  describe GoogleSearch do
4
4
  it "should be able to create a search query" do
5
5
  request_mock = mock('request')
6
- request_mock.should_receive(:get).with(
7
- 'http://www.google.com/search?cx=unique-cse-id&cr=lang_nl&output=xml_no_dtd&q=adres&lr=lang_nl&client=google-csbe&start=0&num=10'
8
- ).and_return('wat_xml')
6
+ request_mock.should_receive(:get).with('http://www.google.com/search?cx=unique-cse-id&q=adres&cr=countryNL&lr=lang_nl').and_return('wat_xml')
9
7
 
10
- SearchResponse.should_receive(:new).with('wat_xml', 10, 0).and_return('search-response-object')
11
- search = GoogleSearch.new({:cx => 'unique-cse-id', :q => 'adres', :cr => 'nl', :lr => 'nl', :start => 0, :num => 10 }, request_mock)
8
+ SearchResponse.should_receive(:new).with('wat_xml').and_return('search-response-object')
9
+ search = GoogleSearch.new({:cx => 'unique-cse-id', :q => 'adres', :cr => 'countryNL', :lr => 'lang_nl'}, request_mock)
12
10
  search.response.should == 'search-response-object'
13
11
  end
14
12
  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.3.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rene Heino
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2009-01-21 00:00:00 -08:00
14
+ date: 2009-02-04 00:00:00 -08:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency