Class: Google::Ajax::Feed
- Inherits:
-
Object
- Object
- Google::Ajax::Feed
- Defined in:
- lib/google_ajax_feed_api.rb
Defined Under Namespace
Class Method Summary collapse
-
.api ⇒ Object
:nodoc:.
-
.config ⇒ Object
Default values are: * config.version = ‘1.0’.
-
.lookup(url) ⇒ Object
Lookup will take any of these url formats: * example.com * example.com/ * www.example.com/ * www.example.com * example.com/rss * etc.
Instance Method Summary collapse
-
#author ⇒ Object
The author of the feed.
-
#canonical_id ⇒ Object
A canonical identifier for the feed.
-
#description ⇒ Object
The description of the feed.
-
#entries ⇒ Object
List of Entry objects for this feed.
-
#feed ⇒ Object
:nodoc:.
-
#initialize(url) ⇒ Feed
constructor
:nodoc:.
-
#link ⇒ Object
The link of the feed.
-
#load(options = {}) ⇒ Object
:nodoc:.
-
#title ⇒ Object
The title of the feed.
-
#valid? ⇒ Boolean
true if the lookup returned a positive match for a feed.
Constructor Details
#initialize(url) ⇒ Feed
:nodoc:
216 217 218 |
# File 'lib/google_ajax_feed_api.rb', line 216 def initialize url #:nodoc: @url = url end |
Class Method Details
.api ⇒ Object
:nodoc:
156 157 158 |
# File 'lib/google_ajax_feed_api.rb', line 156 def api #:nodoc: API[config.version] end |
.config ⇒ Object
Default values are:
-
config.version = ‘1.0’
version specifies what version of the feed API to use. 1.0 is the only version that exists and thusly the only option supported. DO NOT CHANGE THIS
-
config.limit = 15
limit specifies how many feed items may be fetched at once Google specifies a hard limit of 100. But an individual feed might have it’s own, lower limit.
-
config.history = false
Which is where the history option comes into play. History pulls from Googls cache of the feed, not from the current state of the feed. With this option you can fetch up to 100 items from a feed that shows fewer than 100 at any given time.
132 133 134 135 136 137 138 |
# File 'lib/google_ajax_feed_api.rb', line 132 def config @config ||= OpenStruct.new( :version => '1.0', :limit => 15, :history => false ) end |
.lookup(url) ⇒ Object
Lookup will take any of these url formats:
-
example.com/rss
-
etc.
And the object created will have the same Feed#canonical_id Use of Feed#new is strongly discouraged
150 151 152 153 154 |
# File 'lib/google_ajax_feed_api.rb', line 150 def lookup url http_response = JSON.parse open(api.lookup_query(url)).read url = http_response["responseData"]["url"] new url end |
Instance Method Details
#author ⇒ Object
The author of the feed.
179 180 181 |
# File 'lib/google_ajax_feed_api.rb', line 179 def feed["author"] end |
#canonical_id ⇒ Object
A canonical identifier for the feed. Feeds found with Feed#lookup will have the some canonical_id even if the url used to find them was not 100% the same. (Missing ‘/’ etc.)
164 165 166 |
# File 'lib/google_ajax_feed_api.rb', line 164 def canonical_id @url end |
#description ⇒ Object
The description of the feed.
189 190 191 |
# File 'lib/google_ajax_feed_api.rb', line 189 def description feed["description"] end |
#entries ⇒ Object
List of Entry objects for this feed.
194 195 196 197 198 |
# File 'lib/google_ajax_feed_api.rb', line 194 def entries @entries ||= feed["entries"].map do |entry| Entry.new(entry) end end |
#feed ⇒ Object
:nodoc:
211 212 213 214 |
# File 'lib/google_ajax_feed_api.rb', line 211 def feed #:nodoc: load if @feed.nil? @feed end |
#link ⇒ Object
The link of the feed.
174 175 176 |
# File 'lib/google_ajax_feed_api.rb', line 174 def link feed["link"] end |
#load(options = {}) ⇒ Object
:nodoc:
200 201 202 203 204 205 206 207 208 209 |
# File 'lib/google_ajax_feed_api.rb', line 200 def load ={} #:nodoc: url = self.class.api.load_query @url, # Very strange json bug. Bye bye tabs http_response = JSON.parse open(url).read.gsub("\t", '') @feed = http_response["responseData"]["feed"] return @feed.length end |
#title ⇒ Object
The title of the feed.
184 185 186 |
# File 'lib/google_ajax_feed_api.rb', line 184 def title feed["title"] end |
#valid? ⇒ Boolean
true if the lookup returned a positive match for a feed
169 170 171 |
# File 'lib/google_ajax_feed_api.rb', line 169 def valid? not @url.nil? end |