twitter 4.6.2 → 4.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/CHANGELOG.md +12 -0
- data/CONTRIBUTING.md +1 -1
- data/README.md +1 -1
- data/lib/twitter.rb +8 -0
- data/lib/twitter/api/friends_and_followers.rb +2 -4
- data/lib/twitter/api/lists.rb +26 -0
- data/lib/twitter/api/oauth.rb +43 -0
- data/lib/twitter/api/tweets.rb +15 -0
- data/lib/twitter/client.rb +42 -5
- data/lib/twitter/configurable.rb +21 -10
- data/lib/twitter/default.rb +5 -3
- data/lib/twitter/entity/symbol.rb +9 -0
- data/lib/twitter/search_results.rb +11 -1
- data/lib/twitter/token.rb +7 -0
- data/lib/twitter/tweet.rb +6 -0
- data/lib/twitter/version.rb +2 -2
- data/spec/fixtures/bearer_token.json +1 -0
- data/spec/fixtures/ownerships.json +1 -0
- data/spec/helper.rb +4 -0
- data/spec/twitter/api/lists_spec.rb +36 -0
- data/spec/twitter/api/oauth_spec.rb +49 -0
- data/spec/twitter/api/tweets_spec.rb +26 -0
- data/spec/twitter/client_spec.rb +44 -2
- data/spec/twitter/search_results_spec.rb +16 -1
- data/spec/twitter/tweet_spec.rb +39 -16
- data/spec/twitter_spec.rb +7 -1
- data/twitter.gemspec +1 -1
- metadata +54 -31
- metadata.gz.sig +0 -0
- checksums.yaml +0 -7
- checksums.yaml.gz.sig +0 -0
- data/spec/fixtures/rate_limit_status.json +0 -1
data.tar.gz.sig
CHANGED
Binary file
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
4.7.0
|
2
|
+
-----
|
3
|
+
* [Add support for application-only authentication](https://github.com/sferik/twitter/pull/387) ([@paracycle](https://twitter.com/paracycle))
|
4
|
+
* [Add support for `Twitter::Entity::Symbol` entities](https://github.com/sferik/twitter/commit/a14a0cdc57ad5d7760392f71a280c7100a5b5936) ([@anno](https://twitter.com/anno))
|
5
|
+
* [Add `Twitter::API::OAuth#invalidate_token`](https://github.com/sferik/twitter/pull/372) ([@terenceponce](https://twitter.com/terenceponce))
|
6
|
+
* [Add `Twitter::API::Lists#lists_owned` method](https://github.com/sferik/twitter/commit/9e97b51c20aabf4485a91ae7db697ee3be131a89)
|
7
|
+
* [Add `Twitter::API::Tweets#retweeters_ids` method](https://github.com/sferik/twitter/commit/8cf5b2ddf3d2647084496c7c3f205b2468d84cbe)
|
8
|
+
* [Add `Twitter::SearchResults#next_results`](https://github.com/sferik/twitter/pull/365) ([@KentonWhite](https://twitter.com/KentonWhite))
|
9
|
+
* [Make consumer_key readable](https://github.com/sferik/twitter/commit/a318869c4827d6add781730cfb67fd2bdca5c584)
|
10
|
+
* [Loosen required_rubygems_version for compatibility with Ubuntu 10.04](https://github.com/sferik/twitter/commit/41bd5655c2e7eca813807d742cb7fdec8f0bb027)
|
11
|
+
* [Remove default SSL configuration options and override](https://github.com/sferik/twitter/commit/113b14bc05a9f8e513245fda057e7f16f8965357)
|
12
|
+
|
1
13
|
4.6.2
|
2
14
|
-----
|
3
15
|
* [Fix `SystemStackError: stack level too deep` when converting to JSON](https://github.com/sferik/twitter/issues/368)
|
data/CONTRIBUTING.md
CHANGED
@@ -40,7 +40,7 @@ Ideally, a bug report should include a pull request with failing specs.
|
|
40
40
|
6. Run `bundle exec rake spec`. If your specs fail, return to step 5.
|
41
41
|
7. Run `open coverage/index.html`. If your changes are not completely covered
|
42
42
|
by your tests, return to step 3.
|
43
|
-
8 Run `RUBYOPT=W2 bundle exec rake spec 2>&1 | grep twitter`. If your changes
|
43
|
+
8. Run `RUBYOPT=W2 bundle exec rake spec 2>&1 | grep twitter`. If your changes
|
44
44
|
produce any warnings, return to step 5.
|
45
45
|
9. Add documentation for your feature or bug fix.
|
46
46
|
10. Run `bundle exec rake yard`. If your changes are not 100% documented, go
|
data/README.md
CHANGED
@@ -23,7 +23,7 @@ To ensure the code you're installing hasn't been tampered with, it's
|
|
23
23
|
recommended that you verify the signature. To do this, you need to add my
|
24
24
|
public key as a trusted certificate (you only need to do this once):
|
25
25
|
|
26
|
-
gem cert --add <(curl -Ls https://
|
26
|
+
gem cert --add <(curl -Ls https://raw.github.com/sferik/twitter/master/certs/sferik.pem)
|
27
27
|
|
28
28
|
Then, install the gem with the high security trust policy:
|
29
29
|
|
data/lib/twitter.rb
CHANGED
@@ -7,6 +7,7 @@ require 'twitter/default'
|
|
7
7
|
require 'twitter/direct_message'
|
8
8
|
require 'twitter/entity'
|
9
9
|
require 'twitter/entity/hashtag'
|
10
|
+
require 'twitter/entity/symbol'
|
10
11
|
require 'twitter/entity/url'
|
11
12
|
require 'twitter/entity/user_mention'
|
12
13
|
require 'twitter/geo_factory'
|
@@ -42,6 +43,13 @@ module Twitter
|
|
42
43
|
@client
|
43
44
|
end
|
44
45
|
|
46
|
+
# Has a client been initialized on the Twitter module
|
47
|
+
#
|
48
|
+
# @return [Boolean]
|
49
|
+
def client?
|
50
|
+
!!@client
|
51
|
+
end
|
52
|
+
|
45
53
|
def respond_to_missing?(method_name, include_private=false); client.respond_to?(method_name, include_private); end if RUBY_VERSION >= "1.9"
|
46
54
|
def respond_to?(method_name, include_private=false); client.respond_to?(method_name, include_private) || super; end if RUBY_VERSION < "1.9"
|
47
55
|
|
@@ -315,16 +315,14 @@ module Twitter
|
|
315
315
|
end
|
316
316
|
alias following friends
|
317
317
|
|
318
|
-
# Returns a collection of
|
319
|
-
# =>
|
318
|
+
# Returns a collection of user IDs that the currently authenticated user does not want to receive retweets from.
|
320
319
|
# @see https://dev.twitter.com/docs/api/1.1/get/friendships/no_retweets/ids
|
321
320
|
# @rate_limited Yes
|
322
321
|
# @authentication Requires user context
|
323
322
|
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
324
323
|
# @return [Array<Integer>]
|
325
324
|
# @param options [Hash] A customizable set of options.
|
326
|
-
# @
|
327
|
-
# @example Enable rewteets and devise notifications for @sferik
|
325
|
+
# @example Return a collection of user IDs that the currently authenticated user does not want to receive retweets from
|
328
326
|
# Twitter.no_retweet_ids
|
329
327
|
def no_retweet_ids(options={})
|
330
328
|
get("/1.1/friendships/no_retweets/ids.json", options)[:body].map(&:to_i)
|
data/lib/twitter/api/lists.rb
CHANGED
@@ -23,11 +23,13 @@ module Twitter
|
|
23
23
|
# @return [Array<Twitter::List>]
|
24
24
|
# @overload lists(options={})
|
25
25
|
# @param options [Hash] A customizable set of options.
|
26
|
+
# @option options [Boolean] :reverse Set this to true if you would like owned lists to be returned first.
|
26
27
|
# @example Return all lists the authenticating user subscribes to
|
27
28
|
# Twitter.lists
|
28
29
|
# @overload lists(user, options={})
|
29
30
|
# @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
|
30
31
|
# @param options [Hash] A customizable set of options.
|
32
|
+
# @option options [Boolean] :reverse Set this to true if you would like owned lists to be returned first.
|
31
33
|
# @example Return all lists that @sferik subscribes to
|
32
34
|
# Twitter.lists('sferik')
|
33
35
|
# Twitter.lists(7505382)
|
@@ -506,6 +508,30 @@ module Twitter
|
|
506
508
|
list_from_response_with_users(:post, "/1.1/lists/members/destroy_all.json", args)
|
507
509
|
end
|
508
510
|
|
511
|
+
# Returns the lists owned by the specified Twitter user
|
512
|
+
#
|
513
|
+
# @see https://dev.twitter.com/docs/api/1.1/get/lists/ownerships
|
514
|
+
# @rate_limited Yes
|
515
|
+
# @authentication Requires user context
|
516
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
517
|
+
# @return [Array<Twitter::List>]
|
518
|
+
# @overload lists_owned(options={})
|
519
|
+
# @param options [Hash] A customizable set of options.
|
520
|
+
# @option options [Integer] :count The amount of results to return per page. Defaults to 20. No more than 1000 results will ever be returned in a single page.
|
521
|
+
# @example Return all lists the authenticating user owns
|
522
|
+
# Twitter.lists_owend
|
523
|
+
# @overload lists_owned(user, options={})
|
524
|
+
# @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
|
525
|
+
# @param options [Hash] A customizable set of options.
|
526
|
+
# @option options [Integer] :count The amount of results to return per page. Defaults to 20. No more than 1000 results will ever be returned in a single page.
|
527
|
+
# @example Return all lists that @sferik owns
|
528
|
+
# Twitter.lists_owned('sferik')
|
529
|
+
# Twitter.lists_owned(7505382)
|
530
|
+
def lists_owned(*args)
|
531
|
+
cursor_from_response_with_user(:lists, Twitter::List, :get, "/1.1/lists/ownerships.json", args, :lists_owned)
|
532
|
+
end
|
533
|
+
alias lists_ownerships lists_owned
|
534
|
+
|
509
535
|
private
|
510
536
|
|
511
537
|
# @param request_method [Symbol]
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'twitter/api/utils'
|
2
|
+
require 'twitter/token'
|
3
|
+
|
4
|
+
module Twitter
|
5
|
+
module API
|
6
|
+
module OAuth
|
7
|
+
include Twitter::API::Utils
|
8
|
+
|
9
|
+
# Allows a registered application to obtain an OAuth 2 Bearer Token, which can be used to make API requests
|
10
|
+
# on an application's own behalf, without a user context.
|
11
|
+
#
|
12
|
+
# Only one bearer token may exist outstanding for an application, and repeated requests to this method
|
13
|
+
# will yield the same already-existent token until it has been invalidated.
|
14
|
+
#
|
15
|
+
# @see https://dev.twitter.com/docs/api/1.1/post/oauth2/token
|
16
|
+
# @rate_limited No
|
17
|
+
# @authentication Required
|
18
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
19
|
+
# @return [Twitter::Token] The Bearer Token. token_type should be 'bearer'.
|
20
|
+
# @example Generate a Bearer Token
|
21
|
+
# client = Twitter::Client.new(:consumer_key => "abc", :consumer_secret => 'def')
|
22
|
+
# bearer_token = client.token
|
23
|
+
def token
|
24
|
+
object_from_response(Twitter::Token, :post, "/oauth2/token", :grant_type => "client_credentials", :bearer_token_request => true)
|
25
|
+
end
|
26
|
+
alias bearer_token token
|
27
|
+
|
28
|
+
# Allows a registered application to revoke an issued OAuth 2 Bearer Token by presenting its client credentials.
|
29
|
+
#
|
30
|
+
# @see https://dev.twitter.com/docs/api/1.1/post/oauth2/invalidate_token
|
31
|
+
# @rate_limited No
|
32
|
+
# @authentication Required
|
33
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
34
|
+
# @param access_token [String] The value of the bearer token to revoke.
|
35
|
+
# @return [Twitter::Token] The invalidated token. token_type should be nil.
|
36
|
+
# @example Revoke a token
|
37
|
+
# Twitter.invalidate_token("AAAA%2FAAA%3DAAAAAAAA")
|
38
|
+
def invalidate_token(access_token)
|
39
|
+
object_from_response(Twitter::Token, :post, "/oauth2/invalidate_token", :access_token => access_token)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/twitter/api/tweets.rb
CHANGED
@@ -256,6 +256,21 @@ module Twitter
|
|
256
256
|
end
|
257
257
|
end
|
258
258
|
|
259
|
+
# Returns a collection of user IDs belonging to users who have retweeted the specified Tweet.
|
260
|
+
# @see https://dev.twitter.com/docs/api/1.1/get/statuses/retweeters/ids
|
261
|
+
# @rate_limited Yes
|
262
|
+
# @authentication Required
|
263
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
264
|
+
# @return [Array<Integer>]
|
265
|
+
# @param options [Hash] A customizable set of options.
|
266
|
+
# @example Return a collection of user IDs belonging to users who have retweeted the specified Tweet
|
267
|
+
# Twitter.retweeters_ids(25938088801)
|
268
|
+
def retweeters_ids(*args)
|
269
|
+
arguments = Twitter::API::Arguments.new(args)
|
270
|
+
arguments.options[:id] ||= arguments.first
|
271
|
+
cursor_from_response(:ids, nil, :get, "/1.1/statuses/retweeters/ids.json", arguments.options, :retweeters_ids)
|
272
|
+
end
|
273
|
+
|
259
274
|
private
|
260
275
|
|
261
276
|
# @param request_method [Symbol]
|
data/lib/twitter/client.rb
CHANGED
@@ -5,6 +5,7 @@ require 'twitter/api/favorites'
|
|
5
5
|
require 'twitter/api/friends_and_followers'
|
6
6
|
require 'twitter/api/help'
|
7
7
|
require 'twitter/api/lists'
|
8
|
+
require 'twitter/api/oauth'
|
8
9
|
require 'twitter/api/places_and_geo'
|
9
10
|
require 'twitter/api/saved_searches'
|
10
11
|
require 'twitter/api/search'
|
@@ -19,6 +20,7 @@ require 'twitter/configurable'
|
|
19
20
|
require 'twitter/error/client_error'
|
20
21
|
require 'twitter/error/decode_error'
|
21
22
|
require 'simple_oauth'
|
23
|
+
require 'base64'
|
22
24
|
require 'uri'
|
23
25
|
|
24
26
|
module Twitter
|
@@ -32,6 +34,7 @@ module Twitter
|
|
32
34
|
include Twitter::API::FriendsAndFollowers
|
33
35
|
include Twitter::API::Help
|
34
36
|
include Twitter::API::Lists
|
37
|
+
include Twitter::API::OAuth
|
35
38
|
include Twitter::API::PlacesAndGeo
|
36
39
|
include Twitter::API::SavedSearches
|
37
40
|
include Twitter::API::Search
|
@@ -77,10 +80,33 @@ module Twitter
|
|
77
80
|
|
78
81
|
private
|
79
82
|
|
83
|
+
# Returns a proc that can be used to setup the Faraday::Request headers
|
84
|
+
#
|
85
|
+
# @param method [Symbol]
|
86
|
+
# @param path [String]
|
87
|
+
# @param params [Hash]
|
88
|
+
# @return [Proc]
|
89
|
+
def request_setup(method, path, params)
|
90
|
+
Proc.new do |request|
|
91
|
+
if params.delete(:bearer_token_request)
|
92
|
+
request.headers[:authorization] = bearer_token_credentials_auth_header
|
93
|
+
request.headers[:content_type] = 'application/x-www-form-urlencoded; charset=UTF-8'
|
94
|
+
request.headers[:accept] = '*/*' # It is important we set this, otherwise we get an error.
|
95
|
+
elsif params.delete(:app_auth) || !user_token?
|
96
|
+
unless bearer_token?
|
97
|
+
@bearer_token = token[:access_token]
|
98
|
+
Twitter.client.bearer_token = @bearer_token if Twitter.client?
|
99
|
+
end
|
100
|
+
request.headers[:authorization] = bearer_auth_header
|
101
|
+
else
|
102
|
+
request.headers[:authorization] = oauth_auth_header(method, path, params).to_s
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
80
107
|
def request(method, path, params={}, signature_params=params)
|
81
|
-
|
82
|
-
|
83
|
-
end.env
|
108
|
+
request_setup = request_setup(method, path, params)
|
109
|
+
connection.send(method.to_sym, path, params, &request_setup).env
|
84
110
|
rescue Faraday::Error::ClientError
|
85
111
|
raise Twitter::Error::ClientError
|
86
112
|
rescue MultiJson::DecodeError
|
@@ -94,10 +120,21 @@ module Twitter
|
|
94
120
|
@connection ||= Faraday.new(@endpoint, @connection_options.merge(:builder => @middleware))
|
95
121
|
end
|
96
122
|
|
97
|
-
|
123
|
+
# Generates authentication header for a bearer token request
|
124
|
+
#
|
125
|
+
# @return [String]
|
126
|
+
def bearer_token_credentials_auth_header
|
127
|
+
basic_auth_token = Base64.strict_encode64("#{@consumer_key}:#{@consumer_secret}")
|
128
|
+
"Basic #{basic_auth_token}"
|
129
|
+
end
|
130
|
+
|
131
|
+
def bearer_auth_header
|
132
|
+
"Bearer #{@bearer_token}"
|
133
|
+
end
|
134
|
+
|
135
|
+
def oauth_auth_header(method, path, params={})
|
98
136
|
uri = URI(@endpoint + path)
|
99
137
|
SimpleOAuth::Header.new(method, uri, params, credentials)
|
100
138
|
end
|
101
|
-
|
102
139
|
end
|
103
140
|
end
|
data/lib/twitter/configurable.rb
CHANGED
@@ -4,8 +4,8 @@ require 'twitter/error/configuration_error'
|
|
4
4
|
module Twitter
|
5
5
|
module Configurable
|
6
6
|
extend Forwardable
|
7
|
-
attr_writer :
|
8
|
-
attr_accessor :endpoint, :connection_options, :identity_map, :middleware
|
7
|
+
attr_writer :consumer_secret, :oauth_token, :oauth_token_secret, :bearer_token
|
8
|
+
attr_accessor :consumer_key, :endpoint, :connection_options, :identity_map, :middleware
|
9
9
|
def_delegator :options, :hash
|
10
10
|
|
11
11
|
class << self
|
@@ -16,6 +16,7 @@ module Twitter
|
|
16
16
|
:consumer_secret,
|
17
17
|
:oauth_token,
|
18
18
|
:oauth_token_secret,
|
19
|
+
:bearer_token,
|
19
20
|
:endpoint,
|
20
21
|
:connection_options,
|
21
22
|
:identity_map,
|
@@ -35,11 +36,6 @@ module Twitter
|
|
35
36
|
self
|
36
37
|
end
|
37
38
|
|
38
|
-
# @return [Boolean]
|
39
|
-
def credentials?
|
40
|
-
credentials.values.all?
|
41
|
-
end
|
42
|
-
|
43
39
|
def reset!
|
44
40
|
Twitter::Configurable.keys.each do |key|
|
45
41
|
instance_variable_set(:"@#{key}", Twitter::Default.options[key])
|
@@ -48,15 +44,30 @@ module Twitter
|
|
48
44
|
end
|
49
45
|
alias setup reset!
|
50
46
|
|
47
|
+
# @return [Boolean]
|
48
|
+
def user_token?
|
49
|
+
!!(@oauth_token && @oauth_token_secret)
|
50
|
+
end
|
51
|
+
|
52
|
+
# @return [Boolean]
|
53
|
+
def bearer_token?
|
54
|
+
!!@bearer_token
|
55
|
+
end
|
56
|
+
|
57
|
+
# @return [Boolean]
|
58
|
+
def credentials?
|
59
|
+
credentials.values.all? || bearer_token?
|
60
|
+
end
|
61
|
+
|
51
62
|
private
|
52
63
|
|
53
64
|
# @return [Hash]
|
54
65
|
def credentials
|
55
66
|
{
|
56
|
-
:consumer_key
|
67
|
+
:consumer_key => @consumer_key,
|
57
68
|
:consumer_secret => @consumer_secret,
|
58
|
-
:token
|
59
|
-
:token_secret
|
69
|
+
:token => @oauth_token,
|
70
|
+
:token_secret => @oauth_token_secret,
|
60
71
|
}
|
61
72
|
end
|
62
73
|
|
data/lib/twitter/default.rb
CHANGED
@@ -20,9 +20,6 @@ module Twitter
|
|
20
20
|
:open_timeout => 5,
|
21
21
|
:timeout => 10,
|
22
22
|
},
|
23
|
-
:ssl => {
|
24
|
-
:verify => false
|
25
|
-
},
|
26
23
|
} unless defined? Twitter::Default::CONNECTION_OPTIONS
|
27
24
|
IDENTITY_MAP = false unless defined? Twitter::Default::IDENTITY_MAP
|
28
25
|
MIDDLEWARE = Faraday::Builder.new do |builder|
|
@@ -69,6 +66,11 @@ module Twitter
|
|
69
66
|
ENV['TWITTER_OAUTH_TOKEN_SECRET']
|
70
67
|
end
|
71
68
|
|
69
|
+
# @return [String]
|
70
|
+
def bearer_token
|
71
|
+
ENV['TWITTER_BEARER_TOKEN']
|
72
|
+
end
|
73
|
+
|
72
74
|
# @note This is configurable in case you want to use a Twitter-compatible endpoint.
|
73
75
|
# @see http://status.net/wiki/Twitter-compatible_API
|
74
76
|
# @see http://en.blog.wordpress.com/2009/12/12/twitter-api/
|
@@ -46,12 +46,22 @@ module Twitter
|
|
46
46
|
def since_id
|
47
47
|
@attrs[:search_metadata][:since_id] if search_metadata?
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
# @return [Boolean]
|
51
51
|
def next_results?
|
52
52
|
!@attrs[:search_metadata][:next_results].nil? if search_metadata?
|
53
53
|
end
|
54
54
|
alias next_page? next_results?
|
55
55
|
|
56
|
+
# Returns a Hash of query parameters for the next result in the search
|
57
|
+
#
|
58
|
+
# Returned Hash can be merged into the previous search options list
|
59
|
+
# to easily access the next page
|
60
|
+
#
|
61
|
+
# @return [Hash]
|
62
|
+
def next_results
|
63
|
+
Faraday::Utils.parse_nested_query(@attrs[:search_metadata][:next_results][1..-1]).inject({}) { |memo, (k,v)| memo[k.to_sym] = v; memo} if next_results?
|
64
|
+
end
|
65
|
+
alias next_page next_results
|
56
66
|
end
|
57
67
|
end
|
data/lib/twitter/tweet.rb
CHANGED
@@ -114,6 +114,12 @@ module Twitter
|
|
114
114
|
end
|
115
115
|
alias retweet_count retweeters_count
|
116
116
|
|
117
|
+
# @note Must include entities in your request for this method to work
|
118
|
+
# @return [Array<Twitter::Entity::Symbol>]
|
119
|
+
def symbols
|
120
|
+
@symbols ||= entities(Twitter::Entity::Symbol, :symbols)
|
121
|
+
end
|
122
|
+
|
117
123
|
# @note Must include entities in your request for this method to work
|
118
124
|
# @return [Array<Twitter::Entity::Url>]
|
119
125
|
def urls
|
data/lib/twitter/version.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module Twitter
|
2
2
|
class Version
|
3
3
|
MAJOR = 4 unless defined? Twitter::Version::MAJOR
|
4
|
-
MINOR =
|
5
|
-
PATCH =
|
4
|
+
MINOR = 7 unless defined? Twitter::Version::MINOR
|
5
|
+
PATCH = 0 unless defined? Twitter::Version::PATCH
|
6
6
|
PRE = nil unless defined? Twitter::Version::PRE
|
7
7
|
|
8
8
|
class << self
|
@@ -0,0 +1 @@
|
|
1
|
+
{"token_type":"bearer","access_token":"AAAA%2FAAA%3DAAAAAAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"next_cursor":0,"next_cursor_str":"0","previous_cursor":0,"previous_cursor_str":"0","lists":[{"id":78890017,"id_str":"78890017","name":"My favstar.fm list","uri":"\/sferik\/my-favstar-fm-list","subscriber_count":0,"member_count":137,"mode":"private","description":"My favorite tweeters, created with help from http:\/\/favstar.fm","slug":"my-favstar-fm-list","full_name":"@sferik\/my-favstar-fm-list","created_at":"Fri Oct 12 19:47:53 +0000 2012","following":true,"user":{"id":7505382,"id_str":"7505382","name":"Erik Michaels-Ober","screen_name":"sferik","location":"San Francisco","description":"Write code. Not too much. Mostly Ruby.","url":"https:\/\/github.com\/sferik","entities":{"url":{"urls":[{"url":"https:\/\/github.com\/sferik","expanded_url":null,"indices":[0,25]}]},"description":{"urls":[]}},"protected":false,"followers_count":8855,"friends_count":248,"listed_count":167,"created_at":"Mon Jul 16 12:59:01 +0000 2007","favourites_count":6063,"utc_offset":-28800,"time_zone":"Pacific Time (US & Canada)","geo_enabled":true,"verified":false,"statuses_count":11166,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"000000","profile_background_image_url":"http:\/\/a0.twimg.com\/profile_background_images\/677717672\/bb0b3653dcf0644e344823e0a2eb3382.png","profile_background_image_url_https":"https:\/\/si0.twimg.com\/profile_background_images\/677717672\/bb0b3653dcf0644e344823e0a2eb3382.png","profile_background_tile":false,"profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/1759857427\/image1326743606_normal.png","profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/1759857427\/image1326743606_normal.png","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/7505382\/1349499693","profile_link_color":"0084B4","profile_sidebar_border_color":"000000","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false}},{"id":73546689,"id_str":"73546689","name":"test","uri":"\/sferik\/test","subscriber_count":0,"member_count":2,"mode":"private","description":"","slug":"test","full_name":"@sferik\/test","created_at":"Sun Jul 08 22:19:05 +0000 2012","following":true,"user":{"id":7505382,"id_str":"7505382","name":"Erik Michaels-Ober","screen_name":"sferik","location":"San Francisco","description":"Write code. Not too much. Mostly Ruby.","url":"https:\/\/github.com\/sferik","entities":{"url":{"urls":[{"url":"https:\/\/github.com\/sferik","expanded_url":null,"indices":[0,25]}]},"description":{"urls":[]}},"protected":false,"followers_count":8855,"friends_count":248,"listed_count":167,"created_at":"Mon Jul 16 12:59:01 +0000 2007","favourites_count":6063,"utc_offset":-28800,"time_zone":"Pacific Time (US & Canada)","geo_enabled":true,"verified":false,"statuses_count":11166,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"000000","profile_background_image_url":"http:\/\/a0.twimg.com\/profile_background_images\/677717672\/bb0b3653dcf0644e344823e0a2eb3382.png","profile_background_image_url_https":"https:\/\/si0.twimg.com\/profile_background_images\/677717672\/bb0b3653dcf0644e344823e0a2eb3382.png","profile_background_tile":false,"profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/1759857427\/image1326743606_normal.png","profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/1759857427\/image1326743606_normal.png","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/7505382\/1349499693","profile_link_color":"0084B4","profile_sidebar_border_color":"000000","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false}},{"id":20817728,"id_str":"20817728","name":"interesting","uri":"\/sferik\/interesting","subscriber_count":0,"member_count":4,"mode":"private","description":"People who are interesting.","slug":"interesting","full_name":"@sferik\/interesting","created_at":"Sat Sep 04 00:46:03 +0000 2010","following":true,"user":{"id":7505382,"id_str":"7505382","name":"Erik Michaels-Ober","screen_name":"sferik","location":"San Francisco","description":"Write code. Not too much. Mostly Ruby.","url":"https:\/\/github.com\/sferik","entities":{"url":{"urls":[{"url":"https:\/\/github.com\/sferik","expanded_url":null,"indices":[0,25]}]},"description":{"urls":[]}},"protected":false,"followers_count":8855,"friends_count":248,"listed_count":167,"created_at":"Mon Jul 16 12:59:01 +0000 2007","favourites_count":6063,"utc_offset":-28800,"time_zone":"Pacific Time (US & Canada)","geo_enabled":true,"verified":false,"statuses_count":11166,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"000000","profile_background_image_url":"http:\/\/a0.twimg.com\/profile_background_images\/677717672\/bb0b3653dcf0644e344823e0a2eb3382.png","profile_background_image_url_https":"https:\/\/si0.twimg.com\/profile_background_images\/677717672\/bb0b3653dcf0644e344823e0a2eb3382.png","profile_background_tile":false,"profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/1759857427\/image1326743606_normal.png","profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/1759857427\/image1326743606_normal.png","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/7505382\/1349499693","profile_link_color":"0084B4","profile_sidebar_border_color":"000000","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false}},{"id":20712515,"id_str":"20712515","name":"recommended","uri":"\/sferik\/recommended","subscriber_count":0,"member_count":71,"mode":"private","description":"Users recommended to me by Twitter","slug":"recommended","full_name":"@sferik\/recommended","created_at":"Thu Sep 02 18:29:24 +0000 2010","following":true,"user":{"id":7505382,"id_str":"7505382","name":"Erik Michaels-Ober","screen_name":"sferik","location":"San Francisco","description":"Write code. Not too much. Mostly Ruby.","url":"https:\/\/github.com\/sferik","entities":{"url":{"urls":[{"url":"https:\/\/github.com\/sferik","expanded_url":null,"indices":[0,25]}]},"description":{"urls":[]}},"protected":false,"followers_count":8855,"friends_count":248,"listed_count":167,"created_at":"Mon Jul 16 12:59:01 +0000 2007","favourites_count":6063,"utc_offset":-28800,"time_zone":"Pacific Time (US & Canada)","geo_enabled":true,"verified":false,"statuses_count":11166,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"000000","profile_background_image_url":"http:\/\/a0.twimg.com\/profile_background_images\/677717672\/bb0b3653dcf0644e344823e0a2eb3382.png","profile_background_image_url_https":"https:\/\/si0.twimg.com\/profile_background_images\/677717672\/bb0b3653dcf0644e344823e0a2eb3382.png","profile_background_tile":false,"profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/1759857427\/image1326743606_normal.png","profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/1759857427\/image1326743606_normal.png","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/7505382\/1349499693","profile_link_color":"0084B4","profile_sidebar_border_color":"000000","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false}},{"id":8863586,"id_str":"8863586","name":"presidents","uri":"\/sferik\/presidents","subscriber_count":0,"member_count":2,"mode":"public","description":"Presidents of the United States of America","slug":"presidents","full_name":"@sferik\/presidents","created_at":"Mon Mar 15 06:10:13 +0000 2010","following":true,"user":{"id":7505382,"id_str":"7505382","name":"Erik Michaels-Ober","screen_name":"sferik","location":"San Francisco","description":"Write code. Not too much. Mostly Ruby.","url":"https:\/\/github.com\/sferik","entities":{"url":{"urls":[{"url":"https:\/\/github.com\/sferik","expanded_url":null,"indices":[0,25]}]},"description":{"urls":[]}},"protected":false,"followers_count":8855,"friends_count":248,"listed_count":167,"created_at":"Mon Jul 16 12:59:01 +0000 2007","favourites_count":6063,"utc_offset":-28800,"time_zone":"Pacific Time (US & Canada)","geo_enabled":true,"verified":false,"statuses_count":11166,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"000000","profile_background_image_url":"http:\/\/a0.twimg.com\/profile_background_images\/677717672\/bb0b3653dcf0644e344823e0a2eb3382.png","profile_background_image_url_https":"https:\/\/si0.twimg.com\/profile_background_images\/677717672\/bb0b3653dcf0644e344823e0a2eb3382.png","profile_background_tile":false,"profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/1759857427\/image1326743606_normal.png","profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/1759857427\/image1326743606_normal.png","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/7505382\/1349499693","profile_link_color":"0084B4","profile_sidebar_border_color":"000000","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false}}]}
|
data/spec/helper.rb
CHANGED
@@ -21,6 +21,10 @@ RSpec.configure do |config|
|
|
21
21
|
config.expect_with :rspec do |c|
|
22
22
|
c.syntax = :expect
|
23
23
|
end
|
24
|
+
|
25
|
+
config.before(:each) do
|
26
|
+
stub_post("/oauth2/token").with(:body => "grant_type=client_credentials").to_return(:body => fixture("bearer_token.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
27
|
+
end
|
24
28
|
end
|
25
29
|
|
26
30
|
def a_delete(path)
|
@@ -829,4 +829,40 @@ describe Twitter::API::Lists do
|
|
829
829
|
end
|
830
830
|
end
|
831
831
|
|
832
|
+
describe "#lists_owned" do
|
833
|
+
context "with a screen name passed" do
|
834
|
+
before do
|
835
|
+
stub_get("/1.1/lists/ownerships.json").with(:query => {:screen_name => "sferik", :cursor => "-1"}).to_return(:body => fixture("ownerships.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
836
|
+
end
|
837
|
+
it "requests the correct resource" do
|
838
|
+
@client.lists_owned("sferik")
|
839
|
+
expect(a_get("/1.1/lists/ownerships.json").with(:query => {:screen_name => "sferik", :cursor => "-1"})).to have_been_made
|
840
|
+
end
|
841
|
+
it "returns the requested list" do
|
842
|
+
lists = @client.lists_owned("sferik")
|
843
|
+
expect(lists).to be_a Twitter::Cursor
|
844
|
+
expect(lists.lists).to be_an Array
|
845
|
+
expect(lists.lists.first).to be_a Twitter::List
|
846
|
+
expect(lists.lists.first.name).to eq "My favstar.fm list"
|
847
|
+
end
|
848
|
+
end
|
849
|
+
context "without a screen name passed" do
|
850
|
+
before do
|
851
|
+
stub_get("/1.1/account/verify_credentials.json").to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
852
|
+
stub_get("/1.1/lists/ownerships.json").with(:query => {:screen_name => "sferik", :cursor => "-1"}).to_return(:body => fixture("ownerships.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
853
|
+
end
|
854
|
+
it "requests the correct resource" do
|
855
|
+
@client.lists_owned
|
856
|
+
expect(a_get("/1.1/lists/ownerships.json").with(:query => {:screen_name => "sferik", :cursor => "-1"})).to have_been_made
|
857
|
+
end
|
858
|
+
it "returns the requested list" do
|
859
|
+
lists = @client.lists_owned
|
860
|
+
expect(lists).to be_a Twitter::Cursor
|
861
|
+
expect(lists.lists).to be_an Array
|
862
|
+
expect(lists.lists.first).to be_a Twitter::List
|
863
|
+
expect(lists.lists.first.name).to eq "My favstar.fm list"
|
864
|
+
end
|
865
|
+
end
|
866
|
+
end
|
867
|
+
|
832
868
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Twitter::API::OAuth do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@client = Twitter::Client.new(:consumer_key => 'CK', :consumer_secret => 'CS')
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "#token" do
|
10
|
+
before do
|
11
|
+
# WebMock treats Basic Auth differently so we have to chack against the full url with credentials.
|
12
|
+
@oauth2_token_url = "https://CK:CS@api.twitter.com/oauth2/token"
|
13
|
+
stub_request(:post, @oauth2_token_url).with(:body => "grant_type=client_credentials").to_return(:body => fixture("bearer_token.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
14
|
+
end
|
15
|
+
it "requests the correct resource" do
|
16
|
+
@client.token
|
17
|
+
expect(a_request(:post, @oauth2_token_url).with(:body => {:grant_type => "client_credentials"})).to have_been_made
|
18
|
+
end
|
19
|
+
it "requests with the correct headers" do
|
20
|
+
@client.token
|
21
|
+
expect(a_request(:post, @oauth2_token_url).with(:headers => {
|
22
|
+
:content_type => "application/x-www-form-urlencoded; charset=UTF-8",
|
23
|
+
:accept => "*/*"
|
24
|
+
})).to have_been_made
|
25
|
+
end
|
26
|
+
it "returns the bearer token" do
|
27
|
+
bearer_token = @client.token
|
28
|
+
expect(bearer_token.access_token).to eq "AAAA%2FAAA%3DAAAAAAAA"
|
29
|
+
expect(bearer_token.token_type).to eq "bearer"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#invalidate_token" do
|
34
|
+
before do
|
35
|
+
stub_post("/oauth2/invalidate_token").with(:body => {:access_token => "AAAA%2FAAA%3DAAAAAAAA"}).to_return(:body => '{"access_token" : "AAAA%2FAAA%3DAAAAAAAA"}', :headers => {:content_type => "application/json; charset=utf-8"})
|
36
|
+
@client.bearer_token = "AAAA%2FAAA%3DAAAAAAAA"
|
37
|
+
end
|
38
|
+
it "requests the correct resource" do
|
39
|
+
@client.invalidate_token("AAAA%2FAAA%3DAAAAAAAA")
|
40
|
+
expect(a_post("/oauth2/invalidate_token").with(:body => {:access_token => "AAAA%2FAAA%3DAAAAAAAA"})).to have_been_made
|
41
|
+
end
|
42
|
+
it "returns the invalidated token" do
|
43
|
+
token = @client.invalidate_token("AAAA%2FAAA%3DAAAAAAAA")
|
44
|
+
expect(token.access_token).to eq "AAAA%2FAAA%3DAAAAAAAA"
|
45
|
+
expect(token.token_type).to eq nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -256,4 +256,30 @@ describe Twitter::API::Tweets do
|
|
256
256
|
end
|
257
257
|
end
|
258
258
|
|
259
|
+
describe "#retweeters_ids" do
|
260
|
+
before do
|
261
|
+
stub_get("/1.1/statuses/retweeters/ids.json").with(:query => {:id => "25938088801", :cursor => "-1"}).to_return(:body => fixture("ids_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
262
|
+
end
|
263
|
+
it "requests the correct resource" do
|
264
|
+
@client.retweeters_ids(25938088801)
|
265
|
+
expect(a_get("/1.1/statuses/retweeters/ids.json").with(:query => {:id => "25938088801", :cursor => "-1"})).to have_been_made
|
266
|
+
end
|
267
|
+
it "returns a collection of user IDs belonging to users who have retweeted the specified Tweet" do
|
268
|
+
retweeters_ids = @client.retweeters_ids(25938088801)
|
269
|
+
expect(retweeters_ids).to be_a Twitter::Cursor
|
270
|
+
expect(retweeters_ids.ids).to be_an Array
|
271
|
+
expect(retweeters_ids.ids.first).to eq 14100886
|
272
|
+
end
|
273
|
+
context "with all" do
|
274
|
+
before do
|
275
|
+
stub_get("/1.1/statuses/retweeters/ids.json").with(:query => {:id => "25938088801", :cursor => "1305102810874389703"}).to_return(:body => fixture("ids_list2.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
276
|
+
end
|
277
|
+
it "requests the correct resource" do
|
278
|
+
@client.retweeters_ids(25938088801).all
|
279
|
+
expect(a_get("/1.1/statuses/retweeters/ids.json").with(:query => {:id => "25938088801", :cursor => "-1"})).to have_been_made
|
280
|
+
expect(a_get("/1.1/statuses/retweeters/ids.json").with(:query => {:id => "25938088801", :cursor => "1305102810874389703"})).to have_been_made
|
281
|
+
end
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
259
285
|
end
|
data/spec/twitter/client_spec.rb
CHANGED
@@ -38,6 +38,7 @@ describe Twitter::Client do
|
|
38
38
|
:middleware => Proc.new{},
|
39
39
|
:oauth_token => 'OT',
|
40
40
|
:oauth_token_secret => 'OS',
|
41
|
+
:bearer_token => 'BT',
|
41
42
|
:identity_map => ::Hash
|
42
43
|
}
|
43
44
|
end
|
@@ -97,6 +98,28 @@ describe Twitter::Client do
|
|
97
98
|
end
|
98
99
|
end
|
99
100
|
|
101
|
+
describe "#user_token?" do
|
102
|
+
it "returns true if the user token/secret are present" do
|
103
|
+
client = Twitter::Client.new(:consumer_key => 'CK', :consumer_secret => 'CS', :oauth_token => 'OT', :oauth_token_secret => 'OS')
|
104
|
+
expect(client.user_token?).to be_true
|
105
|
+
end
|
106
|
+
it "returns false if the user token/secret are not completely present" do
|
107
|
+
client = Twitter::Client.new(:consumer_key => 'CK', :consumer_secret => 'CS', :oauth_token => 'OT')
|
108
|
+
expect(client.user_token?).to be_false
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe "#bearer_token?" do
|
113
|
+
it "returns true if the app token is present" do
|
114
|
+
client = Twitter::Client.new(:consumer_key => 'CK', :consumer_secret => 'CS', :bearer_token => 'BT')
|
115
|
+
expect(client.bearer_token?).to be_true
|
116
|
+
end
|
117
|
+
it "returns false if the bearer_token is not present" do
|
118
|
+
client = Twitter::Client.new(:consumer_key => 'CK', :consumer_secret => 'CS')
|
119
|
+
expect(client.bearer_token?).to be_false
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
100
123
|
describe "#credentials?" do
|
101
124
|
it "returns true if all credentials are present" do
|
102
125
|
client = Twitter::Client.new(:consumer_key => 'CK', :consumer_secret => 'CS', :oauth_token => 'OT', :oauth_token_secret => 'OS')
|
@@ -139,10 +162,10 @@ describe Twitter::Client do
|
|
139
162
|
end
|
140
163
|
end
|
141
164
|
|
142
|
-
describe "#
|
165
|
+
describe "#oauth_auth_header" do
|
143
166
|
it "creates the correct auth headers" do
|
144
167
|
uri = "/1.1/direct_messages.json"
|
145
|
-
authorization = subject.send(:
|
168
|
+
authorization = subject.send(:oauth_auth_header, :get, uri)
|
146
169
|
expect(authorization.options[:signature_method]).to eq "HMAC-SHA1"
|
147
170
|
expect(authorization.options[:version]).to eq "1.0"
|
148
171
|
expect(authorization.options[:consumer_key]).to eq "CK"
|
@@ -152,4 +175,23 @@ describe Twitter::Client do
|
|
152
175
|
end
|
153
176
|
end
|
154
177
|
|
178
|
+
describe "#bearer_auth_header" do
|
179
|
+
subject do
|
180
|
+
Twitter::Client.new(:bearer_token => "BT")
|
181
|
+
end
|
182
|
+
|
183
|
+
it "creates the correct auth headers with supplied bearer_token" do
|
184
|
+
uri = "/1.1/direct_messages.json"
|
185
|
+
authorization = subject.send(:bearer_auth_header)
|
186
|
+
expect(authorization).to eq "Bearer BT"
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
describe "#bearer_token_credentials_auth_header" do
|
191
|
+
it "creates the correct auth header with supplied consumer_key and consumer_secret" do
|
192
|
+
uri = "/1.1/direct_messages.json"
|
193
|
+
authorization = subject.send(:bearer_token_credentials_auth_header)
|
194
|
+
expect(authorization).to eq "Basic #{Base64.strict_encode64("CK:CS")}"
|
195
|
+
end
|
196
|
+
end
|
155
197
|
end
|
@@ -96,7 +96,7 @@ describe Twitter::SearchResults do
|
|
96
96
|
expect(since_id).to be_nil
|
97
97
|
end
|
98
98
|
end
|
99
|
-
|
99
|
+
|
100
100
|
describe "#next_results?" do
|
101
101
|
it "returns true when next_results is set" do
|
102
102
|
next_results = Twitter::SearchResults.new(:search_metadata => {:next_results => "?"}).next_results?
|
@@ -112,4 +112,19 @@ describe Twitter::SearchResults do
|
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
|
+
describe "#next_results" do
|
116
|
+
let(:next_results) {Twitter::SearchResults.new(:search_metadata =>
|
117
|
+
{:next_results => "?max_id=249279667666817023&q=%23freebandnames&count=4&include_entities=1&result_type=mixed"
|
118
|
+
}).next_results
|
119
|
+
}
|
120
|
+
|
121
|
+
it "returns a hash of query parameters" do
|
122
|
+
expect(next_results).to be_a Hash
|
123
|
+
end
|
124
|
+
|
125
|
+
it "returns a max_id" do
|
126
|
+
expect(next_results[:max_id]).to eq "249279667666817023"
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
115
130
|
end
|
data/spec/twitter/tweet_spec.rb
CHANGED
@@ -40,6 +40,26 @@ describe Twitter::Tweet do
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
+
describe "#entities?" do
|
44
|
+
it "returns false if there are no entities set" do
|
45
|
+
tweet = Twitter::Tweet.new(:id => 28669546014)
|
46
|
+
expect(tweet.entities?).to be_false
|
47
|
+
end
|
48
|
+
|
49
|
+
it "returns true if there are entities set" do
|
50
|
+
urls_array = [
|
51
|
+
{
|
52
|
+
:url => 'http://example.com/t.co',
|
53
|
+
:expanded_url => 'http://example.com/expanded',
|
54
|
+
:display_url => 'example.com/expanded',
|
55
|
+
:indices => [10, 33],
|
56
|
+
}
|
57
|
+
]
|
58
|
+
tweet = Twitter::Tweet.new(:id => 28669546014, :entities => {:urls => urls_array})
|
59
|
+
expect(tweet.entities?).to be_true
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
43
63
|
describe "#favoriters_count" do
|
44
64
|
it "returns the count of favoriters when favoriters_count is set" do
|
45
65
|
tweet = Twitter::Tweet.new(:id => 28669546014, :favoriters_count => '1')
|
@@ -239,23 +259,26 @@ describe Twitter::Tweet do
|
|
239
259
|
end
|
240
260
|
end
|
241
261
|
|
242
|
-
describe "#
|
243
|
-
it "returns
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
it "returns true if there are entities set" do
|
249
|
-
urls_array = [
|
250
|
-
{
|
251
|
-
:url => 'http://example.com/t.co',
|
252
|
-
:expanded_url => 'http://example.com/expanded',
|
253
|
-
:display_url => 'example.com/expanded',
|
254
|
-
:indices => [10, 33],
|
255
|
-
}
|
262
|
+
describe "#symbols" do
|
263
|
+
it "returns an Array of Entity::Symbol when symbols are set" do
|
264
|
+
symbols_array = [
|
265
|
+
{ :text => 'PEP', :indices => [114, 118] },
|
266
|
+
{ :text => 'COKE', :indices => [128, 133] }
|
256
267
|
]
|
257
|
-
|
258
|
-
expect(
|
268
|
+
symbols = Twitter::Tweet.new(:id => 28669546014, :entities => {:symbols => symbols_array}).symbols
|
269
|
+
expect(symbols).to be_an Array
|
270
|
+
expect(symbols.size).to eq 2
|
271
|
+
expect(symbols.first).to be_a Twitter::Entity::Symbol
|
272
|
+
expect(symbols.first.indices).to eq [114, 118]
|
273
|
+
expect(symbols.first.text).to eq 'PEP'
|
274
|
+
end
|
275
|
+
it "is empty when not set" do
|
276
|
+
symbols = Twitter::Tweet.new(:id => 28669546014).symbols
|
277
|
+
expect(symbols).to be_empty
|
278
|
+
end
|
279
|
+
it "warns when not set" do
|
280
|
+
Twitter::Tweet.new(:id => 28669546014).symbols
|
281
|
+
expect($stderr.string).to match(/To get symbols, you must pass `:include_entities => true` when requesting the Twitter::Tweet\./)
|
259
282
|
end
|
260
283
|
end
|
261
284
|
|
data/spec/twitter_spec.rb
CHANGED
@@ -91,7 +91,13 @@ describe Twitter do
|
|
91
91
|
end
|
92
92
|
|
93
93
|
describe ".credentials?" do
|
94
|
-
it "returns true if
|
94
|
+
it "returns true if only bearer_token is supplied" do
|
95
|
+
Twitter.configure do |config|
|
96
|
+
config.bearer_token = 'BT'
|
97
|
+
end
|
98
|
+
expect(Twitter.credentials?).to be_true
|
99
|
+
end
|
100
|
+
it "returns true if all oauth credentials are present" do
|
95
101
|
Twitter.configure do |config|
|
96
102
|
config.consumer_key = 'CK'
|
97
103
|
config.consumer_secret = 'CS'
|
data/twitter.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.licenses = ['MIT']
|
20
20
|
spec.name = 'twitter'
|
21
21
|
spec.require_paths = ['lib']
|
22
|
-
spec.required_rubygems_version = '>= 1.3.
|
22
|
+
spec.required_rubygems_version = '>= 1.3.5'
|
23
23
|
spec.signing_key = File.expand_path("~/.gem/private_key.pem") if $0 =~ /gem\z/
|
24
24
|
spec.summary = spec.description
|
25
25
|
spec.test_files = Dir.glob("spec/**/*")
|
metadata
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twitter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.7.0
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- John Nunemaker
|
@@ -12,32 +13,39 @@ authors:
|
|
12
13
|
autorequire:
|
13
14
|
bindir: bin
|
14
15
|
cert_chain:
|
15
|
-
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
16
|
+
- !binary |-
|
17
|
+
LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURMakNDQWhhZ0F3SUJB
|
18
|
+
Z0lCQURBTkJna3Foa2lHOXcwQkFRVUZBREE5TVE4d0RRWURWUVFEREFaelpt
|
19
|
+
VnkKYVdzeEZUQVRCZ29Ka2lhSmsvSXNaQUVaRmdWbmJXRnBiREVUTUJFR0Nn
|
20
|
+
bVNKb21UOGl4a0FSa1dBMk52YlRBZQpGdzB4TXpBeU1ETXhNREF5TWpkYUZ3
|
21
|
+
MHhOREF5TURNeE1EQXlNamRhTUQweER6QU5CZ05WQkFNTUJuTm1aWEpwCmF6
|
22
|
+
RVZNQk1HQ2dtU0pvbVQ4aXhrQVJrV0JXZHRZV2xzTVJNd0VRWUtDWkltaVpQ
|
23
|
+
eUxHUUJHUllEWTI5dE1JSUIKSWpBTkJna3Foa2lHOXcwQkFRRUZBQU9DQVE4
|
24
|
+
QU1JSUJDZ0tDQVFFQWwweDVkeDh1S3hpN1Rrckl1eUJVVEpWQgp2MW85M25V
|
25
|
+
QjlqL3k0TTk2Z1Yycll3QWNpMUpQQnNlTmQ2RnliempvM1lHdUhsN0VRSHVT
|
26
|
+
SE5hZjFwMmx4ZXcvCnk2MEpYSUpCQmdQY0RLL0tDUDROVUhvZm0wamZvWUQr
|
27
|
+
SDV1TkpmSENOcTcvWnNUeE90RTNSYTkyczBCQ01UcG0Kd0JNTWxXUjVNdGRF
|
28
|
+
aElZdUJPNFhobmVqWWdIMEwvN0JMMmx5bW50Vm5zci9hZ2RRb29qUUNOMUlR
|
29
|
+
bXNSSnZyUgpkdVpSTzN0WnZvSW8xcEJjNEpFZWhEdXFDZXlCZ1BMT3FNb0t0
|
30
|
+
UWxvbGQxVFFzMWtXVUJLN0tXTUZFaEtDL0tnCnp5ektSSFFvOXlEWXdPdllu
|
31
|
+
Z29CTFkrVC9sd0NUNGR5c3NkaHpSYmZueEFoYUt1NFNBc3NJd2FDMDF5Vm93
|
32
|
+
SUQKQVFBQm96a3dOekFKQmdOVkhSTUVBakFBTUIwR0ExVWREZ1FXQkJTMHJ1
|
33
|
+
RGZSYWs1Y2kxT3BETlgvWmRERWtJcwppVEFMQmdOVkhROEVCQU1DQkxBd0RR
|
34
|
+
WUpLb1pJaHZjTkFRRUZCUUFEZ2dFQkFISFNNcy9NUDBzT2FMa0V2NEpvCnp2
|
35
|
+
a20zcW41QTZ0MHZhSHg3NzRjbWVqeU1VKzV3eVN4UmV6c3BMN1VMaDlOZXVL
|
36
|
+
Mk9oVStPZTNUcHFyQWc1VEsKUjhHUUlMblZ1MkZlbUdBNnNBa1BEbGNQdGdB
|
37
|
+
NmllSTE5UFpPRjZIVkxtYy9JRC9kUC9OZ1pXV3pFZXFRS21jSwoyK0hNK1NF
|
38
|
+
RURoWmtTY1lla3c0Wk9lMTY0WnRaRzgxNm9BdjV4MHBHaXRTSWt1bVVwN1Y4
|
39
|
+
aUVaLzZlaHI3WTllClhPZzRlZXVuNUwvSmptakFSb1cya05kdmtSRDNjMkVl
|
40
|
+
U0xxV3ZRUnNCbHlwSGZoczZKSnVMbHlaUEdoVTNSL3YKU2YzbFZLcEJDV2dS
|
41
|
+
cEdUdnk0NVhWcEIrNTl5MzNQSm1FdVExUFRFT1l2UXlhbzlVS01BQWFBTi83
|
42
|
+
cVdRdGpsMApobHc9Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K
|
43
|
+
date: 2013-05-30 00:00:00.000000000 Z
|
37
44
|
dependencies:
|
38
45
|
- !ruby/object:Gem::Dependency
|
39
46
|
name: faraday
|
40
47
|
requirement: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
41
49
|
requirements:
|
42
50
|
- - ~>
|
43
51
|
- !ruby/object:Gem::Version
|
@@ -48,6 +56,7 @@ dependencies:
|
|
48
56
|
type: :runtime
|
49
57
|
prerelease: false
|
50
58
|
version_requirements: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
51
60
|
requirements:
|
52
61
|
- - ~>
|
53
62
|
- !ruby/object:Gem::Version
|
@@ -58,6 +67,7 @@ dependencies:
|
|
58
67
|
- !ruby/object:Gem::Dependency
|
59
68
|
name: multi_json
|
60
69
|
requirement: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
61
71
|
requirements:
|
62
72
|
- - ~>
|
63
73
|
- !ruby/object:Gem::Version
|
@@ -65,6 +75,7 @@ dependencies:
|
|
65
75
|
type: :runtime
|
66
76
|
prerelease: false
|
67
77
|
version_requirements: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
68
79
|
requirements:
|
69
80
|
- - ~>
|
70
81
|
- !ruby/object:Gem::Version
|
@@ -72,6 +83,7 @@ dependencies:
|
|
72
83
|
- !ruby/object:Gem::Dependency
|
73
84
|
name: simple_oauth
|
74
85
|
requirement: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
75
87
|
requirements:
|
76
88
|
- - ~>
|
77
89
|
- !ruby/object:Gem::Version
|
@@ -79,6 +91,7 @@ dependencies:
|
|
79
91
|
type: :runtime
|
80
92
|
prerelease: false
|
81
93
|
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
82
95
|
requirements:
|
83
96
|
- - ~>
|
84
97
|
- !ruby/object:Gem::Version
|
@@ -86,6 +99,7 @@ dependencies:
|
|
86
99
|
- !ruby/object:Gem::Dependency
|
87
100
|
name: bundler
|
88
101
|
requirement: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
89
103
|
requirements:
|
90
104
|
- - ~>
|
91
105
|
- !ruby/object:Gem::Version
|
@@ -93,6 +107,7 @@ dependencies:
|
|
93
107
|
type: :development
|
94
108
|
prerelease: false
|
95
109
|
version_requirements: !ruby/object:Gem::Requirement
|
110
|
+
none: false
|
96
111
|
requirements:
|
97
112
|
- - ~>
|
98
113
|
- !ruby/object:Gem::Version
|
@@ -129,6 +144,7 @@ files:
|
|
129
144
|
- lib/twitter/api/friends_and_followers.rb
|
130
145
|
- lib/twitter/api/help.rb
|
131
146
|
- lib/twitter/api/lists.rb
|
147
|
+
- lib/twitter/api/oauth.rb
|
132
148
|
- lib/twitter/api/places_and_geo.rb
|
133
149
|
- lib/twitter/api/saved_searches.rb
|
134
150
|
- lib/twitter/api/search.rb
|
@@ -152,6 +168,7 @@ files:
|
|
152
168
|
- lib/twitter/default.rb
|
153
169
|
- lib/twitter/direct_message.rb
|
154
170
|
- lib/twitter/entity/hashtag.rb
|
171
|
+
- lib/twitter/entity/symbol.rb
|
155
172
|
- lib/twitter/entity/url.rb
|
156
173
|
- lib/twitter/entity/user_mention.rb
|
157
174
|
- lib/twitter/entity.rb
|
@@ -202,6 +219,7 @@ files:
|
|
202
219
|
- lib/twitter/source_user.rb
|
203
220
|
- lib/twitter/suggestion.rb
|
204
221
|
- lib/twitter/target_user.rb
|
222
|
+
- lib/twitter/token.rb
|
205
223
|
- lib/twitter/trend.rb
|
206
224
|
- lib/twitter/tweet.rb
|
207
225
|
- lib/twitter/user.rb
|
@@ -213,6 +231,7 @@ files:
|
|
213
231
|
- spec/fixtures/already_retweeted.json
|
214
232
|
- spec/fixtures/bad_gateway.json
|
215
233
|
- spec/fixtures/bad_request.json
|
234
|
+
- spec/fixtures/bearer_token.json
|
216
235
|
- spec/fixtures/by_friends.json
|
217
236
|
- spec/fixtures/category.json
|
218
237
|
- spec/fixtures/configuration.json
|
@@ -245,6 +264,7 @@ files:
|
|
245
264
|
- spec/fixtures/not_following.json
|
246
265
|
- spec/fixtures/not_found.json
|
247
266
|
- spec/fixtures/oembed.json
|
267
|
+
- spec/fixtures/ownerships.json
|
248
268
|
- spec/fixtures/pbjt.gif
|
249
269
|
- spec/fixtures/pengwynn.json
|
250
270
|
- spec/fixtures/phoenix_search.phoenix
|
@@ -252,7 +272,6 @@ files:
|
|
252
272
|
- spec/fixtures/places.json
|
253
273
|
- spec/fixtures/privacy.json
|
254
274
|
- spec/fixtures/profile_banner.json
|
255
|
-
- spec/fixtures/rate_limit_status.json
|
256
275
|
- spec/fixtures/resolve.json
|
257
276
|
- spec/fixtures/retweet.json
|
258
277
|
- spec/fixtures/retweets.json
|
@@ -295,6 +314,7 @@ files:
|
|
295
314
|
- spec/twitter/api/geo_spec.rb
|
296
315
|
- spec/twitter/api/help_spec.rb
|
297
316
|
- spec/twitter/api/lists_spec.rb
|
317
|
+
- spec/twitter/api/oauth_spec.rb
|
298
318
|
- spec/twitter/api/saved_searches_spec.rb
|
299
319
|
- spec/twitter/api/search_spec.rb
|
300
320
|
- spec/twitter/api/spam_reporting_spec.rb
|
@@ -340,26 +360,27 @@ files:
|
|
340
360
|
homepage: http://sferik.github.com/twitter/
|
341
361
|
licenses:
|
342
362
|
- MIT
|
343
|
-
metadata: {}
|
344
363
|
post_install_message:
|
345
364
|
rdoc_options: []
|
346
365
|
require_paths:
|
347
366
|
- lib
|
348
367
|
required_ruby_version: !ruby/object:Gem::Requirement
|
368
|
+
none: false
|
349
369
|
requirements:
|
350
|
-
- - '>='
|
370
|
+
- - ! '>='
|
351
371
|
- !ruby/object:Gem::Version
|
352
372
|
version: '0'
|
353
373
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
374
|
+
none: false
|
354
375
|
requirements:
|
355
|
-
- - '>='
|
376
|
+
- - ! '>='
|
356
377
|
- !ruby/object:Gem::Version
|
357
|
-
version: 1.3.
|
378
|
+
version: 1.3.5
|
358
379
|
requirements: []
|
359
380
|
rubyforge_project:
|
360
|
-
rubygems_version:
|
381
|
+
rubygems_version: 1.8.23
|
361
382
|
signing_key:
|
362
|
-
specification_version:
|
383
|
+
specification_version: 3
|
363
384
|
summary: A Ruby interface to the Twitter API.
|
364
385
|
test_files:
|
365
386
|
- spec/fixtures/about_me.json
|
@@ -368,6 +389,7 @@ test_files:
|
|
368
389
|
- spec/fixtures/already_retweeted.json
|
369
390
|
- spec/fixtures/bad_gateway.json
|
370
391
|
- spec/fixtures/bad_request.json
|
392
|
+
- spec/fixtures/bearer_token.json
|
371
393
|
- spec/fixtures/by_friends.json
|
372
394
|
- spec/fixtures/category.json
|
373
395
|
- spec/fixtures/configuration.json
|
@@ -400,6 +422,7 @@ test_files:
|
|
400
422
|
- spec/fixtures/not_following.json
|
401
423
|
- spec/fixtures/not_found.json
|
402
424
|
- spec/fixtures/oembed.json
|
425
|
+
- spec/fixtures/ownerships.json
|
403
426
|
- spec/fixtures/pbjt.gif
|
404
427
|
- spec/fixtures/pengwynn.json
|
405
428
|
- spec/fixtures/phoenix_search.phoenix
|
@@ -407,7 +430,6 @@ test_files:
|
|
407
430
|
- spec/fixtures/places.json
|
408
431
|
- spec/fixtures/privacy.json
|
409
432
|
- spec/fixtures/profile_banner.json
|
410
|
-
- spec/fixtures/rate_limit_status.json
|
411
433
|
- spec/fixtures/resolve.json
|
412
434
|
- spec/fixtures/retweet.json
|
413
435
|
- spec/fixtures/retweets.json
|
@@ -450,6 +472,7 @@ test_files:
|
|
450
472
|
- spec/twitter/api/geo_spec.rb
|
451
473
|
- spec/twitter/api/help_spec.rb
|
452
474
|
- spec/twitter/api/lists_spec.rb
|
475
|
+
- spec/twitter/api/oauth_spec.rb
|
453
476
|
- spec/twitter/api/saved_searches_spec.rb
|
454
477
|
- spec/twitter/api/search_spec.rb
|
455
478
|
- spec/twitter/api/spam_reporting_spec.rb
|
metadata.gz.sig
CHANGED
Binary file
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: 43e71cbb5e79156a7a79f74e460db593730894fa
|
4
|
-
data.tar.gz: 60420417eb25d17246d2b4e39864b54cbb6c8732
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: 50730023660f01809773b2a9a91a3c8bbe295374320b43994377cddf5cf7acdd90d5d107ad0ab6aafb9c18100eb260306ae61cdda283610a86853087c904dbce
|
7
|
-
data.tar.gz: c84cdd2b416aa7e33a24671c676d01e516800c982224e1274bbac9e224bcd5028f77d5b177ce0ad6920a62da110419c866b5ca9b6f8e5ff943ca2427edcb3ee7
|
checksums.yaml.gz.sig
DELETED
Binary file
|
@@ -1 +0,0 @@
|
|
1
|
-
{"remaining_hits":19993,"hourly_limit":20000,"reset_time_in_seconds":1288060988,"reset_time":"Tue Oct 26 02:43:08 +0000 2010"}
|