Skip to content

Commit

Permalink
Adding globalize option to the request
Browse files Browse the repository at this point in the history
  • Loading branch information
staskie committed Jul 13, 2012
1 parent d093af6 commit dcd64ba
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/ruby-web-search.rb
Expand Up @@ -28,7 +28,7 @@ def self.unthreaded_search(options={})
end

class Query
attr_accessor :query, :start_index, :result_size, :filter, :country_code, :language_code
attr_accessor :query, :start_index, :result_size, :filter, :country_code, :language_code, :global
attr_accessor :safe_search, :type, :custom_search_engine_id, :version, :referer, :request_url
attr_accessor :size, :cursor, :custom_request_url, :response

Expand Down Expand Up @@ -77,6 +77,7 @@ def initialize(options={})
@version = options[:version] || "1.0"
@referer = options[:referer] || "http://github.com/mattetti/"
@size = options[:size] || 4
@global = options[:global]
@result_size = "large" if size > 4 # increase the result set size to avoid making too many requests
@size = 8 if (@result_size == "large" && size < 8)
end
Expand All @@ -92,6 +93,7 @@ def build_request
@request_url << "&start=#{cursor}" if cursor > 0
@request_url << "&lr=#{language_code}" if language_code
@request_url << "&hl=#{country_code}" if country_code
@request_url << "&gl=#{global}" if global

puts request_url if $RUBY_WEB_SEARCH_DEBUG
request_url
Expand All @@ -110,6 +112,7 @@ def build_requests
url << "&rsz=#{result_size}" if result_size
url << "&lr=#{language_code}" if language_code
url << "&hl=#{country_code}" if country_code
url << "&gl=#{global}" if global
url << "&start=#{cursor}"
@cursor += 8
requests << url
Expand Down Expand Up @@ -538,4 +541,4 @@ def limit(req_size)

end #of Bing

end
end

0 comments on commit dcd64ba

Please sign in to comment.