Class: Google::Ajax::Feed

Inherits:
Object
  • Object
show all
Defined in:
lib/google_ajax_feed_api.rb,
lib/google_ajax_feed_api/api.rb,
lib/google_ajax_feed_api/feed.rb,
lib/google_ajax_feed_api/entry.rb,
lib/google_ajax_feed_api/api/one_zero.rb

Defined Under Namespace

Modules: API Classes: Entry

Constant Summary collapse

Version =
"0.0.3"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Feed

:nodoc:



107
108
109
# File 'lib/google_ajax_feed_api/feed.rb', line 107

def initialize url #:nodoc:
  @url = url
end

Class Method Details

.apiObject

:nodoc:



47
48
49
# File 'lib/google_ajax_feed_api/feed.rb', line 47

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.



23
24
25
26
27
28
29
# File 'lib/google_ajax_feed_api/feed.rb', line 23

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



41
42
43
44
45
# File 'lib/google_ajax_feed_api/feed.rb', line 41

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.



70
71
72
# File 'lib/google_ajax_feed_api/feed.rb', line 70

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.)



55
56
57
# File 'lib/google_ajax_feed_api/feed.rb', line 55

def canonical_id
  @url
end

#descriptionObject

The description of the feed.



80
81
82
# File 'lib/google_ajax_feed_api/feed.rb', line 80

def description
  feed["description"]
end

#entriesObject

List of Entry objects for this feed.



85
86
87
88
89
# File 'lib/google_ajax_feed_api/feed.rb', line 85

def entries
  @entries ||= feed["entries"].map do |entry| 
    Entry.new(entry)
  end
end

#feedObject

:nodoc:



102
103
104
105
# File 'lib/google_ajax_feed_api/feed.rb', line 102

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

The link of the feed.



65
66
67
# File 'lib/google_ajax_feed_api/feed.rb', line 65

def link
  feed["link"]
end

#load(options = {}) ⇒ Object

:nodoc:



91
92
93
94
95
96
97
98
99
100
# File 'lib/google_ajax_feed_api/feed.rb', line 91

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.



75
76
77
# File 'lib/google_ajax_feed_api/feed.rb', line 75

def title
  feed["title"]
end

#valid?Boolean

true if the lookup returned a positive match for a feed

Returns:

  • (Boolean)


60
61
62
# File 'lib/google_ajax_feed_api/feed.rb', line 60

def valid?
  not @url.nil?
end