Class: BingSearchClient::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url:) ⇒ Client

Returns a new instance of Client.



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

def initialize(url:)
  @url = url
end

Instance Attribute Details

#urlObject (readonly)

Returns the value of attribute url.



3
4
5
# File 'lib/bing_search_client/client.rb', line 3

def url
  @url
end

Instance Method Details

#getObject



9
10
11
12
13
14
15
16
17
# File 'lib/bing_search_client/client.rb', line 9

def get
  uri = URI(url)
  req = Net::HTTP::Get.new(uri.request_uri)
  req.add_field('Ocp-Apim-Subscription-Key', BingSearchClient.config.)
  response = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => uri.scheme == 'https') do |http|
    http.request(req)
  end
  parse_response(response)
end