class Gugl::Search::RemoteSearcher

Constants

ERROR_RESPONSE_NODE
ITEMS_RESPONSE_NODE

Attributes

credentials[RW]

Public Instance Methods

authorize() { |credentials| ... } click to toggle source
# File lib/search/remote_searcher.rb, line 22
def authorize
  self.credentials = ApiCredentials.new
  yield credentials
end

Private Instance Methods

base_url() click to toggle source
# File lib/search/remote_searcher.rb, line 41
def base_url
  "https://www.googleapis.com/customsearch/v1"
end
fetch(query, limit) click to toggle source
# File lib/search/remote_searcher.rb, line 34
def fetch(query, limit)
  HTTParty.get(base_url, query: {
    num: limit,
    q: query
  }.merge(credentials.to_h))
end
fetch_and_parse(query, limit) click to toggle source
# File lib/search/remote_searcher.rb, line 29
def fetch_and_parse(query, limit)
  response = fetch(query, limit)
  parse_response(response)
end
parse_response(response) click to toggle source
# File lib/search/remote_searcher.rb, line 45
def parse_response(response)
  JSON.parse(response.body)
end