rbuzz 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ * 0.1
2
+ - Initial version with simple feed parsing
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2010 Conor Hunt <conor.hunt@gmail.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,66 @@
1
+ RBuzz
2
+ =====
3
+
4
+ A simple wrapper to help retrieve and parse the Google Buzz Atom Feed.
5
+
6
+ Coming soon - subscribing to updates, posting to feed
7
+
8
+ Install
9
+ -------
10
+
11
+ gem install rbuzz
12
+
13
+ RBuzz is hosted on the Gemcutter repository. It depends on the RAtom library - http://github.com/seangeo/ratom
14
+
15
+ Example
16
+ -------
17
+
18
+ require 'rbuzz'
19
+
20
+ feed_url = RBuzz::Feed.discover(ARGV[0])
21
+ feed = RBuzz::Feed.retrieve(feed_url)
22
+
23
+ feed.entries.each do |entry|
24
+ puts "Title: #{entry.title}"
25
+ puts "Author: #{entry.author.name}"
26
+ puts "Comment Count: #{entry.comment_count}"
27
+ puts "Content"
28
+ puts entry.content
29
+ puts
30
+
31
+ if entry.urls.length > 0
32
+ puts "Links"
33
+ entry.urls.each {|u| puts "URI: #{u}" }
34
+ puts
35
+ end
36
+
37
+ if entry.images.length > 0
38
+ puts "Images"
39
+ entry.images.each {|i| puts "URI: #{i}" }
40
+ puts
41
+ end
42
+
43
+ if entry.videos.length > 0
44
+ puts "Videos"
45
+ entry.videos.each {|v| puts "URI: #{v}" }
46
+ puts
47
+ end
48
+
49
+ if entry.comment_count > 0
50
+ puts "Comments"
51
+ puts
52
+ entry.comments.each do |comment|
53
+ puts "Author: #{comment.author.name}"
54
+ puts "#{comment.content}"
55
+ puts
56
+ end
57
+ end
58
+ puts "------"
59
+ puts
60
+ end
61
+
62
+ COPYRIGHT
63
+ ---------
64
+
65
+ Copyright (c) 2010 Conor Hunt <conor.hunt@gmail.com>
66
+ Released under the MIT license
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+ require 'atom'
3
+ require 'open-uri'
4
+ require 'rbuzz/feed'
5
+ require 'rbuzz/feed_entry'
6
+ require 'rbuzz/feed_reply'
@@ -0,0 +1,52 @@
1
+ require 'ruby-debug'
2
+ Debugger.start
3
+
4
+ module RBuzz
5
+ class FeedError < Exception; end;
6
+
7
+ class Feed
8
+ attr :feed_url
9
+ attr :atom_feed
10
+
11
+ def initialize(feed_url, options = {})
12
+ @feed_url = feed_url
13
+ end
14
+
15
+ def self.retrieve(feed_url)
16
+ feed = RBuzz::Feed.new(feed_url)
17
+ feed.fetch
18
+ feed
19
+ end
20
+
21
+ # Extract the feed url from the users's google profile page
22
+ def self.discover(profile_name)
23
+ begin
24
+ page = open("http://www.google.com/profiles/#{profile_name}").read
25
+ rescue OpenURI::HTTPError => e
26
+ if e.io.status[0] == '404'
27
+ raise FeedError, "Could not find profile for #{profile_name} at - http://www.google.com/profiles/#{profile_name}"
28
+ end
29
+ end
30
+
31
+ if match = page.match(%r{<link rel="alternate" type="application/atom\+xml" href="([^"]+)})
32
+ match[1]
33
+ else
34
+ raise FeedError, "Could not find atom feed on profile page"
35
+ end
36
+ end
37
+
38
+ # Retrieve and parse the buzz atom feed
39
+ def fetch
40
+ @feed_entries = nil
41
+ @atom_feed = Atom::Feed.load_feed(URI.parse(@feed_url))
42
+ end
43
+
44
+ # Retrieve the entries in the buzz atom feed as an array of RBuzz::FeedEntry objects
45
+ # This will fetch the feed if it has not already been fetched
46
+ def entries
47
+ return @feed_entries if @feed_entries
48
+ fetch if @atom_feed.nil?
49
+ @feed_entries = @atom_feed.entries.collect {|e| FeedEntry.new(e) }
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,52 @@
1
+ module RBuzz
2
+ class FeedEntry
3
+ attr :atom_entry
4
+ attr :atom_replies
5
+
6
+ # Expects an Atom::Entry object
7
+ def initialize(atom_entry)
8
+ @atom_entry = atom_entry
9
+ end
10
+
11
+ def [](name)
12
+ @atom_entry.send(name)
13
+ end
14
+
15
+ def method_missing(method, *args, &block)
16
+ @atom_entry.send(method)
17
+ end
18
+
19
+ def fetch_comments
20
+ @comments = nil
21
+ link = @atom_entry.links.find {|l| l.rel == 'replies'}
22
+ @atom_replies = Atom::Feed.load_feed(URI.parse(link.href)) if link
23
+ end
24
+
25
+ def comments
26
+ return @comments if @comments
27
+ fetch_comments if @atom_replies.nil?
28
+ @comments = @atom_replies.entries.collect {|r| FeedReply.new(r) }
29
+ end
30
+
31
+ def comment_count
32
+ return @comments.length if @comments
33
+ @atom_entry["http://purl.org/syndication/thread/1.0","total"][0].to_i
34
+ end
35
+
36
+ def urls
37
+ @links ||= @atom_entry.links.find_all {|l| l.type =~ %r{text/html}i }.collect {|l| l.href}
38
+ end
39
+
40
+ def images
41
+ @images ||= @atom_entry.links.find_all {|l| l.type =~ /image/i }.collect {|l| l.href}
42
+ end
43
+
44
+ def videos
45
+ @videos ||= @atom_entry.links.find_all {|l| l.type =~ /video/i }.collect {|l| l.href}
46
+ end
47
+
48
+ def author
49
+ @atom_entry.authors[0] if @atom_entry.respond_to?(:authors)
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,22 @@
1
+ module RBuzz
2
+ class FeedReply
3
+ attr :atom_entry
4
+
5
+ # Expects an Atom::Entry object
6
+ def initialize(atom_entry)
7
+ @atom_entry = atom_entry
8
+ end
9
+
10
+ def [](name)
11
+ @atom_entry.send(name)
12
+ end
13
+
14
+ def method_missing(method, *args, &block)
15
+ @atom_entry.send(method)
16
+ end
17
+
18
+ def author
19
+ @atom_entry.authors[0] if @atom_entry.respond_to?(:authors)
20
+ end
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rbuzz
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.1"
5
+ platform: ruby
6
+ authors:
7
+ - Conor Hunt
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-10 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: ratom
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.6.3
24
+ version:
25
+ description: Ruby wrapper for Google Buzz Atom Feeds
26
+ email: conor.hunt@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files: []
32
+
33
+ files:
34
+ - README.md
35
+ - LICENSE
36
+ - Changelog
37
+ - lib/rbuzz/feed.rb
38
+ - lib/rbuzz/feed_entry.rb
39
+ - lib/rbuzz/feed_reply.rb
40
+ - lib/rbuzz.rb
41
+ has_rdoc: true
42
+ homepage: http://github.com/conorh/rbuzz
43
+ licenses: []
44
+
45
+ post_install_message:
46
+ rdoc_options: []
47
+
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ version:
62
+ requirements: []
63
+
64
+ rubyforge_project:
65
+ rubygems_version: 1.3.5
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: Ruby wrapper for Google Buzz Atom Feeds
69
+ test_files: []
70
+