Class: Google::Ajax::Feed

Inherits:
Object
  • Object
show all
Defined in:
lib/google_ajax_feed_api.rb

Defined Under Namespace

Modules: API Classes: Entry

Class Method Summary collapse

Instance Method Summary collapse

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

.apiObject

:nodoc:



156
157
158
# File 'lib/google_ajax_feed_api.rb', line 156

def api #:nodoc:
  API[config.version]
end

.configObject

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:

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

#authorObject

The author of the feed.



179
180
181
# File 'lib/google_ajax_feed_api.rb', line 179

def author
  feed["author"]
end

#canonical_idObject

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

#descriptionObject

The description of the feed.



189
190
191
# File 'lib/google_ajax_feed_api.rb', line 189

def description
  feed["description"]
end

#entriesObject

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

#feedObject

:nodoc:



211
212
213
214
# File 'lib/google_ajax_feed_api.rb', line 211

def feed #:nodoc:
  load if @feed.nil?
  @feed
end

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 options={} #:nodoc:
  url = self.class.api.load_query @url, options
  
  # 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

#titleObject

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

Returns:

  • (Boolean)


169
170
171
# File 'lib/google_ajax_feed_api.rb', line 169

def valid?
  not @url.nil?
end