Class: BingHelper::Bing
- Inherits:
-
Object
- Object
- BingHelper::Bing
- Defined in:
- lib/bing-helper/bing.rb
Constant Summary collapse
- API_URL =
"http://api.search.live.net/json.aspx"
- BASE_OPTIONS =
[:version, :market, :adult, :query, :appid, :sources]
- QUERY_KEYWORDS =
[:site, :language, :contains, :filetype, :inanchor, :inbody, :intitle, :ip, :loc, :location, :prefer, :feed, :hasfeed, :url]
- SOURCES =
Source Types: <msdn.microsoft.com/en-us/library/dd250847.aspx>
%w(Ad Image InstantAnswer News Phonebook RelatedSearch Spell Web)
Instance Attribute Summary collapse
-
#faraday_client ⇒ Object
readonly
Returns the value of attribute faraday_client.
-
#instance_options ⇒ Object
Returns the value of attribute instance_options.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(app_id, options = {}) ⇒ Bing
constructor
A new instance of Bing.
- #query_params_for(source, query, options) ⇒ Object
- #search(source, query, options = {}) ⇒ Object
Constructor Details
#initialize(app_id, options = {}) ⇒ Bing
Returns a new instance of Bing.
55 56 57 |
# File 'lib/bing-helper/bing.rb', line 55 def initialize(app_id, ={}) self. = .merge(:AppId=>app_id) end |
Instance Attribute Details
#faraday_client ⇒ Object (readonly)
Returns the value of attribute faraday_client.
8 9 10 |
# File 'lib/bing-helper/bing.rb', line 8 def faraday_client @faraday_client end |
#instance_options ⇒ Object
Returns the value of attribute instance_options.
7 8 9 |
# File 'lib/bing-helper/bing.rb', line 7 def @instance_options end |
Class Method Details
.base_url ⇒ Object
69 70 71 |
# File 'lib/bing-helper/bing.rb', line 69 def self.base_url return API_URL end |
Instance Method Details
#query_params_for(source, query, options) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/bing-helper/bing.rb', line 48 def query_params_for(source, query, ) = self..merge({:sources=>source, :query=>build_query(query, )}) .merge(()) end |
#search(source, query, options = {}) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/bing-helper/bing.rb', line 37 def search(source, query, ={}) response = self.faraday_client.get do |req| req.url "", query_params_for(source, query, ) end begin Response.new(Yajl::Parser.new.parse(response.body)) rescue nil end end |