Class: GoogleRest::Request
- Inherits:
-
Object
- Object
- GoogleRest::Request
- Includes:
- HTTParty
- Defined in:
- lib/google_rest.rb
Defined Under Namespace
Modules: Util
Constant Summary collapse
- API_VERSION =
"1.0"- API_URL =
{ :feed_lookup => "/feed/lookup", :feed_load => "/feed/load", :web => "/search/web", :blog => "/search/blogs", :news => "/search/news", :image => "/search/images", :local => "/search/local", :video => "/search/video" }
- @@ascii_available =
"".respond_to?(:to_ascii)
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#referer ⇒ Object
Returns the value of attribute referer.
-
#userip ⇒ Object
Returns the value of attribute userip.
Instance Method Summary collapse
- #api_key? ⇒ Boolean
- #blog_search(query, options = {}) ⇒ Object
- #feed_load(feed_url, count_entries = false) ⇒ Object
- #feed_lookup(website) ⇒ Object
- #image_search(query, options = {}) ⇒ Object
- #inbound_links(url) ⇒ Object
- #indexed_pages(url) ⇒ Object
-
#initialize(userip = nil) ⇒ Request
constructor
A new instance of Request.
- #local_search(query, options = {}) ⇒ Object
- #news_search(query, options = {}) ⇒ Object
- #userip? ⇒ Boolean
- #video_search(query, options = {}) ⇒ Object
- #web_search(query, options = {}) ⇒ Object
Constructor Details
#initialize(userip = nil) ⇒ Request
Returns a new instance of Request.
93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/google_rest.rb', line 93 def initialize(userip = nil) path = Rails.root.join("config/google_rest.yml") if !File.exists?(path) raise StandardError, "Missing config file: #{path}" else config = YAML.load_file(path) || {} data = config[Rails.env.to_s] || config self.api_key = data['api_key'] self.referer = data['referer'] self.userip = userip end end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
75 76 77 |
# File 'lib/google_rest.rb', line 75 def api_key @api_key end |
#referer ⇒ Object
Returns the value of attribute referer.
76 77 78 |
# File 'lib/google_rest.rb', line 76 def referer @referer end |
#userip ⇒ Object
Returns the value of attribute userip.
77 78 79 |
# File 'lib/google_rest.rb', line 77 def userip @userip end |
Instance Method Details
#api_key? ⇒ Boolean
157 158 159 |
# File 'lib/google_rest.rb', line 157 def api_key? !self.api_key.blank? end |
#blog_search(query, options = {}) ⇒ Object
123 124 125 |
# File 'lib/google_rest.rb', line 123 def blog_search(query, = {}) common_search(:blog, {:scoring => 'd', :rsz => 'large', :q => query}.merge()) end |
#feed_load(feed_url, count_entries = false) ⇒ Object
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/google_rest.rb', line 112 def feed_load(feed_url, count_entries = false) return nil if feed_url.blank? if count_entries == false # we retrieve the current feed entries res = google_request(:feed_load, {:q => feed_url, :num => -1}) else res = google_request(:feed_load, {:q => feed_url, :num => count_entries, :scoring => 'h'} ) end res.empty? ? nil : res.raw["feed"] end |
#feed_lookup(website) ⇒ Object
106 107 108 109 110 |
# File 'lib/google_rest.rb', line 106 def feed_lookup(website) return nil if website.blank? res = google_request(:feed_lookup, {:q => website.to_s.gsub(/^https?:\/\//i, '')}) res.empty? ? nil : res.raw["url"] end |
#image_search(query, options = {}) ⇒ Object
135 136 137 |
# File 'lib/google_rest.rb', line 135 def image_search(query, = {}) common_search(:image, {:q => query}.merge()) end |
#inbound_links(url) ⇒ Object
147 148 149 150 |
# File 'lib/google_rest.rb', line 147 def inbound_links(url) res = common_search(:web, {:q => "link:#{url.gsub(/^https?:\/\//,'')}"}) res.cursor.blank? ? 0 : res.cursor["estimatedResultCount"].to_i end |
#indexed_pages(url) ⇒ Object
152 153 154 155 |
# File 'lib/google_rest.rb', line 152 def indexed_pages(url) res = common_search(:web, {:q => "site:#{url.gsub(/^https?:\/\//,'')}"}) res.cursor.blank? ? 0 : res.cursor["estimatedResultCount"].to_i end |
#local_search(query, options = {}) ⇒ Object
143 144 145 |
# File 'lib/google_rest.rb', line 143 def local_search(query, = {}) common_search(:local, {:q => query}.merge()) end |
#news_search(query, options = {}) ⇒ Object
131 132 133 |
# File 'lib/google_rest.rb', line 131 def news_search(query, = {}) common_search(:news, {:rsz => 'large', :scoring => 'd', :q => query}.merge()) end |
#userip? ⇒ Boolean
161 162 163 |
# File 'lib/google_rest.rb', line 161 def userip? !self.userip.blank? end |
#video_search(query, options = {}) ⇒ Object
139 140 141 |
# File 'lib/google_rest.rb', line 139 def video_search(query, = {}) common_search(:video, {:q => query}.merge()) end |
#web_search(query, options = {}) ⇒ Object
127 128 129 |
# File 'lib/google_rest.rb', line 127 def web_search(query, = {}) common_search(:web, {:rsz => 'large', :q => query}.merge()) end |