class CognitiveBingNews

Attributes

account_key[RW]

Public Class Methods

new(account_key, params = {}) click to toggle source
# File lib/cognitivebing.rb, line 92
def initialize(account_key, params = {})
  @account_key = account_key
  @params = params
end

Public Instance Methods

category(category_term, params = {}) click to toggle source
# File lib/cognitivebing.rb, line 131
def category(category_term, params = {})

  web_search_url = URI('https://api.cognitive.microsoft.com/bing/v5.0/news/')
  web_search_url.query = URI.encode_www_form({
    # Request parameters
    'category' => category_term.to_s
  })


  uri = URI(web_search_url)
  req = Net::HTTP::Get.new(uri.request_uri)
  req.add_field("Ocp-Apim-Subscription-Key", @account_key)


  res = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => uri.scheme == 'https') { |http|
    http.request(req)
  }

  body = JSON.parse(res.body, :symbolize_names => true)


  return body
end