titi 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.textile CHANGED
@@ -1,6 +1,83 @@
1
- = titi
1
+ h1. titi: Agile Monkeying around with Activity Streams
2
+
3
+ Titi is a first stab at a universal ActivityStream interface.
4
+
5
+ h3. BUGS:
6
+
7
+ * The XML output isn't activity stream format: needs namespaces, much more
8
+
9
+
10
+ h3. Example
11
+
12
+ <pre><code>
13
+
14
+ class Titi::Provider::Twitter::Status
15
+ def to_activity_stream_entry
16
+ ActivityStreams::Entry.adapt(
17
+ :id => %Q{tag:twitter.com,2007:http://twitter.com/#{user.screen_name}/statuses/#{id}},
18
+ :title => text,
19
+ :content => text,
20
+ :published => created_at,
21
+ :verb => :post
22
+ ) do |entry|
23
+ entry.author = ActivityStreams::Author.new(user.name, user.url)
24
+ entry.object = ActivityStreams::ActivityObject.adapt do |activity_obj|
25
+ activity_obj.id = id
26
+ activity_obj.title = text
27
+ activity_obj.published = created_at
28
+ activity_obj.updated = created_at
29
+ activity_obj.author = entry.author
30
+ end
31
+ end
32
+ end
33
+
34
+ tweet = Twitter::Status.get(12233609555)
35
+ entry = tweet.to_activity_stream_entry
36
+
37
+ puts entry.to_xml
38
+
39
+ <?xml version="1.0" encoding="UTF-8"?>
40
+ <entry>
41
+ <verb type="symbol">post</verb>
42
+ <mood nil="true"></mood>
43
+ <category nil="true"></category>
44
+ <author>
45
+ <name>Sockamillion</name>
46
+ <uri>http://www.sockington.org/</uri>
47
+ </author>
48
+ <title>THANK GOODNESS THE LIBRARY OF CONGRESS HAS UNDERSTOOD THE IMPORTANCE OF MY TWEETS what do you mean others are getting in too</title>
49
+ <actor nil="true"></actor>
50
+ <published type="datetime">2010-04-15T17:01:52+00:00</published>
51
+ <rank nil="true"></rank>
52
+ <sync nil="true"></sync>
53
+ <id>tag:twitter.com,2007:http://twitter.com/sockington/statuses/12233609555</id>
54
+ <content>THANK GOODNESS THE LIBRARY OF CONGRESS HAS UNDERSTOOD THE IMPORTANCE OF MY TWEETS what do you mean others are getting in too</content>
55
+ <target nil="true"></target>
56
+ <link nil="true"></link>
57
+ <object>
58
+ <author>
59
+ <name>Sockamillion</name>
60
+ <uri>http://www.sockington.org/</uri>
61
+ </author>
62
+ <title>THANK GOODNESS THE LIBRARY OF CONGRESS HAS UNDERSTOOD THE IMPORTANCE OF MY TWEETS what do you mean others are getting in too</title>
63
+ <published>Thu Apr 15 17:01:52 +0000 2010</published>
64
+ <id type="integer">12233609555</id>
65
+ <vevent nil="true"></vevent>
66
+ <content nil="true"></content>
67
+ <link nil="true"></link>
68
+ <updated>Thu Apr 15 17:01:52 +0000 2010</updated>
69
+ <object-type nil="true"></object-type>
70
+ </object>
71
+ <source nil="true"></source>
72
+ <updated nil="true"></updated>
73
+ </entry>
74
+
75
+
76
+ p tweet
77
+
78
+ {"truncated"=>false, "favorited"=>false, "created_at"=>"Thu Apr 15 17:01:52 +0000 2010", "text"=>"THANK GOODNESS THE LIBRARY OF CONGRESS HAS UNDERSTOOD THE IMPORTANCE OF MY TWEETS what do you mean others are getting in too", "id"=>12233609555, "in_reply_to_user_id"=>nil, "in_reply_to_screen_name"=>nil, "source"=>"<a href=\"http://apiwiki.twitter.com/\" rel=\"nofollow\">API</a>", "user"=>#<struct Titi::Provider::Twitter::User id=1468401, screen_name="sockington", protected=false, followers_count=1520814, friends_count=457, statuses_count=6234, favourites_count=2, created_at=Mon, 19 Mar 2007 03:45:00 +0000, name="Sockamillion", url="http://www.sockington.org/", location="Waltham, MA", description="I am Jason Scott's Cat.", time_zone="Eastern Time (US & Canada)", utc_offset=-18000, profile_background_color="48484c", profile_text_color="000000", profile_link_color="000000", profile_sidebar_border_color="79c021", profile_sidebar_fill_color="585e7e", profile_background_tile=false, profile_background_image_url="http://a1.twimg.com/profile_background_images/6682718/SocksTwitter.jpg", profile_image_url="http://a3.twimg.com/profile_images/77537329/IMG_3738_normal.JPG">, "in_reply_to_status_id"=>nil}
79
+ </code></pre>
2
80
 
3
- Description goes here.
4
81
 
5
82
  == Note on Patches/Pull Requests
6
83
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'restclient'
4
+ require 'json'
5
+ require 'active_support'
6
+
7
+ TITI_DIR = File.dirname(File.expand_path(__FILE__+'/..')) unless defined?(TITI_DIR)
8
+ $: << TITI_DIR+'/lib' unless $:.include?(TITI_DIR+'/lib')
9
+
10
+ require 'titi'
11
+ require 'titi/provider/twitter'
12
+ include Titi::Provider
13
+
14
+ tweet = Twitter::Status.get(12233609555)
15
+ entry = tweet.to_activity_stream_entry
16
+
17
+ p tweet.to_hash
18
+ puts entry.to_xml
@@ -19,6 +19,20 @@ module Titi
19
19
  end
20
20
  end
21
21
 
22
+ Feed = Struct.new(
23
+ :entry
24
+ )
25
+ Feed.class_eval do
26
+ include Titi::Adaptor
27
+ include Titi::Provider::ActivityStreams::Common
28
+
29
+ def adapt objs
30
+ self.entry = objs.map do |obj|
31
+ obj.to_activity_stream_entry
32
+ end
33
+ end
34
+ end
35
+
22
36
  # An ActivityStream entry
23
37
  # http://activitystrea.ms/spec/1.0/atom-activity-01.html#activityentries
24
38
  Entry = Struct.new(
@@ -56,10 +56,8 @@ module Titi::Provider
56
56
  # end
57
57
 
58
58
  def created_at= date_time
59
- p [:created_at, date_time]
60
59
  unless date_time.is_a?(DateTime)
61
60
  dt = DateTime.parse(date_time) rescue nil
62
- p dt
63
61
  end
64
62
  self[:created_at] = dt
65
63
  end
@@ -93,10 +91,27 @@ module Titi::Provider
93
91
  include Titi::Provider
94
92
  include Titi::Adaptor
95
93
 
94
+ # virtual setter for user: If argument is not a Twitter::User, adapt it to
95
+ # be a user (assuming it is a hash or a hash_like.
96
96
  def user= new_user
97
- new_user = Twitter::User.from_hash(new_user.to_hash) unless new_user.is_a?(Twitter::User)
97
+ new_user = Twitter::User.adapt(new_user.to_hash) unless new_user.is_a?(Twitter::User)
98
98
  self[:user] = new_user
99
99
  end
100
+
101
+
102
+ # Call the twitter API and fetch tweet with given ID
103
+ #
104
+ # @example
105
+ # tweet = Status.get(12233609555)
106
+ # tweet.text
107
+ # #=> "THANK GOODNESS THE LIBRARY OF CONGRESS HAS UNDERSTOOD THE IMPORTANCE OF MY TWEETS what do you mean others are getting in too"
108
+ #
109
+ def self.get status_id
110
+ raw_json_str = RestClient.get "http://twitter.com/statuses/show/#{status_id}.json"
111
+ # raw_json_str = %q{{"created_at":"Mon Mar 19 21:08:24 +0000 2007","profile_sidebar_fill_color":"ffffff","description":"Founder, http://infochimps.org - Building tools to Organize, Explore and Comprehend massive data sources","verified":false,"time_zone":"Central Time (US & Canada)","status":{"in_reply_to_status_id":null,"created_at":"Sat Apr 17 05:47:28 +0000 2010","favorited":false,"in_reply_to_user_id":null,"source":"<a href=\"http://www.atebits.com/\" rel=\"nofollow\">Tweetie</a>","id":12327261220,"in_reply_to_screen_name":null,"truncated":false,"text":"Hacking Activity Streams yay"},"following":null,"profile_sidebar_border_color":"f0edd8","url":"http://infochimps.org","profile_image_url":"http://a3.twimg.com/profile_images/377919497/FlipCircle-2009-900-trans_normal.png","notifications":null,"followers_count":1061,"profile_background_color":"BCC0C8","location":"iPhone: 30.316122,-97.733817","screen_name":"mrflip","profile_background_image_url":"http://a3.twimg.com/profile_background_images/2348065/2005Mar-AustinTypeTour-075_-_Rappers_Delight_Raindrop.jpg","friends_count":754,"statuses_count":1744,"profile_text_color":"000000","protected":false,"profile_background_tile":false,"favourites_count":98,"name":"Philip Flip Kromer","contributors_enabled":false,"profile_link_color":"0000ff","id":1554031,"lang":"en","geo_enabled":true,"utc_offset":-21600}}
112
+ raw_status = JSON.load(raw_json_str.to_s)
113
+ adapt(raw_status)
114
+ end
100
115
  end
101
116
  end
102
117
  end
data/lib/titi/provider.rb CHANGED
@@ -1,8 +1,9 @@
1
+ require 'wukong'
1
2
  module Titi
2
3
  module Provider
3
4
  autoload :ActivityStreams, 'titi/provider/activity_streams'
4
5
  #
5
- autoload :Twitter , 'titi/provider/twitter'
6
+ autoload :Twitter , 'titi/provider/twitter'
6
7
  # autoload :Gowalla , 'titi/provider/gowalla'
7
8
  # autoload :Foursquare, 'titi/provider/foursquare'
8
9
  # autoload :Tripit , 'titi/provider/tripit'
data/titi.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{titi}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["mrflip"]
@@ -23,6 +23,7 @@ Gem::Specification.new do |s|
23
23
  "README.textile",
24
24
  "Rakefile",
25
25
  "VERSION",
26
+ "examples/twitter.rb",
26
27
  "lib/titi.rb",
27
28
  "lib/titi/adaptor.rb",
28
29
  "lib/titi/matcher.rb",
@@ -32,7 +33,6 @@ Gem::Specification.new do |s|
32
33
  "lib/titi/provider/activity_streams.rb",
33
34
  "lib/titi/provider/tripit.rb",
34
35
  "lib/titi/provider/twitter.rb",
35
- "lib/titi/provider/twitter/example.rb",
36
36
  "lib/titi/provider/twitter/models.rb",
37
37
  "notes/jeweler-gen.sh",
38
38
  "spec/spec.opts",
@@ -47,7 +47,8 @@ Gem::Specification.new do |s|
47
47
  s.summary = %q{Emit and consume Activity Streams from a wide variety of sources}
48
48
  s.test_files = [
49
49
  "spec/spec_helper.rb",
50
- "spec/titi_spec.rb"
50
+ "spec/titi_spec.rb",
51
+ "examples/twitter.rb"
51
52
  ]
52
53
 
53
54
  if s.respond_to? :specification_version then
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - mrflip
@@ -101,6 +101,7 @@ files:
101
101
  - README.textile
102
102
  - Rakefile
103
103
  - VERSION
104
+ - examples/twitter.rb
104
105
  - lib/titi.rb
105
106
  - lib/titi/adaptor.rb
106
107
  - lib/titi/matcher.rb
@@ -110,7 +111,6 @@ files:
110
111
  - lib/titi/provider/activity_streams.rb
111
112
  - lib/titi/provider/tripit.rb
112
113
  - lib/titi/provider/twitter.rb
113
- - lib/titi/provider/twitter/example.rb
114
114
  - lib/titi/provider/twitter/models.rb
115
115
  - notes/jeweler-gen.sh
116
116
  - spec/spec.opts
@@ -150,3 +150,4 @@ summary: Emit and consume Activity Streams from a wide variety of sources
150
150
  test_files:
151
151
  - spec/spec_helper.rb
152
152
  - spec/titi_spec.rb
153
+ - examples/twitter.rb
@@ -1,11 +0,0 @@
1
- require 'restclient'
2
- require 'json'
3
- require 'titi'
4
- require 'wukong'
5
- require 'active_support'
6
-
7
- # Dir['./**/*.rb'].each{|req| load req }^
8
- # $raw_json_str = RestClient.get 'http://twitter.com/users/show/mrflip.json'
9
- $raw_json_str = %q{{"created_at":"Mon Mar 19 21:08:24 +0000 2007","profile_sidebar_fill_color":"ffffff","description":"Founder, http://infochimps.org - Building tools to Organize, Explore and Comprehend massive data sources","verified":false,"time_zone":"Central Time (US & Canada)","status":{"in_reply_to_status_id":null,"created_at":"Sat Apr 17 05:47:28 +0000 2010","favorited":false,"in_reply_to_user_id":null,"source":"<a href=\"http://www.atebits.com/\" rel=\"nofollow\">Tweetie</a>","id":12327261220,"in_reply_to_screen_name":null,"truncated":false,"text":"Hacking Activity Streams yay"},"following":null,"profile_sidebar_border_color":"f0edd8","url":"http://infochimps.org","profile_image_url":"http://a3.twimg.com/profile_images/377919497/FlipCircle-2009-900-trans_normal.png","notifications":null,"followers_count":1061,"profile_background_color":"BCC0C8","location":"iPhone: 30.316122,-97.733817","screen_name":"mrflip","profile_background_image_url":"http://a3.twimg.com/profile_background_images/2348065/2005Mar-AustinTypeTour-075_-_Rappers_Delight_Raindrop.jpg","friends_count":754,"statuses_count":1744,"profile_text_color":"000000","protected":false,"profile_background_tile":false,"favourites_count":98,"name":"Philip Flip Kromer","contributors_enabled":false,"profile_link_color":"0000ff","id":1554031,"lang":"en","geo_enabled":true,"utc_offset":-21600}}
10
- $raw_user = JSON.load($raw_json_str.to_s)
11
- $user = Titi::Provider::Twitter::User.from_hash $raw_user