Class: FrankResearcher::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/frank_researcher/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize ⇒ Client

Returns a new instance of Client.



6
7
8
9
10
# File 'lib/frank_researcher/client.rb', line 6

def initialize
  google_key = FrankResearcher.configuration.google_api_key
  google_cx = FrankResearcher.configuration.google_cx
  @base_url = "https://www.googleapis.com/customsearch/v1?key=#{google_key}&cx=#{google_cx}"
end

Instance Attribute Details

#base_url ⇒ Object

Returns the value of attribute base_url.



5
6
7
# File 'lib/frank_researcher/client.rb', line 5

def base_url
  @base_url
end

Instance Method Details

#find(params) ⇒ Object



12
13
14
# File 'lib/frank_researcher/client.rb', line 12

def find params
  response = request(@base_url, params)
end

#request(url, query) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/frank_researcher/client.rb', line 16

def request url, query
  url << "&q=#{query}"
  response = RestClient.get(url, headers={content_type: :json, accept: :json})
  if response.code == 200
    response.body
  end
end