chirpstream 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/Readme.rdoc CHANGED
@@ -6,7 +6,12 @@ This is an experimental EventMachine-based client for http://chirpstream.twitter
6
6
 
7
7
  == Fun Things You Can Do At Home
8
8
 
9
- Fire up the
9
+ Fire up the growl client!
10
+
11
+ sudo gem install chirpstream
12
+ chirp_growl
13
+
14
+ Wow! It's growling my tweets! How meta.
10
15
 
11
16
  == Usage
12
17
 
@@ -20,5 +25,6 @@ Fire up the
20
25
  chirp.follow {|t| puts "#{t.source.screen_name.foreground(:green)} following #{t.target.screen_name.foreground(:green)}" }
21
26
  chirp.favorite {|t| puts "#{t.source.screen_name.foreground(:green)} <3 -> #{t.target_object.text}" }
22
27
  chirp.retweet {|t| puts "#{t.source.screen_name.foreground(:green)} RT -> #{t.target_object.text}" }
28
+ chirp.direct_message {|t| puts "DM : #{t.text} (from #{t.sender.name.foreground(:red)} (#{('@' + t.sender.screen_name).foreground(:green)}))" }
23
29
  chirp.connect
24
30
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.5
1
+ 0.0.6
data/lib/chirpstream.rb CHANGED
@@ -9,6 +9,7 @@ $LOAD_PATH.add_current
9
9
  require 'chirpstream/twitter_object'
10
10
  require 'chirpstream/event'
11
11
  require 'chirpstream/event/follow'
12
+ require 'chirpstream/event/direct_message'
12
13
  require 'chirpstream/event/retweet'
13
14
  require 'chirpstream/event/favorite'
14
15
  require 'chirpstream/event/delete'
@@ -19,7 +20,7 @@ class Chirpstream
19
20
 
20
21
  attr_reader :handlers
21
22
 
22
- Handlers = Struct.new(:friend, :tweet, :follow, :favorite, :retweet, :delete, :reconnect)
23
+ Handlers = Struct.new(:friend, :tweet, :follow, :favorite, :retweet, :delete, :reconnect, :direct_message)
23
24
 
24
25
  attr_reader :username, :password
25
26
 
@@ -27,7 +28,7 @@ class Chirpstream
27
28
  @username = username
28
29
  @password = password
29
30
  @connect_url = "http://chirpstream.twitter.com/2b/user.json"
30
- @handlers = Handlers.new([], [], [], [], [], [], [])
31
+ @handlers = Handlers.new([], [], [], [], [], [], [], [])
31
32
  @data = ''
32
33
  end
33
34
 
@@ -51,6 +52,10 @@ class Chirpstream
51
52
  @handlers.retweet << block
52
53
  end
53
54
 
55
+ def direct_message(&block)
56
+ @handlers.direct_message << block
57
+ end
58
+
54
59
  def delete(&block)
55
60
  @handlers.delete << block
56
61
  end
@@ -68,7 +73,7 @@ class Chirpstream
68
73
  @handlers.friend.each{|h| h.call(friend)}
69
74
  end
70
75
  }
71
- friend_http = EM::HttpRequest.new("http://api.twitter.com/1/users/lookup.json").post(:body => {'user_id' => friend_ids.join(',')}, :head => {'authorization' => [@username, @password]})
76
+ friend_http = EM::HttpRequest.new("http://api.twitter.com/1/users/lookup.json").post(:body => {'user_id' => friend_ids.join(',')}, :head => {'authorization' => [@username, @password]}, :timeout => 0)
72
77
  http.stream { |chunk|
73
78
  parser << chunk
74
79
  }
@@ -94,6 +99,15 @@ class Chirpstream
94
99
  end
95
100
  end
96
101
 
102
+ def dispatch_direct_message(data)
103
+ unless @handlers.direct_message.empty?
104
+ dm = DirectMessage.new(self, data)
105
+ dm.load_all { |f|
106
+ @handlers.direct_message.each{|h| h.call(f)}
107
+ }
108
+ end
109
+ end
110
+
97
111
  def dispatch_favorite(data)
98
112
  unless @handlers.favorite.empty?
99
113
  favorite = Favorite.new(self, data)
@@ -127,7 +141,9 @@ class Chirpstream
127
141
  end
128
142
 
129
143
  def handle_tweet(parsed_data)
130
- if parsed_data['friends']
144
+ if parsed_data['direct_message']
145
+ dispatch_direct_message(parsed_data)
146
+ elsif parsed_data['friends']
131
147
  dispatch_friend(parsed_data)
132
148
  elsif parsed_data['text']
133
149
  dispatch_tweet(parsed_data)
@@ -163,7 +179,11 @@ class Chirpstream
163
179
  connect
164
180
  }
165
181
  http.stream { |chunk|
166
- parser << chunk
182
+ begin
183
+ parser << chunk
184
+ rescue Yajl::ParseError
185
+ puts "bad chunk: #{chunk.inspect}"
186
+ end
167
187
  }
168
188
  end
169
189
  end
@@ -0,0 +1,23 @@
1
+ class Chirpstream
2
+ class DirectMessage < TwitterObject
3
+
4
+ ATTRS = [:coordinates, :recipient, :sender, :sender_screen_name, :text, :id, :recipient_id, :sender_id]
5
+
6
+ attr_accessor *ATTRS
7
+ user_writer :sender
8
+
9
+ def initialize(base, data = nil)
10
+ @base = base
11
+ from_json(data['direct_message']) if data and data['direct_message']
12
+ yield self if block_given?
13
+ end
14
+
15
+ def tweet_loadable_id
16
+ id
17
+ end
18
+
19
+ def loaded?
20
+ !text.nil?
21
+ end
22
+ end
23
+ end
@@ -132,4 +132,4 @@ class TwitterObject
132
132
  }
133
133
  end
134
134
 
135
- end
135
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 5
9
- version: 0.0.5
8
+ - 6
9
+ version: 0.0.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - Joshua Hull
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-01 00:00:00 -04:00
17
+ date: 2010-05-19 00:00:00 -04:00
18
18
  default_executable: chirp_growl
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -91,6 +91,7 @@ files:
91
91
  - lib/chirpstream.rb
92
92
  - lib/chirpstream/event.rb
93
93
  - lib/chirpstream/event/delete.rb
94
+ - lib/chirpstream/event/direct_message.rb
94
95
  - lib/chirpstream/event/favorite.rb
95
96
  - lib/chirpstream/event/follow.rb
96
97
  - lib/chirpstream/event/retweet.rb