Class: BingSearchClient::News
- Inherits:
-
Object
- Object
- BingSearchClient::News
- Defined in:
- lib/bing_search_client/news.rb
Instance Attribute Summary collapse
-
#num_results ⇒ Object
readonly
Returns the value of attribute num_results.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
-
#initialize(num_results: 100, params: {}) ⇒ News
constructor
A new instance of News.
- #search(q:, offset: 0) ⇒ Object
Constructor Details
#initialize(num_results: 100, params: {}) ⇒ News
Returns a new instance of News.
6 7 8 9 |
# File 'lib/bing_search_client/news.rb', line 6 def initialize(num_results: 100, params: {}) @num_results = num_results @params = params end |
Instance Attribute Details
#num_results ⇒ Object (readonly)
Returns the value of attribute num_results.
4 5 6 |
# File 'lib/bing_search_client/news.rb', line 4 def num_results @num_results end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
4 5 6 |
# File 'lib/bing_search_client/news.rb', line 4 def params @params end |
Instance Method Details
#search(q:, offset: 0) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/bing_search_client/news.rb', line 11 def search(q:, offset: 0) query_string = 'q=' query_portion = URI.encode_www_form_component('\'' + q + '\'') local_params = "&count=#{num_results}&offset=#{offset}" @params.each do |k,v| local_params << "&#{k.to_s}=#{v.to_s}" end full_address = [BingSearchClient.config.base_url, 'news/search'].join('/') + '?' + query_string + query_portion + local_params Client.new(url: full_address).get end |