buzzr 0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Changelog ADDED
@@ -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.
data/README.md ADDED
@@ -0,0 +1,66 @@
1
+ Buzzr
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 buzzr
12
+
13
+ Buzzr is hosted on the Gemcutter repository. It depends on the RAtom library - http://github.com/seangeo/ratom
14
+
15
+ Example
16
+ -------
17
+
18
+ require 'buzzr'
19
+
20
+ feed_url = Buzzr::Feed.discover("conorhunt")
21
+ feed = Buzzr::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
data/lib/basic.rb ADDED
@@ -0,0 +1,44 @@
1
+ require 'rubygems'
2
+ require 'buzzr'
3
+
4
+ feed_url = Buzzr::Feed.discover(ARGV[0])
5
+ feed = Buzzr::Feed.retrieve(feed_url)
6
+
7
+ feed.entries.each do |entry|
8
+ puts "Title: #{entry.title}"
9
+ puts "Author: #{entry.author.name}"
10
+ puts "Comment Count: #{entry.comment_count}"
11
+ puts "Content"
12
+ puts entry.content
13
+ puts
14
+
15
+ if entry.urls.length > 0
16
+ puts "Links"
17
+ entry.urls.each {|u| puts "URI: #{u}" }
18
+ puts
19
+ end
20
+
21
+ if entry.images.length > 0
22
+ puts "Images"
23
+ entry.images.each {|i| puts "URI: #{i}" }
24
+ puts
25
+ end
26
+
27
+ if entry.videos.length > 0
28
+ puts "Videos"
29
+ entry.videos.each {|v| puts "URI: #{v}" }
30
+ puts
31
+ end
32
+
33
+ if entry.comment_count > 0
34
+ puts "Comments"
35
+ puts
36
+ entry.comments.each do |comment|
37
+ puts "Author: #{comment.author.name}"
38
+ puts "#{comment.content}"
39
+ puts
40
+ end
41
+ end
42
+ puts "------"
43
+ puts
44
+ end
data/lib/buzzr.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+ require 'atom'
3
+ require 'open-uri'
4
+ require 'buzzr/feed'
5
+ require 'buzzr/feed_entry'
6
+ require 'buzzr/feed_reply'
data/lib/buzzr/feed.rb ADDED
@@ -0,0 +1,49 @@
1
+ module Buzzr
2
+ class FeedError < Exception; end;
3
+
4
+ class Feed
5
+ attr :feed_url
6
+ attr :atom_feed
7
+
8
+ def initialize(feed_url, options = {})
9
+ @feed_url = feed_url
10
+ end
11
+
12
+ def self.retrieve(feed_url)
13
+ feed = Feed.new(feed_url)
14
+ feed.fetch
15
+ feed
16
+ end
17
+
18
+ # Extract the feed url from the users's google profile page
19
+ def self.discover(profile_name)
20
+ begin
21
+ page = open("http://www.google.com/profiles/#{profile_name}").read
22
+ rescue OpenURI::HTTPError => e
23
+ if e.io.status[0] == '404'
24
+ raise FeedError, "Could not find profile for #{profile_name} at - http://www.google.com/profiles/#{profile_name}"
25
+ end
26
+ end
27
+
28
+ if match = page.match(%r{<link rel="alternate" type="application/atom\+xml" href="([^"]+)})
29
+ match[1]
30
+ else
31
+ raise FeedError, "Could not find atom feed on profile page"
32
+ end
33
+ end
34
+
35
+ # Retrieve and parse the buzz atom feed
36
+ def fetch
37
+ @feed_entries = nil
38
+ @atom_feed = Atom::Feed.load_feed(URI.parse(@feed_url))
39
+ end
40
+
41
+ # Retrieve the entries in the buzz atom feed as an array of FeedEntry objects
42
+ # This will fetch the feed if it has not already been fetched
43
+ def entries
44
+ return @feed_entries if @feed_entries
45
+ fetch if @atom_feed.nil?
46
+ @feed_entries = @atom_feed.entries.collect {|e| FeedEntry.new(e) }
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,52 @@
1
+ module Buzzr
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 Buzzr
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,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: buzzr
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/basic.rb
38
+ - lib/buzzr/feed.rb
39
+ - lib/buzzr/feed_entry.rb
40
+ - lib/buzzr/feed_reply.rb
41
+ - lib/buzzr.rb
42
+ has_rdoc: true
43
+ homepage: http://github.com/conorh/buzzr
44
+ licenses: []
45
+
46
+ post_install_message:
47
+ rdoc_options: []
48
+
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ requirements: []
64
+
65
+ rubyforge_project:
66
+ rubygems_version: 1.3.5
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: Ruby wrapper for Google Buzz atom feeds
70
+ test_files: []
71
+