Class: Google::Ajax::Feed
- Inherits:
-
Object
- Object
- Google::Ajax::Feed
- 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
Constant Summary collapse
- Version =
"0.0.3"
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:
107 108 109 |
# File 'lib/google_ajax_feed_api/feed.rb', line 107 def initialize url #:nodoc: @url = url end |
Class Method Details
.api ⇒ Object
:nodoc:
47 48 49 |
# File 'lib/google_ajax_feed_api/feed.rb', line 47 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.
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:
-
example.com/rss
-
etc.
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
#author ⇒ Object
The author of the feed.
70 71 72 |
# File 'lib/google_ajax_feed_api/feed.rb', line 70 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.)
55 56 57 |
# File 'lib/google_ajax_feed_api/feed.rb', line 55 def canonical_id @url end |
#description ⇒ Object
The description of the feed.
80 81 82 |
# File 'lib/google_ajax_feed_api/feed.rb', line 80 def description feed["description"] end |
#entries ⇒ Object
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 |
#feed ⇒ Object
:nodoc:
102 103 104 105 |
# File 'lib/google_ajax_feed_api/feed.rb', line 102 def feed #:nodoc: load if @feed.nil? @feed end |
#link ⇒ Object
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 ={} #: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.
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
60 61 62 |
# File 'lib/google_ajax_feed_api/feed.rb', line 60 def valid? not @url.nil? end |