gnip_gnop 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +55 -0
- data/Rakefile +9 -0
- data/gnip_gnop.gemspec +23 -0
- data/lib/gnip_gnop/activity_actor.rb +13 -0
- data/lib/gnip_gnop/activity_author.rb +18 -0
- data/lib/gnip_gnop/activity_object.rb +14 -0
- data/lib/gnip_gnop/author.rb +8 -0
- data/lib/gnip_gnop/category.rb +10 -0
- data/lib/gnip_gnop/entry.rb +25 -0
- data/lib/gnip_gnop/link.rb +11 -0
- data/lib/gnip_gnop/matching_rule.rb +11 -0
- data/lib/gnip_gnop/service_provider.rb +13 -0
- data/lib/gnip_gnop/source.rb +11 -0
- data/lib/gnip_gnop/version.rb +3 -0
- data/lib/gnip_gnop.rb +14 -0
- data/test/fixtures/entry.xml +47 -0
- data/test/gnip_gnop_entry_test.rb +92 -0
- data/test/minitest_helper.rb +3 -0
- metadata +82 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Chris Kraybill
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# GnipGnop
|
2
|
+
|
3
|
+
A ruby library that given a Gnip activity stream XML <entry>, will
|
4
|
+
allow you to interact with that entry as a first-class Ruby object.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'gnip_gnop'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install gnip_gnop
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
The library assumes that you have a well formed activity stream
|
23
|
+
entry element (generally chunked in via a Gnip stream). You can
|
24
|
+
then parse that xml element like this:
|
25
|
+
|
26
|
+
> entry = GnipGnop::Entry.parse(xml)
|
27
|
+
|
28
|
+
Given this object reference, you can then "walk" the XML object's
|
29
|
+
hierarchy.
|
30
|
+
|
31
|
+
> entry.id
|
32
|
+
=> "tag:search.twitter.com,2005:180761363340197888"
|
33
|
+
|
34
|
+
Or, a more complex example:
|
35
|
+
|
36
|
+
> entry.author.name
|
37
|
+
=> "greeneyedtengu"
|
38
|
+
|
39
|
+
Where there were namespace conflicts (for example there is an
|
40
|
+
<author> element as well as a namespaced author element, e.g.
|
41
|
+
<activity:author>, in which cases I camelcased the accessor.
|
42
|
+
|
43
|
+
So for example the activity author has an id, which can be
|
44
|
+
accessed like:
|
45
|
+
|
46
|
+
> entry.activity_author.id
|
47
|
+
=> "http://twitter.com/greeneyedtengu"
|
48
|
+
|
49
|
+
## Contributing
|
50
|
+
|
51
|
+
1. Fork it
|
52
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
53
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
54
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
55
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/gnip_gnop.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/gnip_gnop/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Chris Kraybill"]
|
6
|
+
gem.email = ["ckraybill@gmail.com"]
|
7
|
+
gem.description = %q{A ruby library that given a Gnip activity
|
8
|
+
stream XML <entry>, will allow you to
|
9
|
+
interact with that entry as a first-class
|
10
|
+
Ruby object.}
|
11
|
+
gem.summary = %q{Work with Gnip activity streams with joy}
|
12
|
+
gem.homepage = "https://www.github.com/ckraybill/gnip_gnop"
|
13
|
+
|
14
|
+
gem.files = `git ls-files`.split($\)
|
15
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
16
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
|
+
gem.name = "gnip_gnop"
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency 'happymapper'
|
21
|
+
|
22
|
+
gem.version = GnipGnop::VERSION
|
23
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module GnipGnop
|
2
|
+
class ActivityActor
|
3
|
+
include HappyMapper
|
4
|
+
|
5
|
+
tag 'actor'
|
6
|
+
|
7
|
+
namespace 'http://activitystrea.ms/spec/1.0/'
|
8
|
+
|
9
|
+
element :object_type, String, :tag => 'object-type'
|
10
|
+
has_many :links, Link
|
11
|
+
element :id, String, :namespace => 'http://www.w3.org/2005/Atom'
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module GnipGnop
|
2
|
+
class ActivityAuthor
|
3
|
+
include HappyMapper
|
4
|
+
|
5
|
+
tag 'author'
|
6
|
+
|
7
|
+
def avatar_image
|
8
|
+
avatar_link = links.detect { |l| l.rel == 'avatar' }
|
9
|
+
avatar_link ? avatar_link.href : ''
|
10
|
+
end
|
11
|
+
|
12
|
+
namespace 'http://activitystrea.ms/spec/1.0/'
|
13
|
+
|
14
|
+
element :object_type, String, :tag => 'object-type'
|
15
|
+
has_many :links, Link
|
16
|
+
element :id, String, :namespace => 'http://www.w3.org/2005/Atom'
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module GnipGnop
|
2
|
+
class ActivityObject
|
3
|
+
include HappyMapper
|
4
|
+
|
5
|
+
tag 'object'
|
6
|
+
|
7
|
+
namespace 'http://activitystrea.ms/spec/1.0/'
|
8
|
+
|
9
|
+
element :object_type, String, :tag => 'object-type'
|
10
|
+
element :id, String, :namespace => 'http://www.w3.org/2005/Atom'
|
11
|
+
element :content, String, :attributes => { :type => String }, :namespace => 'http://www.w3.org/2005/Atom'
|
12
|
+
has_one :link, Link
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module GnipGnop
|
2
|
+
class Entry
|
3
|
+
include HappyMapper
|
4
|
+
|
5
|
+
tag 'entry'
|
6
|
+
|
7
|
+
namespace 'http://www.w3.org/2005/Atom'
|
8
|
+
|
9
|
+
element :id, String
|
10
|
+
element :published, DateTime
|
11
|
+
element :updated, DateTime
|
12
|
+
element :title, String
|
13
|
+
element :summary, String, :attributes => { :type => String }
|
14
|
+
has_many :categories, Category
|
15
|
+
has_one :link, Link
|
16
|
+
has_one :source, Source
|
17
|
+
has_one :service_provider, ServiceProvider
|
18
|
+
element :activity_verb, String, :tag => 'verb', :namespace => 'http://activitystrea.ms/spec/1.0/'
|
19
|
+
has_one :activity_object, ActivityObject
|
20
|
+
has_one :author, Author
|
21
|
+
has_one :activity_author, ActivityAuthor
|
22
|
+
has_one :activity_actor, ActivityActor
|
23
|
+
has_one :matching_rule, MatchingRule
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module GnipGnop
|
2
|
+
class ServiceProvider
|
3
|
+
include HappyMapper
|
4
|
+
|
5
|
+
tag 'provider'
|
6
|
+
|
7
|
+
namespace 'http://activitystrea.ms/service-provider'
|
8
|
+
|
9
|
+
element :name, String, :namespace => 'http://www.w3.org/2005/Atom'
|
10
|
+
element :uri, String, :namespace => 'http://www.w3.org/2005/Atom'
|
11
|
+
element :icon, String, :namespace => 'http://www.w3.org/2005/Atom'
|
12
|
+
end
|
13
|
+
end
|
data/lib/gnip_gnop.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'gnip_gnop/version'
|
2
|
+
|
3
|
+
require 'happymapper'
|
4
|
+
|
5
|
+
require 'gnip_gnop/link'
|
6
|
+
require 'gnip_gnop/category'
|
7
|
+
require 'gnip_gnop/author'
|
8
|
+
require 'gnip_gnop/source'
|
9
|
+
require 'gnip_gnop/service_provider'
|
10
|
+
require 'gnip_gnop/activity_object'
|
11
|
+
require 'gnip_gnop/activity_author'
|
12
|
+
require 'gnip_gnop/activity_actor'
|
13
|
+
require 'gnip_gnop/matching_rule'
|
14
|
+
require 'gnip_gnop/entry'
|
@@ -0,0 +1,47 @@
|
|
1
|
+
<entry xmlns:gnip="http://www.gnip.com/schemas/2010" xmlns="http://www.w3.org/2005/Atom">
|
2
|
+
<id>tag:search.twitter.com,2005:180761363340197888</id>
|
3
|
+
<published>2012-03-16T21:04:02Z</published>
|
4
|
+
<updated>2012-03-16T21:04:02Z</updated>
|
5
|
+
<title>greeneyedtengu (Robyn Omega) posted a note on Twitter</title>
|
6
|
+
<summary type="html">@redheadphotog Huh. Good luck hon. You know... Two apartments in our building will be vacant soon... D101 and D103...</summary>
|
7
|
+
<category term="StatusPosted" label="Status Posted"/>
|
8
|
+
<category term="NotePosted" label="Note Posted"/>
|
9
|
+
<link rel="alternate" type="text/html" href="http://twitter.com/greeneyedtengu/statuses/180761363340197888"/>
|
10
|
+
<source>
|
11
|
+
<link rel="self" type="application/atom+xml" href="http://search.twitter.com/search.atom?q=apartments&rpp=99&result_type=recent&since_id=180761625198993408"/>
|
12
|
+
<title>Twitter - Keyword - Notices - apartments</title>
|
13
|
+
<updated>2012-03-16T14-05-25Z</updated>
|
14
|
+
</source>
|
15
|
+
<service:provider xmlns:service="http://activitystrea.ms/service-provider">
|
16
|
+
<name>Twitter</name>
|
17
|
+
<uri>http://www.twitter.com/</uri>
|
18
|
+
<icon/>
|
19
|
+
</service:provider>
|
20
|
+
<activity:verb xmlns:activity="http://activitystrea.ms/spec/1.0/">http://activitystrea.ms/schema/1.0/post</activity:verb>
|
21
|
+
<activity:object xmlns:activity="http://activitystrea.ms/spec/1.0/">
|
22
|
+
<activity:object-type>http://activitystrea.ms
|
23
|
+
/schema/1.0/note</activity:object-type>
|
24
|
+
<id>object:tag:search.twitter.com,2005:180761363340197888</id>
|
25
|
+
<content type="html">@<a class=" " href="http://twitter.com/redheadphotog">redheadphotog</a> Huh. Good luck hon. You know... Two <em>apartments</em> in our building will be vacant soon... D101 and D103...</content>
|
26
|
+
<link rel="alternate" type="text/html" href="http://twitter.com/greeneyedtengu/statuses/180761363340197888"/>
|
27
|
+
</activity:object>
|
28
|
+
<author>
|
29
|
+
<name>greeneyedtengu</name>
|
30
|
+
<uri>http://twitter.com/greeneyedtengu</uri>
|
31
|
+
</author>
|
32
|
+
<activity:author xmlns:activity="http://activitystrea.ms/spec/1.0/">
|
33
|
+
<activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
|
34
|
+
<link rel="alternate" type="text/html" length="0" href="http://twitter.com/greeneyedtengu"/>
|
35
|
+
<link rel="avatar" type="image/png" href="http://a0.twimg.com/profile_images/1886588117/profile_normal.jpg"/>
|
36
|
+
<id>http://twitter.com/greeneyedtengu</id>
|
37
|
+
</activity:author>
|
38
|
+
<activity:actor xmlns:activity="http://activitystrea.ms/spec/1.0/">
|
39
|
+
<activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
|
40
|
+
<link rel="alternate" type="text/html" length="0" href="http://twitter.com/greeneyedtengu"/>
|
41
|
+
<link rel="avatar" type="image/png" href="http://a0.twimg.com/profile_images/1886588117/profile_normal.jpg"/>
|
42
|
+
<id>http://twitter.com/greeneyedtengu</id>
|
43
|
+
</activity:actor>
|
44
|
+
<gnip:matching_rules>
|
45
|
+
<gnip:matching_rule rel="source">apartments</gnip:matching_rule>
|
46
|
+
</gnip:matching_rules>
|
47
|
+
</entry>
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'minitest_helper'
|
2
|
+
|
3
|
+
describe GnipGnop::Entry do
|
4
|
+
|
5
|
+
def xml
|
6
|
+
@xml ||= File.read(File.expand_path('../fixtures/entry.xml', __FILE__))
|
7
|
+
end
|
8
|
+
|
9
|
+
before do
|
10
|
+
@entry = GnipGnop::Entry.parse(xml)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should parse a top-level element" do
|
14
|
+
@entry.id.must_equal "tag:search.twitter.com,2005:180761363340197888"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should parse the summary's text" do
|
18
|
+
@entry.summary.must_equal "@redheadphotog Huh. Good luck hon. You know... Two apartments in our building will be vacant soon... D101 and D103..."
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should parse the summary's type attribute" do
|
22
|
+
@entry.summary.type.must_equal 'html'
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should parse the entry's link's href" do
|
26
|
+
@entry.link.href.must_equal "http://twitter.com/greeneyedtengu/statuses/180761363340197888"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should parse the entry's source's link's href" do
|
30
|
+
@entry.source.link.href.must_equal "http://search.twitter.com/search.atom?q=apartments&rpp=99&result_type=recent&since_id=180761625198993408"
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should parse the entry's source's title" do
|
34
|
+
@entry.source.title.must_equal "Twitter - Keyword - Notices - apartments"
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should parse the entry's provider" do
|
38
|
+
@entry.service_provider.name.must_equal "Twitter"
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should parse the entry's verb" do
|
42
|
+
@entry.activity_verb.must_equal "http://activitystrea.ms/schema/1.0/post"
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should parse the entry's object's link's href" do
|
46
|
+
@entry.activity_object.link.href.must_equal "http://twitter.com/greeneyedtengu/statuses/180761363340197888"
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should parse the entry's object's id" do
|
50
|
+
@entry.activity_object.id.must_equal "object:tag:search.twitter.com,2005:180761363340197888"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should parse the author's name" do
|
54
|
+
@entry.author.name.must_equal "greeneyedtengu"
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should parse the namespaced author's namespaced object-type" do
|
58
|
+
@entry.activity_author.object_type.must_equal "http://activitystrea.ms/schema/1.0/person"
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should parse the namespaced author's differently namespaced id" do
|
62
|
+
@entry.activity_author.id.must_equal "http://twitter.com/greeneyedtengu"
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should parse the namespaced author's avatar image" do
|
66
|
+
@entry.activity_author.avatar_image.must_equal "http://a0.twimg.com/profile_images/1886588117/profile_normal.jpg"
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should parse the namespaced author's links into an arrary" do
|
70
|
+
@entry.activity_author.links.must_be_kind_of Array
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should parse all of the namespaced author's links" do
|
74
|
+
@entry.activity_author.links.size.must_equal 2
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should parse the namespaced actor's differently namespaced id" do
|
78
|
+
@entry.activity_actor.id.must_equal "http://twitter.com/greeneyedtengu"
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should parse the namespaced actor's links into an arrary" do
|
82
|
+
@entry.activity_actor.links.must_be_kind_of Array
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should parse all of the namespaced actor's links" do
|
86
|
+
@entry.activity_actor.links.size.must_equal 2
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should parse the matching rules" do
|
90
|
+
@entry.matching_rule.rule.must_equal "apartments"
|
91
|
+
end
|
92
|
+
end
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gnip_gnop
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Chris Kraybill
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-21 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: happymapper
|
16
|
+
requirement: &70126788536440 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70126788536440
|
25
|
+
description: ! "A ruby library that given a Gnip activity\n stream
|
26
|
+
XML <entry>, will allow you to\n interact with that entry
|
27
|
+
as a first-class\n Ruby object."
|
28
|
+
email:
|
29
|
+
- ckraybill@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- .gitignore
|
35
|
+
- Gemfile
|
36
|
+
- LICENSE
|
37
|
+
- README.md
|
38
|
+
- Rakefile
|
39
|
+
- gnip_gnop.gemspec
|
40
|
+
- lib/gnip_gnop.rb
|
41
|
+
- lib/gnip_gnop/activity_actor.rb
|
42
|
+
- lib/gnip_gnop/activity_author.rb
|
43
|
+
- lib/gnip_gnop/activity_object.rb
|
44
|
+
- lib/gnip_gnop/author.rb
|
45
|
+
- lib/gnip_gnop/category.rb
|
46
|
+
- lib/gnip_gnop/entry.rb
|
47
|
+
- lib/gnip_gnop/link.rb
|
48
|
+
- lib/gnip_gnop/matching_rule.rb
|
49
|
+
- lib/gnip_gnop/service_provider.rb
|
50
|
+
- lib/gnip_gnop/source.rb
|
51
|
+
- lib/gnip_gnop/version.rb
|
52
|
+
- test/fixtures/entry.xml
|
53
|
+
- test/gnip_gnop_entry_test.rb
|
54
|
+
- test/minitest_helper.rb
|
55
|
+
homepage: https://www.github.com/ckraybill/gnip_gnop
|
56
|
+
licenses: []
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 1.8.10
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: Work with Gnip activity streams with joy
|
79
|
+
test_files:
|
80
|
+
- test/fixtures/entry.xml
|
81
|
+
- test/gnip_gnop_entry_test.rb
|
82
|
+
- test/minitest_helper.rb
|