titi 0.0.3 → 0.0.4

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
@@ -43,8 +43,8 @@ Titi lets you write a straightforward and compact adaptor to activity stream for
43
43
  :published => created_at,
44
44
  :verb => :post
45
45
  ) do |entry|
46
- entry.author = ActivityStreams::Author.new(user.name, user.url)
47
- entry.object = ActivityStreams::ActivityObject.adapt do |activity_obj|
46
+ entry.has_author user.name, user.url
47
+ entry.has_obj do |activity_obj|
48
48
  activity_obj.id = id
49
49
  activity_obj.title = text
50
50
  activity_obj.published = created_at
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
data/lib/titi/adaptor.rb CHANGED
@@ -18,33 +18,35 @@ module Titi
18
18
  # Adopt attributes from given hash, and programatically-set attributes from block
19
19
  #
20
20
  # @example
21
- # ActivityStreams::Entry.adapt(
22
- # :id => status.id,
23
- # :title => status.text,
24
- # :content => status.text,
25
- # :verb => :post
26
- # ) do |entry|
27
- # status_time = Time.parse(status.created_at) rescue nil
28
- # entry.published = status_time
29
- # entry.author = ActivityStreams::Author.new(:name => status.user.name, :url => status.user.url)
30
- # entry.object = ActivityStreams::Object.adapt do |activity_obj|
31
- # activity_obj.id = status.id
32
- # activity_obj.title = status.text
33
- # activity_obj.published = status_time
34
- # activity_obj.updated = status_time
35
- # activity_obj.author = ActivityStreams::Author.new(:name => status.user.name, :url => status.user.url)
36
- # end
37
- # end
38
- def adapt hsh={}, &block
39
- self.attributes = hsh
21
+ # ActivityStreams::Entry.adapt(
22
+ # :id => %Q{tag:twitter.com,2007:http://twitter.com/#{user.screen_name}/statuses/#{id}},
23
+ # :title => text,
24
+ # :content => text,
25
+ # :published => created_at,
26
+ # :verb => :post
27
+ # ) do |entry|
28
+ # entry.has_author user.name, user.url
29
+ # entry.has_obj do |activity_obj|
30
+ # activity_obj.id = id
31
+ # activity_obj.title = text
32
+ # activity_obj.published = created_at
33
+ # activity_obj.updated = created_at
34
+ # activity_obj.author = entry.author
35
+ # end
36
+ # end
37
+ def adapt *args, &block
38
+ hsh = args.extract_options!
39
+ args_hsh = Hash.zip(self.members[0...args.length], args)
40
+ self.attributes = hsh.merge(args_hsh)
40
41
  yield self if block
41
42
  end
42
43
 
43
44
  # The standard hack to construct class methods on a class that #include's this model
44
45
  module ClassMethods
45
46
  # created an object and then adopts from the given hash and block
46
- def adapt hsh={}, &block
47
- obj = self.new
47
+ def adapt *args, &block
48
+ hsh = args.extract_options!
49
+ obj = self.new *args
48
50
  obj.adapt(hsh, &block)
49
51
  obj
50
52
  end
@@ -17,6 +17,23 @@ module Titi
17
17
  hsh = self.to_hash
18
18
  hsh.to_xml :root => self.class.to_s.underscore.gsub(%r{.*/},'')
19
19
  end
20
+
21
+ def has_thingy thingy, *args, &block
22
+ thingy_klass = ('ActivityStreams::'+thingy.to_s.classify).constantize
23
+ thingy_setter = "#{thingy}="
24
+ p [thingy, thingy_klass, thingy_setter]
25
+ self.send(thingy_setter, thingy_klass.new) unless self.send(thingy)
26
+ self.send(thingy).adapt *args, &block
27
+ self.send(thingy)
28
+ end
29
+
30
+ def method_missing meth, *args, &block
31
+ if (meth.to_s =~ /has_(\w+)/) && (self.respond_to?("#{$1}="))
32
+ has_thingy $1, *args, &block
33
+ else
34
+ super
35
+ end
36
+ end
20
37
  end
21
38
 
22
39
  Feed = Struct.new(
@@ -26,9 +43,9 @@ module Titi
26
43
  include Titi::Adaptor
27
44
  include Titi::Provider::ActivityStreams::Common
28
45
 
29
- def adapt objs
30
- self.entry = objs.map do |obj|
31
- obj.to_activity_stream_entry
46
+ def adapt thingys
47
+ self.entry = thingys.map do |thingy|
48
+ thingy.to_activity_stream_entry
32
49
  end
33
50
  end
34
51
  end
@@ -52,7 +69,7 @@ module Titi
52
69
  :author, # author {"name"=>["misterflip"], "uri"=>["http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendid=24601"]}
53
70
  :mood, #
54
71
  :source,
55
- :object, # object
72
+ :obj, # object
56
73
  :target # target
57
74
  )
58
75
  Entry.class_eval do
@@ -78,9 +95,10 @@ module Titi
78
95
  end
79
96
  Author = Actor
80
97
 
81
- # ActivityStream object
98
+ # ActivityStream object.
99
+ # We can't call them 'Object' (ruby has a class like that already :)
82
100
  # http://activitystrea.ms/spec/1.0/atom-activity-01.html#activityobjectelement
83
- ActivityObject = Struct.new(
101
+ Obj = Struct.new(
84
102
  :id,
85
103
  :title,
86
104
  :content,
@@ -92,7 +110,7 @@ module Titi
92
110
  :object_type,
93
111
  :vevent
94
112
  )
95
- ActivityObject.class_eval do
113
+ Obj.class_eval do
96
114
  include Titi::Adaptor
97
115
  include Titi::Provider::ActivityStreams::Common
98
116
  end
@@ -0,0 +1,27 @@
1
+ <feed>
2
+ <entry>
3
+ <title><%= entry.title %></title>
4
+ <content type="html"><%= entry.content %></content>
5
+ <id><%= entry.id %></id>
6
+ <published><%= entry.published %></published>
7
+ <updated ><%= entry.updated %></updated>
8
+ <link type="text/html" rel="alternate" href="<%= entry.alt_link %>"/>
9
+ <link type="image/pjpeg" rel="image" href="<%= entry.img_link %>"/>
10
+ <author>
11
+ <name><%= entry.author.name %></name>
12
+ <uri><%= entry.author.url %></uri>
13
+ </author>
14
+ <activity:verb><%= entry.verb %></activity:verb>
15
+ <activity:object>
16
+ <id><%= entry.object.id %></id>
17
+ <title><%= entry.object.title %></title>
18
+ <link type="text/html" rel="alternate" href="<%= entry.object.alt_link %>"/>
19
+ <published><%= entry.object.published %></published>
20
+ <updated ><%= entry.object.updated %></updated>
21
+ <author>
22
+ <name><%= entry.object.author.name %></name>
23
+ <uri ><%= entry.object.author.url %></uri>
24
+ </author>
25
+ </activity:object>
26
+ </entry>
27
+ </feed>
@@ -39,8 +39,8 @@ module Titi::Provider
39
39
  :published => created_at,
40
40
  :verb => :post
41
41
  ) do |entry|
42
- entry.author = ActivityStreams::Author.new(user.name, user.url)
43
- entry.object = ActivityStreams::ActivityObject.adapt do |activity_obj|
42
+ entry.has_author user.name, user.url
43
+ entry.has_obj do |activity_obj|
44
44
  activity_obj.id = id
45
45
  activity_obj.title = text
46
46
  activity_obj.published = created_at
@@ -94,6 +94,7 @@ module Titi::Provider
94
94
  # virtual setter for user: If argument is not a Twitter::User, adapt it to
95
95
  # be a user (assuming it is a hash or a hash_like.
96
96
  def user= new_user
97
+ # return unless new_user
97
98
  new_user = Twitter::User.adapt(new_user.to_hash) unless new_user.is_a?(Twitter::User)
98
99
  self[:user] = new_user
99
100
  end
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.3"
8
+ s.version = "0.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["mrflip"]
@@ -33,6 +33,7 @@ Gem::Specification.new do |s|
33
33
  "lib/titi/provider.rb",
34
34
  "lib/titi/provider/README.textile",
35
35
  "lib/titi/provider/activity_streams.rb",
36
+ "lib/titi/provider/activity_streams/feed.xml.erb",
36
37
  "lib/titi/provider/tripit.rb",
37
38
  "lib/titi/provider/twitter.rb",
38
39
  "lib/titi/provider/twitter/models.rb",
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 3
9
- version: 0.0.3
8
+ - 4
9
+ version: 0.0.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - mrflip
@@ -111,6 +111,7 @@ files:
111
111
  - lib/titi/provider.rb
112
112
  - lib/titi/provider/README.textile
113
113
  - lib/titi/provider/activity_streams.rb
114
+ - lib/titi/provider/activity_streams/feed.xml.erb
114
115
  - lib/titi/provider/tripit.rb
115
116
  - lib/titi/provider/twitter.rb
116
117
  - lib/titi/provider/twitter/models.rb