activity_streams 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Ruben Fonseca
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,35 @@
1
+ = activity_streams
2
+
3
+ Very early activitystream parser (http://activitystrea.ms/). The goal is to eat XML or JSON
4
+ descriptions of ActivityStreams and give a common interface to query the information on them.
5
+ More source formats may be included in the future.
6
+
7
+ Example usage:
8
+ require 'rubygems'
9
+ require 'activity_streams'
10
+ require 'open-uri'
11
+
12
+ twitter = 'http://api.cliqset.com/feed/?svcuser=rubenfonseca&feedid=twitternotesposted'
13
+ feed = ActivityStreams::Feed.from_xml(open(twitter).read)
14
+ feed.entries.size #=> 20
15
+ feed.entries.first.verbs.size #=> 1
16
+ feed.entries.first.verbs.first #=> "http://activitystrea.ms/schema/1.0/post"
17
+ ...
18
+
19
+ This module is in the very early stages, alpha quality :) Have fun!
20
+
21
+ If you have any question, start by looking into the _spec_ directory.
22
+
23
+ == Note on Patches/Pull Requests
24
+
25
+ * Fork the project.
26
+ * Make your feature addition or bug fix.
27
+ * Add tests for it. This is important so I don't break it in a
28
+ future version unintentionally.
29
+ * Commit, do not mess with rakefile, version, or history.
30
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
31
+ * Send me a pull request. Bonus points for topic branches.
32
+
33
+ == Copyright
34
+
35
+ Copyright (c) 2010 Ruben Fonseca. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,50 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "activity_streams"
8
+ gem.summary = %Q{Ruby module to eat and parse ActivityStreams in various formats}
9
+ gem.description = %Q{Ruby module to eat and parse ActivityStreams in various formats}
10
+ gem.email = "root@cpan.org"
11
+ gem.homepage = "http://github.com/rubenfonseca/activity_streams"
12
+ gem.authors = ["Ruben Fonseca"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ gem.add_development_dependency "yard", ">= 0"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+
17
+ gem.add_dependency "sax-machine", ">= 0.0.15"
18
+ gem.add_dependency "feedzirra"
19
+ gem.add_dependency "json"
20
+ gem.add_dependency "hashie"
21
+ end
22
+ Jeweler::GemcutterTasks.new
23
+ rescue LoadError
24
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
25
+ end
26
+
27
+ require 'spec/rake/spectask'
28
+ Spec::Rake::SpecTask.new(:spec) do |spec|
29
+ spec.libs << 'lib' << 'spec'
30
+ spec.spec_files = FileList['spec/**/*_spec.rb']
31
+ end
32
+
33
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
34
+ spec.libs << 'lib' << 'spec'
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :spec => :check_dependencies
40
+
41
+ task :default => :spec
42
+
43
+ begin
44
+ require 'yard'
45
+ YARD::Rake::YardocTask.new
46
+ rescue LoadError
47
+ task :yardoc do
48
+ abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
49
+ end
50
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,137 @@
1
+ require 'rubygems'
2
+ require 'feedzirra'
3
+ require 'json'
4
+ require 'hashie'
5
+
6
+ require 'activity_streams/feedzirra_patches'
7
+ require 'activity_streams/common_fields'
8
+ require 'activity_streams/portable_contact'
9
+
10
+ module ActivityStreams
11
+ class Object
12
+ include CommonFields
13
+ end
14
+
15
+ class Actor
16
+ include CommonFields
17
+ end
18
+
19
+ class Target
20
+ include CommonFields
21
+ end
22
+
23
+ class Context
24
+ include CommonFields
25
+ end
26
+
27
+ class Feed < Hashie::Dash
28
+ attr_accessor :entries
29
+ attr_accessor :raw_structure
30
+
31
+ # Creates a new Feed instance by parsing the XML string as an Atom feed with ActivityStreams
32
+ # extensions.
33
+ #
34
+ # @param [String] xml string representing an Atom feed with ActivityStreams extensions
35
+ # @return [Feed] a new instance filled with the data found on the XML string
36
+ def self.from_xml(xml)
37
+ unless defined?(@@_feedzirra_init)
38
+ @@_feedzirra_init = true
39
+ Feedzirra::Feed.add_common_feed_entry_elements("activity:verb", :as => :activity_verbs)
40
+ Feedzirra::Feed.add_common_feed_entry_elements("activity:object", :as => :activity_objects, :class => ActivityStreams::Object)
41
+ Feedzirra::Feed.add_common_feed_entry_element("activity:actor", :as => :activity_actor, :class => ActivityStreams::Actor)
42
+ Feedzirra::Feed.add_common_feed_entry_element("activity:target", :as => :activity_target, :class => ActivityStreams::Target)
43
+ Feedzirra::Feed.add_common_feed_entry_element("activity:context", :as => :activity_context, :class => ActivityStreams::Context)
44
+ end
45
+
46
+ res = Feed.new
47
+ res.raw_structure = Feedzirra::Feed.parse(xml)
48
+ res.entries = []
49
+
50
+ res.raw_structure.entries.each do |entry|
51
+ e = Hashie::Mash.new
52
+
53
+ # verbs
54
+ e.verbs = []
55
+ entry.activity_verbs.each do |verb|
56
+ e.verbs << verb
57
+ end
58
+
59
+ # actor, target, context
60
+ [:actor, :target, :context].each do |area|
61
+ e[:actor] ||= Hashie::Mash.new
62
+ e[:target] ||= Hashie::Mash.new
63
+ e[:context] ||= Hashie::Hash.new
64
+
65
+ [:id, :links, :object_types, :title, :author, :content].each do |attr|
66
+ unless entry.send("activity_#{area}").nil?
67
+ e.send(:[], area).send(:[]=, attr, entry.send("activity_#{area}").send(attr))
68
+ end
69
+ end
70
+ end
71
+
72
+ # objects
73
+ e.objects = []
74
+ entry.activity_objects.each do |object|
75
+ o = Hashie::Mash.new
76
+ [:id, :links, :object_types, :title, :author, :content].each do |attr|
77
+ o[attr] = object.send(attr)
78
+ end
79
+ e.objects << o
80
+ end
81
+
82
+ res.entries << e
83
+ end
84
+
85
+ return res
86
+ end
87
+
88
+ # Creates a new Feed instance by parsing the JSON string a list of JSON encoded ActivityStreams
89
+ #
90
+ # @param [String] json string representing a list of JSON encoded ActivityStreams
91
+ # @return [Feed] a new instance filled with the data found on the JSON string
92
+ def self.from_json(json)
93
+ res = Feed.new
94
+ res.raw_structure = JSON.parse(json)
95
+ res.entries = []
96
+
97
+ res.raw_structure.map { |x| x['activity'] }.delete_if(&:nil?).each do |entry|
98
+ e = Hashie::Mash.new
99
+
100
+ # verbs
101
+ e.verbs = []
102
+ entry['verbs'] && entry['verbs'].each do |verb|
103
+ e.verbs << verb
104
+ end
105
+
106
+ # actor, target, context
107
+ [:actor, :target, :context].each do |area|
108
+ e[:actor] ||= Hashie::Mash.new
109
+ e[:target] ||= Hashie::Mash.new
110
+ e[:context] ||= Hashie::Hash.new
111
+
112
+ [:id, :links, :object_types, :title, :author, :content].each do |attr|
113
+ unless entry.send(:[], area.to_s).nil?
114
+ json_attr = attr.to_s.gsub(/\_(\w)/) { $1.upcase }
115
+ e.send(:[], area).send(:[]=, attr, entry.send(:[], area.to_s).send(:[], json_attr))
116
+ end
117
+ end
118
+ end
119
+
120
+ # objects
121
+ e.objects = []
122
+ entry['objects'] && entry['objects'].each do |object|
123
+ o = Hashie::Mash.new
124
+ [:id, :links, :object_types, :title, :author, :content].each do |attr|
125
+ json_attr = attr.to_s.gsub(/\_(\w)/) { $1.upcase }
126
+ o[attr] = object.send(:[], json_attr)
127
+ end
128
+ e.objects << o
129
+ end
130
+
131
+ res.entries << e
132
+ end
133
+
134
+ return res
135
+ end
136
+ end
137
+ end
@@ -0,0 +1,153 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "ActivityStreams", "twitter" do
4
+ before :all do
5
+ @twitter_xml = IO.read(File.expand_path(File.dirname(__FILE__) + "/twitter.xml"))
6
+ @feed = ActivityStreams::Feed.from_xml(@twitter_xml)
7
+ end
8
+
9
+ it "should parse twitter example" do
10
+ @feed.should_not be_nil
11
+ end
12
+
13
+ it "should have 20 entries" do
14
+ @feed.entries.size.should == 20
15
+ end
16
+
17
+ it "should have a list of activity:verb on the first entry" do
18
+ verbs = @feed.entries.first.verbs
19
+ verbs.class.should == Array
20
+ verbs.size.should == 1
21
+ verbs.first.should =~ /post/
22
+ end
23
+
24
+ it "should have a list of activity:object on the first entry" do
25
+ objects = @feed.entries.first.objects
26
+ objects.class.should == Array
27
+ objects.size.should == 1
28
+ end
29
+
30
+ it "should parse a proper activity:object" do
31
+ object = @feed.entries.first.objects.first
32
+ object.object_types.size.should == 1
33
+ object.object_types.first.should =~ /note/
34
+ object.content.should == "rubenfonseca: @microft humm what about dropbox?"
35
+
36
+ object.links.size.should == 1
37
+ object.links.first.should == "http://twitter.com/rubenfonseca/statuses/9108531677"
38
+ end
39
+
40
+ it "should have an activity:actor on the first entry" do
41
+ object = @feed.entries.first.actor
42
+ object.should_not be_nil
43
+ end
44
+
45
+ it "should parse a proper activity:actor" do
46
+ object = @feed.entries.first.actor
47
+ object.object_types.size.should == 1
48
+ object.object_types.first.should =~ /person/
49
+ object.title.should == "rubenfonseca"
50
+ end
51
+ end
52
+
53
+ describe "ActivityStreams", "lastfm" do
54
+ before :all do
55
+ @lastfm_xml = IO.read(File.expand_path(File.dirname(__FILE__) + "/lastfm.xml"))
56
+ @feed = ActivityStreams::Feed.from_xml(@lastfm_xml)
57
+ end
58
+
59
+ it "should parse lastfm example" do
60
+ @feed.should_not be_nil
61
+ end
62
+
63
+ it "should have 10 entries" do
64
+ @feed.entries.size.should == 10
65
+ end
66
+
67
+ it "should have a list of activity:verb on the first entry" do
68
+ verbs = @feed.entries.first.verbs
69
+ verbs.class.should == Array
70
+ verbs.size.should == 1
71
+ verbs.first.should =~ /play/
72
+ end
73
+
74
+ it "should have a list of activity:object on the first entry" do
75
+ objects = @feed.entries.first.objects
76
+ objects.class.should == Array
77
+ objects.size.should == 1
78
+ end
79
+
80
+ it "should parse a proper activity:object" do
81
+ object = @feed.entries.first.objects.first
82
+ object.object_types.size.should == 1
83
+ object.object_types.first.should =~ /song/
84
+ object.title.should == "Sure Looks Good To Me"
85
+ object.author.should == "Alicia Keys"
86
+
87
+ object.links.size.should == 1
88
+ object.links.first.should == "http://www.last.fm/music/Alicia+Keys/_/Sure+Looks+Good+To+Me"
89
+ end
90
+
91
+ it "should have an activity:actor on the first entry" do
92
+ object = @feed.entries.first.actor
93
+ object.should_not be_nil
94
+ end
95
+
96
+ it "should parse a proper activity:actor" do
97
+ object = @feed.entries.first.actor
98
+ object.object_types.size.should == 1
99
+ object.object_types.first.should =~ /person/
100
+ object.title.should == "krani1"
101
+ end
102
+ end
103
+
104
+ describe ActivityStreams, "myspace" do
105
+ before :all do
106
+ @myspace_json = IO.read(File.expand_path(File.dirname(__FILE__) + "/myspace.json"))
107
+ @feed = ActivityStreams::Feed.from_json(@myspace_json)
108
+ end
109
+
110
+ it "should parse myspace example" do
111
+ @feed.should_not be_nil
112
+ end
113
+
114
+ it "should have 1 entry" do
115
+ @feed.entries.size.should == 1
116
+ end
117
+
118
+ it "should have a list of activity:verb on the first entry" do
119
+ verbs = @feed.entries.first.verbs
120
+ verbs.class.should == Array
121
+ verbs.size.should == 1
122
+ verbs.first.should =~ /post/
123
+ end
124
+
125
+ it "should have a list of activity:object on the first entry" do
126
+ objects = @feed.entries.first.objects
127
+ objects.class.should == Array
128
+ objects.size.should == 1
129
+ end
130
+
131
+ it "should parse a proper activity:object" do
132
+ object = @feed.entries.first.objects.first
133
+ object.object_types.size.should == 1
134
+ object.object_types.first.should =~ /photo/
135
+ object.title.should == ""
136
+ object.author.should == nil
137
+
138
+ object.links.size.should == 1
139
+ object.links.first.should == "http://c2.ac-images.myspacecdn.com/images02/6/s_be8bb90eebb4c8725724f66dcb9414f1.png"
140
+ end
141
+
142
+ it "should have an activity:actor on the first entry" do
143
+ object = @feed.entries.first.actor
144
+ object.should_not be_nil
145
+ end
146
+
147
+ it "should parse a proper activity:actor" do
148
+ object = @feed.entries.first.actor
149
+ object.object_types.size.should == 1
150
+ object.object_types.first.should =~ /person/
151
+ object.title.should == "Brandon Black"
152
+ end
153
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'activity_streams'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activity_streams
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Ruben Fonseca
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-23 00:00:00 +00:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.2.9
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: yard
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: sax-machine
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 0.0.15
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: feedzirra
47
+ type: :runtime
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ - !ruby/object:Gem::Dependency
56
+ name: json
57
+ type: :runtime
58
+ version_requirement:
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ - !ruby/object:Gem::Dependency
66
+ name: hashie
67
+ type: :runtime
68
+ version_requirement:
69
+ version_requirements: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
74
+ version:
75
+ description: Ruby module to eat and parse ActivityStreams in various formats
76
+ email: root@cpan.org
77
+ executables: []
78
+
79
+ extensions: []
80
+
81
+ extra_rdoc_files:
82
+ - LICENSE
83
+ - README.rdoc
84
+ files:
85
+ - .document
86
+ - .gitignore
87
+ - LICENSE
88
+ - README.rdoc
89
+ - Rakefile
90
+ - VERSION
91
+ - lib/activity_streams.rb
92
+ - spec/activity_streams_spec.rb
93
+ - spec/spec.opts
94
+ - spec/spec_helper.rb
95
+ has_rdoc: true
96
+ homepage: http://github.com/rubenfonseca/activity_streams
97
+ licenses: []
98
+
99
+ post_install_message:
100
+ rdoc_options:
101
+ - --charset=UTF-8
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: "0"
109
+ version:
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: "0"
115
+ version:
116
+ requirements: []
117
+
118
+ rubyforge_project:
119
+ rubygems_version: 1.3.5
120
+ signing_key:
121
+ specification_version: 3
122
+ summary: Ruby module to eat and parse ActivityStreams in various formats
123
+ test_files:
124
+ - spec/activity_streams_spec.rb
125
+ - spec/spec_helper.rb