twitter4r 0.6.0 → 0.7.0
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/lib/twitter.rb +1 -5
- data/lib/twitter/client.rb +1 -0
- data/lib/twitter/client/base.rb +1 -2
- data/lib/twitter/client/status.rb +16 -1
- data/lib/twitter/client/trends.rb +23 -0
- data/lib/twitter/model.rb +120 -3
- data/lib/twitter/version.rb +1 -1
- data/spec/twitter/client/favorites_spec.rb +0 -4
- data/spec/twitter/client/status_spec.rb +10 -0
- data/spec/twitter/client/trends_spec.rb +51 -0
- data/spec/twitter/model_spec.rb +83 -64
- metadata +6 -22
data/lib/twitter.rb
CHANGED
@@ -8,7 +8,7 @@ def require_local(suffix)
|
|
8
8
|
end
|
9
9
|
|
10
10
|
# For better unicode support in 1.8
|
11
|
-
if RUBY_VERSION < '1.9'
|
11
|
+
if RUBY_VERSION < '1.9.0'
|
12
12
|
$KCODE = 'u'
|
13
13
|
require 'jcode'
|
14
14
|
end
|
@@ -23,10 +23,6 @@ require('cgi')
|
|
23
23
|
require('json')
|
24
24
|
require('oauth')
|
25
25
|
|
26
|
-
if RUBY_VERSION < "1.9.0"
|
27
|
-
require('yaml')
|
28
|
-
end
|
29
|
-
|
30
26
|
# Ordering matters...pay attention here!
|
31
27
|
require_local('twitter/ext')
|
32
28
|
require_local('twitter/version')
|
data/lib/twitter/client.rb
CHANGED
data/lib/twitter/client/base.rb
CHANGED
@@ -74,8 +74,7 @@ class Twitter::Client
|
|
74
74
|
key = access[:key] || access["key"]
|
75
75
|
secret = access[:secret] || access["secret"]
|
76
76
|
else
|
77
|
-
|
78
|
-
secret = ""
|
77
|
+
raise Error, "No access tokens are set"
|
79
78
|
end
|
80
79
|
@rest_access_token = OAuth::AccessToken.new(rest_consumer, key, secret)
|
81
80
|
end
|
@@ -23,12 +23,20 @@ class Twitter::Client
|
|
23
23
|
# twitter.status(:get, 107786772)
|
24
24
|
# twitter.status(:post, "New Ruby open source project Twitter4R version 0.2.0 released.")
|
25
25
|
# twitter.status(:delete, 107790712)
|
26
|
+
# twitter.status(:reply, :in_reply_to_status_id => 1390482942342, :status => "@t4ruby This new v0.7.0 release is da bomb! #ruby #twitterapi #twitter4r")
|
27
|
+
# twitter.status(:post, "My brand new status in all its glory here tweeted from Greenwich (the real one). #withawesomehashtag #booyah", :lat => 0, :long => 0)
|
26
28
|
#
|
27
29
|
# An <tt>ArgumentError</tt> will be raised if an invalid <tt>action</tt>
|
28
30
|
# is given. Valid actions are:
|
29
31
|
# * +:get+
|
30
32
|
# * +:post+
|
31
33
|
# * +:delete+
|
34
|
+
#
|
35
|
+
# The third argument +options+ sends on a Hash to the Twitter API with the following keys allowed:
|
36
|
+
# * +:lat+ - latitude (for posting geolocation)
|
37
|
+
# * +:long+ - longitude (for posting geolocation)
|
38
|
+
# * +:place_id+ - using a place ID give by geo/reverse_geocode
|
39
|
+
# * +:display_coordinates+ - whether or not to put a pin in the exact coordinates
|
32
40
|
def status(action, value = nil)
|
33
41
|
return self.timeline_for(action, value || {}) if :replies == action
|
34
42
|
raise ArgumentError, "Invalid status action: #{action}" unless @@STATUS_URIS.keys.member?(action)
|
@@ -39,7 +47,14 @@ class Twitter::Client
|
|
39
47
|
when :get
|
40
48
|
response = rest_oauth_connect(:get, uri, {:id => value.to_i})
|
41
49
|
when :post
|
42
|
-
|
50
|
+
if value.is_a?(Hash)
|
51
|
+
params = value.delete_if { |k, v|
|
52
|
+
![:status, :lat, :long, :place_id, :display_coordinates].member?(k)
|
53
|
+
}
|
54
|
+
else
|
55
|
+
params = {:status => value}
|
56
|
+
end
|
57
|
+
response = rest_oauth_connect(:post, uri, params.merge(:source => self.class.config.source))
|
43
58
|
when :delete
|
44
59
|
response = rest_oauth_connect(:delete, uri, {:id => value.to_i})
|
45
60
|
when :reply
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class Twitter::Client
|
2
|
+
@@TRENDS_URIS = {
|
3
|
+
:locations => '/trends/available.json',
|
4
|
+
:global => '/trends.json',
|
5
|
+
:current => '/trends/current.json',
|
6
|
+
:daily => '/trends/daily.json',
|
7
|
+
:weekly => '/trends/weekly.json',
|
8
|
+
:local => '/trends/',
|
9
|
+
}
|
10
|
+
|
11
|
+
# Provides access to the Twitter list trends API.
|
12
|
+
#
|
13
|
+
# By default you will receive top ten topics that are trending on Twitter.
|
14
|
+
def trends(type = :global)
|
15
|
+
uri = @@TRENDS_URIS[type]
|
16
|
+
response = rest_oauth_connect(:get, uri)
|
17
|
+
if type === :locations
|
18
|
+
bless_models(Twitter::Location.unmarshal(response.body))
|
19
|
+
else
|
20
|
+
bless_models(Twitter::Trendline.unmarshal(response.body))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/twitter/model.rb
CHANGED
@@ -30,7 +30,7 @@ module Twitter
|
|
30
30
|
# from JSON serialization. Currently JSON is only supported
|
31
31
|
# since this is all <tt>Twitter4R</tt> needs.
|
32
32
|
def unmarshal(raw)
|
33
|
-
input = JSON.parse(raw)
|
33
|
+
input = JSON.parse(raw) if raw.is_a?(String)
|
34
34
|
def unmarshal_model(hash)
|
35
35
|
self.new(hash)
|
36
36
|
end
|
@@ -155,6 +155,118 @@ module Twitter
|
|
155
155
|
end
|
156
156
|
end
|
157
157
|
|
158
|
+
# Represents a location in Twitter
|
159
|
+
class Location
|
160
|
+
include ModelMixin
|
161
|
+
|
162
|
+
@@ATTRIBUTES = [:name, :woeid, :country, :url, :countryCode, :parentid, :placeType]
|
163
|
+
attr_accessor(*@@ATTRIBUTES)
|
164
|
+
|
165
|
+
class << self
|
166
|
+
def attributes; @@ATTRIBUTES; end
|
167
|
+
end
|
168
|
+
|
169
|
+
# Alias to +countryCode+ for those wanting to use consistent naming
|
170
|
+
# convention for attribute
|
171
|
+
def country_code
|
172
|
+
@countryCode
|
173
|
+
end
|
174
|
+
|
175
|
+
# Alias to +parentid+ for those wanting to use consistent naming
|
176
|
+
# convention for attribute
|
177
|
+
def parent_id
|
178
|
+
@parentid
|
179
|
+
end
|
180
|
+
|
181
|
+
# Alias to +placeType+ for those wanting to use consistent naming
|
182
|
+
# convention for attribute
|
183
|
+
def place_type
|
184
|
+
@place_type
|
185
|
+
end
|
186
|
+
|
187
|
+
# Convenience method to output meaningful representation to STDOUT as per
|
188
|
+
# Ruby convention
|
189
|
+
def inspect
|
190
|
+
"#{name} / #{woeid} / #{countryCode}\n#{url}\n"
|
191
|
+
end
|
192
|
+
|
193
|
+
protected
|
194
|
+
def init
|
195
|
+
puts @placeType
|
196
|
+
@placeType = ::Twitter::PlaceType.new(:name => @placeType["name"],
|
197
|
+
:code => @placeType["code"]) if @placeType.is_a?(Hash)
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
# Represents a type of a place.
|
202
|
+
class PlaceType
|
203
|
+
include ModelMixin
|
204
|
+
|
205
|
+
@@ATTRIBUTES = [:name, :code]
|
206
|
+
attr_accessor(*@@ATTRIBUTES)
|
207
|
+
|
208
|
+
class << self
|
209
|
+
def attributes; @@ATTRIBUTES; end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
# Represents a sorted, dated and typed list of trends.
|
214
|
+
#
|
215
|
+
# To find out when this +Trendline+ was created query the +as_of+ attribute.
|
216
|
+
# To find out what type +Trendline+ is use the +type+ attribute.
|
217
|
+
# You can iterator over the trends in the +Trendline+ with +each+ or by
|
218
|
+
# index, whichever you prefer.
|
219
|
+
class Trendline
|
220
|
+
include ModelMixin
|
221
|
+
include Enumerable
|
222
|
+
include Comparable
|
223
|
+
|
224
|
+
@@ATTRIBUTES = [:as_of, :type]
|
225
|
+
attr_accessor(*@@ATTRIBUTES)
|
226
|
+
|
227
|
+
class << self
|
228
|
+
def attributes; @@ATTRIBUTES; end
|
229
|
+
end
|
230
|
+
|
231
|
+
# Spaceship operator definition needed by Comparable mixin
|
232
|
+
# for sort, etc.
|
233
|
+
def <=>(other)
|
234
|
+
self.type === other.type && self.as_of <=> other.as_of
|
235
|
+
end
|
236
|
+
|
237
|
+
# each definition needed by Enumerable mixin for first, ...
|
238
|
+
def each
|
239
|
+
trends.each do |t|
|
240
|
+
yield t
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
# index operator definition needed to iterate over trends
|
245
|
+
# in the +::Twitter::Trendline+ object using for or otherwise
|
246
|
+
def [](index)
|
247
|
+
trends[index]
|
248
|
+
end
|
249
|
+
|
250
|
+
protected
|
251
|
+
attr_accessor(:trends)
|
252
|
+
# Constructor callback
|
253
|
+
def init
|
254
|
+
@trends = @trends.collect do |trend|
|
255
|
+
::Twitter::Trend.new(trend) if trend.is_a?(Hash)
|
256
|
+
end if @trends.is_a?(Array)
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
class Trend
|
261
|
+
include ModelMixin
|
262
|
+
@@ATTRIBUTES = [:name, :url]
|
263
|
+
attr_accessor(*@@ATTRIBUTES)
|
264
|
+
|
265
|
+
class << self
|
266
|
+
def attributes; @@ATTRIBUTES; end
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
158
270
|
# Represents a <tt>Twitter</tt> user
|
159
271
|
class User
|
160
272
|
include ModelMixin
|
@@ -273,8 +385,13 @@ module Twitter
|
|
273
385
|
!!@in_reply_to_status_id
|
274
386
|
end
|
275
387
|
|
276
|
-
|
277
|
-
|
388
|
+
# Convenience method to allow client developers to not have to worry about
|
389
|
+
# setting the +in_reply_to_status_id+ attribute or prefixing the status
|
390
|
+
# text with the +screen_name+ being replied to.
|
391
|
+
def reply(reply)
|
392
|
+
status_reply = "@#{user.screen_name} #{reply}"
|
393
|
+
client.status(:reply, :status => status_reply,
|
394
|
+
:in_reply_to_status_id => @id)
|
278
395
|
end
|
279
396
|
|
280
397
|
protected
|
data/lib/twitter/version.rb
CHANGED
@@ -87,10 +87,6 @@ module FavoriteSpecMixin
|
|
87
87
|
"#{@base_uri}/#{method.to_s}/#{id.to_i.to_s}.json"
|
88
88
|
end
|
89
89
|
|
90
|
-
def connection=(connection)
|
91
|
-
@connection = connection
|
92
|
-
end
|
93
|
-
|
94
90
|
def finalize
|
95
91
|
nilize(@uri, @request, @twitter, @default_header, @response, @error_response, @connection)
|
96
92
|
end
|
@@ -45,6 +45,16 @@ describe Twitter::Client, "#status" do
|
|
45
45
|
@twitter.status(:post, @message)
|
46
46
|
end
|
47
47
|
|
48
|
+
it "should create expected HTTP POST request for :post case when passing Hash with lat/long instead of String" do
|
49
|
+
@twitter.should_receive(:rest_oauth_connect).with(:post, @uris[:post], :lat => 0, :long => 0, :status => @message, :source => @source).and_return(@response)
|
50
|
+
@twitter.status(:post, :status => @message, :lat => 0, :long => 0)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should create expected HTTP POST request for :post case when passing Hash with place_idinstead of String" do
|
54
|
+
@twitter.should_receive(:rest_oauth_connect).with(:post, @uris[:post], :place_id => 1234, :status => @message, :source => @source).and_return(@response)
|
55
|
+
@twitter.status(:post, :status => @message, :place_id => 1234)
|
56
|
+
end
|
57
|
+
|
48
58
|
it "should return nil if nil is passed as value argument for :post case" do
|
49
59
|
status = @twitter.status(:post, nil)
|
50
60
|
status.should be_nil
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
|
2
|
+
|
3
|
+
describe Twitter::Client, "#trends" do
|
4
|
+
before(:each) do
|
5
|
+
@uri = '/trends.json'
|
6
|
+
@request = mas_net_http_get
|
7
|
+
@twitter = client_context
|
8
|
+
@default_header = @twitter.send(:http_header)
|
9
|
+
@response = mas_net_http_response(:success)
|
10
|
+
@connection = mas_net_http(@response)
|
11
|
+
@favorites = []
|
12
|
+
Twitter::Status.stub!(:unmarshal).and_return(@favorites)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should create expected HTTP GET request when not giving options" do
|
16
|
+
@twitter.should_receive(:rest_oauth_connect).with(:get, @uri).and_return(@response)
|
17
|
+
@twitter.trends
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should raise Twitter::RESTError when 401 HTTP response received without giving options" do
|
21
|
+
@connection = mas_net_http(mas_net_http_response(:not_authorized))
|
22
|
+
lambda {
|
23
|
+
@twitter.trends
|
24
|
+
}.should raise_error(Twitter::RESTError)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should raise Twitter::RESTError when 401 HTTP response received" do
|
28
|
+
@connection = mas_net_http(mas_net_http_response(:not_authorized))
|
29
|
+
lambda {
|
30
|
+
@twitter.trends
|
31
|
+
}.should raise_error(Twitter::RESTError)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should raise Twitter::RESTError when 403 HTTP response received" do
|
35
|
+
@connection = mas_net_http(mas_net_http_response(:forbidden))
|
36
|
+
lambda {
|
37
|
+
@twitter.trends
|
38
|
+
}.should raise_error(Twitter::RESTError)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should raise Twitter::RESTError when 500 HTTP response received" do
|
42
|
+
@connection = mas_net_http(mas_net_http_response(:server_error))
|
43
|
+
lambda {
|
44
|
+
@twitter.trends
|
45
|
+
}.should raise_error(Twitter::RESTError)
|
46
|
+
end
|
47
|
+
|
48
|
+
after(:each) do
|
49
|
+
nilize(@uri, @request, @twitter, @default_header, @response, @error_response, @connection)
|
50
|
+
end
|
51
|
+
end
|
data/spec/twitter/model_spec.rb
CHANGED
@@ -72,25 +72,25 @@ describe Twitter::User, "unmarshaling" do
|
|
72
72
|
end
|
73
73
|
|
74
74
|
describe "Twitter::ModelMixin#to_hash" do
|
75
|
-
|
75
|
+
before(:all) do
|
76
76
|
class Model
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
77
|
+
include Twitter::ModelMixin
|
78
|
+
@@ATTRIBUTES = [:id, :name, :value, :unused_attr]
|
79
|
+
attr_accessor *@@ATTRIBUTES
|
80
|
+
def self.attributes; @@ATTRIBUTES; end
|
81
81
|
end
|
82
82
|
|
83
83
|
class Hash
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
84
|
+
def eql?(other)
|
85
|
+
return false unless other # trivial nil case.
|
86
|
+
return false unless self.keys.eql?(other.keys)
|
87
|
+
self.each do |key,val|
|
88
|
+
return false unless self[key].eql?(other[key])
|
89
|
+
end
|
90
|
+
true
|
91
|
+
end
|
92
92
|
end
|
93
|
-
|
93
|
+
end
|
94
94
|
|
95
95
|
before(:each) do
|
96
96
|
@attributes = {:id => 14, :name => 'State', :value => 'Illinois'}
|
@@ -115,7 +115,7 @@ describe Twitter::User, ".find" do
|
|
115
115
|
end
|
116
116
|
|
117
117
|
it "should invoke given Twitter::Client's #user method with expected arguments" do
|
118
|
-
|
118
|
+
# case where id => @id
|
119
119
|
@twitter.should_receive(:user).with(@id).and_return(@expected_user)
|
120
120
|
user = Twitter::User.find(@id, @twitter)
|
121
121
|
user.should eql(@expected_user)
|
@@ -232,13 +232,13 @@ end
|
|
232
232
|
|
233
233
|
describe Test::Model, "#to_i" do
|
234
234
|
before(:each) do
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
235
|
+
@id = 234324285
|
236
|
+
class Test::Model
|
237
|
+
attr_accessor :id
|
238
|
+
end
|
239
239
|
@model = Test::Model.new(:id => @id)
|
240
240
|
end
|
241
|
-
|
241
|
+
|
242
242
|
it "should return @id attribute" do
|
243
243
|
@model.to_i.should eql(@id)
|
244
244
|
end
|
@@ -250,10 +250,10 @@ end
|
|
250
250
|
|
251
251
|
describe Test::Model, "#to_s" do
|
252
252
|
before(:each) do
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
253
|
+
class Test::Model
|
254
|
+
attr_accessor :text
|
255
|
+
end
|
256
|
+
@text = 'Some text for the message body here'
|
257
257
|
@model = Test::Model.new(:text => @text)
|
258
258
|
end
|
259
259
|
|
@@ -269,7 +269,7 @@ end
|
|
269
269
|
describe Twitter::Message, ".find" do
|
270
270
|
it "should raise NotImplementedError due to Twitter (as opposed to Twitter4R) API limitation" do
|
271
271
|
lambda {
|
272
|
-
|
272
|
+
Twitter::Message.find(123, nil)
|
273
273
|
}.should raise_error(NotImplementedError)
|
274
274
|
end
|
275
275
|
end
|
@@ -288,26 +288,26 @@ describe Twitter::Status, ".create" do
|
|
288
288
|
|
289
289
|
it "should raise an ArgumentError when no client is given in params" do
|
290
290
|
lambda {
|
291
|
-
|
291
|
+
Twitter::Status.create(:text => @text)
|
292
292
|
}.should raise_error(ArgumentError)
|
293
293
|
end
|
294
294
|
|
295
295
|
it "should raise an ArgumentError when no text is given in params" do
|
296
|
-
|
296
|
+
@twitter.should_receive(:is_a?).with(Twitter::Client)
|
297
297
|
lambda {
|
298
|
-
|
298
|
+
Twitter::Status.create(:client => @twitter)
|
299
299
|
}.should raise_error(ArgumentError)
|
300
300
|
end
|
301
301
|
|
302
302
|
it "should raise an ArgumentError when text given in params is not a String" do
|
303
303
|
lambda {
|
304
|
-
|
304
|
+
Twitter::Status.create(:client => @twitter, :text => 234493)
|
305
305
|
}.should raise_error(ArgumentError)
|
306
306
|
end
|
307
307
|
|
308
308
|
it "should raise an ArgumentError when client context given in params is not a Twitter::Client object" do
|
309
309
|
lambda {
|
310
|
-
|
310
|
+
Twitter::Status.create(:client => 'a string instead of a Twitter::Client', :text => @text)
|
311
311
|
}.should raise_error(ArgumentError)
|
312
312
|
end
|
313
313
|
|
@@ -331,54 +331,54 @@ describe Twitter::Message, ".create" do
|
|
331
331
|
|
332
332
|
it "should raise an ArgumentError if no client context is given in params" do
|
333
333
|
lambda {
|
334
|
-
|
334
|
+
Twitter::Message.create(:text => @text, :recipient => @recipient)
|
335
335
|
}.should raise_error(ArgumentError)
|
336
336
|
end
|
337
337
|
|
338
338
|
it "should raise an ArgumentError if client conext given in params is not a Twitter::Client object" do
|
339
339
|
lambda {
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
340
|
+
Twitter::Message.create(
|
341
|
+
:client => 3.14159,
|
342
|
+
:text => @text,
|
343
|
+
:recipient => @recipient)
|
344
344
|
}.should raise_error(ArgumentError)
|
345
345
|
end
|
346
346
|
|
347
347
|
it "should raise an ArgumentError if no text is given in params" do
|
348
|
-
|
348
|
+
@twitter.should_receive(:is_a?).with(Twitter::Client)
|
349
349
|
lambda {
|
350
|
-
|
351
|
-
|
352
|
-
|
350
|
+
Twitter::Message.create(
|
351
|
+
:client => @twitter,
|
352
|
+
:recipient => @recipient)
|
353
353
|
}.should raise_error(ArgumentError)
|
354
354
|
end
|
355
355
|
|
356
356
|
it "should raise an ArgumentError if text given in params is not a String" do
|
357
357
|
@twitter.should_receive(:is_a?).with(Twitter::Client)
|
358
358
|
lambda {
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
359
|
+
Twitter::Message.create(
|
360
|
+
:client => @twitter,
|
361
|
+
:text => Object.new,
|
362
|
+
:recipient => @recipient)
|
363
363
|
}.should raise_error(ArgumentError)
|
364
364
|
end
|
365
365
|
|
366
366
|
it "should raise an ArgumentError if no recipient is given in params" do
|
367
367
|
@text.should_receive(:is_a?).with(String)
|
368
368
|
lambda {
|
369
|
-
|
370
|
-
|
371
|
-
|
369
|
+
Twitter::Message.create(
|
370
|
+
:client => @twitter,
|
371
|
+
:text => @text)
|
372
372
|
}.should raise_error(ArgumentError)
|
373
373
|
end
|
374
374
|
|
375
375
|
it "should raise an ArgumentError if recipient given in params is not a Twitter::User, Integer or String object" do
|
376
376
|
@text.should_receive(:is_a?).with(String)
|
377
377
|
lambda {
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
378
|
+
Twitter::Message.create(
|
379
|
+
:client => @twitter,
|
380
|
+
:text => @text,
|
381
|
+
:recipient => 3.14159)
|
382
382
|
}.should raise_error(ArgumentError)
|
383
383
|
end
|
384
384
|
|
@@ -391,13 +391,13 @@ describe Twitter::User, "#befriend" do
|
|
391
391
|
before(:each) do
|
392
392
|
@twitter = client_context
|
393
393
|
@user = Twitter::User.new(
|
394
|
-
|
395
|
-
|
396
|
-
|
394
|
+
:id => 1234,
|
395
|
+
:screen_name => 'mylogin',
|
396
|
+
:client => @twitter)
|
397
397
|
@friend = Twitter::User.new(
|
398
|
-
|
399
|
-
|
400
|
-
|
398
|
+
:id => 5678,
|
399
|
+
:screen_name => 'friend',
|
400
|
+
:client => @twitter)
|
401
401
|
end
|
402
402
|
|
403
403
|
it "should invoke #friend(:add, user) on client context" do
|
@@ -414,13 +414,13 @@ describe Twitter::User, "#defriend" do
|
|
414
414
|
before(:each) do
|
415
415
|
@twitter = client_context
|
416
416
|
@user = Twitter::User.new(
|
417
|
-
|
418
|
-
|
419
|
-
|
417
|
+
:id => 1234,
|
418
|
+
:screen_name => 'mylogin',
|
419
|
+
:client => @twitter)
|
420
420
|
@friend = Twitter::User.new(
|
421
|
-
|
422
|
-
|
423
|
-
|
421
|
+
:id => 5678,
|
422
|
+
:screen_name => 'friend',
|
423
|
+
:client => @twitter)
|
424
424
|
end
|
425
425
|
|
426
426
|
it "should invoke #friend(:remove, user) on client context" do
|
@@ -459,16 +459,19 @@ end
|
|
459
459
|
describe Twitter::Status, "#reply(status_text)" do
|
460
460
|
before(:each) do
|
461
461
|
@twitter = client_context
|
462
|
+
@user = Twitter::User.new(:screen_name => "ilovephpnot")
|
462
463
|
@status = Twitter::Status.new(
|
463
464
|
:id => 1234,
|
464
465
|
:text => "The status text",
|
466
|
+
:user => @user,
|
465
467
|
:client => @twitter)
|
466
468
|
@reply_text = "Reply text goes here"
|
467
469
|
@reply_status = Twitter::Status.new()
|
468
470
|
end
|
469
471
|
|
470
472
|
it "should invoke #status(:reply, :status => ..., :in_reply_to_status_id => ...) on client context" do
|
471
|
-
@twitter.should_receive(:status).with(:reply, :status => @reply_text,
|
473
|
+
@twitter.should_receive(:status).with(:reply, :status => "@#{@user.screen_name} #{@reply_text}",
|
474
|
+
:in_reply_to_status_id => @status.id).and_return(@reply_status)
|
472
475
|
@status.reply(@reply_text)
|
473
476
|
end
|
474
477
|
|
@@ -494,7 +497,7 @@ end
|
|
494
497
|
|
495
498
|
describe Twitter::Message, "#to_s" do
|
496
499
|
before(:each) do
|
497
|
-
|
500
|
+
@text = 'Aloha'
|
498
501
|
@message = Twitter::Message.new(:text => @text)
|
499
502
|
end
|
500
503
|
|
@@ -506,3 +509,19 @@ describe Twitter::Message, "#to_s" do
|
|
506
509
|
nilize(@text, @message)
|
507
510
|
end
|
508
511
|
end
|
512
|
+
|
513
|
+
describe Twitter::Trendline, ".new" do
|
514
|
+
it "should initialize trends into an Array of Twitter::Trend objects" do
|
515
|
+
trendline = Twitter::Trendline.new(:trends => [
|
516
|
+
{:name => "booyah", :url => "http://twitter.com/search?q=booyah"},
|
517
|
+
{:name => "twitter4r", :url => "http://twitter.com/search?q=twitter4r"},
|
518
|
+
])
|
519
|
+
trendline.each do |t|
|
520
|
+
t.should be_a(Twitter::Trend)
|
521
|
+
end
|
522
|
+
booyah = trendline.first
|
523
|
+
booyah.name.should === "booyah"
|
524
|
+
twitter4r = trendline[-1]
|
525
|
+
twitter4r.name.should === "twitter4r"
|
526
|
+
end
|
527
|
+
end
|
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twitter4r
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 6
|
8
|
-
- 0
|
9
|
-
version: 0.6.0
|
4
|
+
prerelease:
|
5
|
+
version: 0.7.0
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- Susan Potter
|
@@ -14,7 +10,7 @@ autorequire: twitter
|
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date:
|
13
|
+
date: 2011-07-11 00:00:00 -05:00
|
18
14
|
default_executable:
|
19
15
|
dependencies:
|
20
16
|
- !ruby/object:Gem::Dependency
|
@@ -25,10 +21,6 @@ dependencies:
|
|
25
21
|
requirements:
|
26
22
|
- - ">="
|
27
23
|
- !ruby/object:Gem::Version
|
28
|
-
segments:
|
29
|
-
- 1
|
30
|
-
- 1
|
31
|
-
- 1
|
32
24
|
version: 1.1.1
|
33
25
|
type: :runtime
|
34
26
|
version_requirements: *id001
|
@@ -40,10 +32,6 @@ dependencies:
|
|
40
32
|
requirements:
|
41
33
|
- - ">="
|
42
34
|
- !ruby/object:Gem::Version
|
43
|
-
segments:
|
44
|
-
- 0
|
45
|
-
- 4
|
46
|
-
- 1
|
47
35
|
version: 0.4.1
|
48
36
|
type: :runtime
|
49
37
|
version_requirements: *id002
|
@@ -64,6 +52,7 @@ files:
|
|
64
52
|
- lib/twitter/version.rb
|
65
53
|
- lib/twitter/client/status.rb
|
66
54
|
- lib/twitter/client/timeline.rb
|
55
|
+
- lib/twitter/client/trends.rb
|
67
56
|
- lib/twitter/client/search.rb
|
68
57
|
- lib/twitter/client/graph.rb
|
69
58
|
- lib/twitter/client/favorites.rb
|
@@ -88,6 +77,7 @@ files:
|
|
88
77
|
- spec/twitter/client/friendship_spec.rb
|
89
78
|
- spec/twitter/client/blocks_spec.rb
|
90
79
|
- spec/twitter/client/graph_spec.rb
|
80
|
+
- spec/twitter/client/trends_spec.rb
|
91
81
|
- spec/twitter/client/search_spec.rb
|
92
82
|
- spec/twitter/client/auth_spec.rb
|
93
83
|
- spec/twitter/client/account_spec.rb
|
@@ -126,25 +116,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
126
116
|
requirements:
|
127
117
|
- - ">="
|
128
118
|
- !ruby/object:Gem::Version
|
129
|
-
segments:
|
130
|
-
- 1
|
131
|
-
- 8
|
132
|
-
- 6
|
133
119
|
version: 1.8.6
|
134
120
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
121
|
none: false
|
136
122
|
requirements:
|
137
123
|
- - ">="
|
138
124
|
- !ruby/object:Gem::Version
|
139
|
-
segments:
|
140
|
-
- 0
|
141
125
|
version: "0"
|
142
126
|
requirements:
|
143
127
|
- Ruby 1.8.6+
|
144
128
|
- json gem, version 0.4.3 or higher
|
145
129
|
- jcode (for unicode support)
|
146
130
|
rubyforge_project: twitter4r
|
147
|
-
rubygems_version: 1.
|
131
|
+
rubygems_version: 1.6.2
|
148
132
|
signing_key:
|
149
133
|
specification_version: 3
|
150
134
|
summary: A clean Twitter client API in pure Ruby. Will include Twitter add-ons also in Ruby.
|