twitter 4.8.0 → 4.8.1

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
@@ -1,3 +1,10 @@
1
+ 4.8.1
2
+ -----
3
+ * [Ignore case of profile image extension](https://github.com/sferik/twitter/commit/73760610e959ae868de23de3da661d237fbcb106)
4
+ * [Allow use of Twitter::Token in place of bearer token string](https://github.com/sferik/twitter/commit/13596bc60db36ecaf5a1df09ecb322d85d8c2922)
5
+ * [Add Twitter::API::Undocumented#tweet_count](https://github.com/sferik/twitter/commit/795458a25ec7b143a995e7f2f2043e523c11961c)
6
+ * [Add missing dependencies](https://github.com/sferik/twitter/commit/e07e034472df8b7aa44c779371cf1e25d8caa77d) ([@tmatilai](https://twitter.com/tmatilai))
7
+
1
8
  4.8.0
2
9
  -----
3
10
  * [Add `Twitter::SearchResults#refresh_url`](https://github.com/sferik/twitter/commit/6bf08c008de139aad3ec173461e8633bfa5a3bd8) ([@mustafaturan](https://twitter.com/mustafaturan))
@@ -31,11 +31,12 @@ module Twitter
31
31
  # @rate_limited No
32
32
  # @authentication Required
33
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.
34
+ # @param access_token [String, Twitter::Token] The bearer token to revoke.
35
35
  # @return [Twitter::Token] The invalidated token. token_type should be nil.
36
36
  # @example Revoke a token
37
37
  # Twitter.invalidate_token("AAAA%2FAAA%3DAAAAAAAA")
38
38
  def invalidate_token(access_token)
39
+ access_token = access_token.access_token if access_token.is_a?(Twitter::Token)
39
40
  object_from_response(Twitter::Token, :post, "/oauth2/invalidate_token", :access_token => access_token)
40
41
  end
41
42
  end
@@ -257,14 +257,21 @@ module Twitter
257
257
  end
258
258
 
259
259
  # Returns a collection of user IDs belonging to users who have retweeted the specified Tweet.
260
+ #
260
261
  # @see https://dev.twitter.com/docs/api/1.1/get/statuses/retweeters/ids
261
262
  # @rate_limited Yes
262
263
  # @authentication Required
263
264
  # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
264
265
  # @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)
266
+ # @overload retweeters_ids(options)
267
+ # @param options [Hash] A customizable set of options.
268
+ # @example Return a collection of user IDs belonging to users who have retweeted the specified Tweet
269
+ # Twitter.retweeters_ids({:id => 25938088801})
270
+ # @overload retweeters_ids(id, options={})
271
+ # @param id [Integer] The numerical ID of the desired Tweet.
272
+ # @param options [Hash] A customizable set of options.
273
+ # @example Return a collection of user IDs belonging to users who have retweeted the specified Tweet
274
+ # Twitter.retweeters_ids(25938088801)
268
275
  def retweeters_ids(*args)
269
276
  arguments = Twitter::API::Arguments.new(args)
270
277
  arguments.options[:id] ||= arguments.first
@@ -77,6 +77,21 @@ module Twitter
77
77
  end
78
78
  end
79
79
 
80
+ # Returns Tweets count for a URL
81
+ #
82
+ # @note Undocumented
83
+ # @rate_limited No
84
+ # @authentication Not required
85
+ # @return [Integer]
86
+ # @param url [Integer] A URL.
87
+ # @param options [Hash] A customizable set of options.
88
+ # @example Return Tweet count for http://twitter.com
89
+ # Twitter.tweet_count("http://twitter.com/")
90
+ def tweet_count(url, options={})
91
+ connection = Faraday.new("https://cdn.api.twitter.com", @connection_options.merge(:builder => @middleware))
92
+ connection.get("/1/urls/count.json", options.merge(:url => url)).body[:count]
93
+ end
94
+
80
95
  end
81
96
  end
82
97
  end
@@ -93,7 +93,7 @@ module Twitter
93
93
  request.headers[:accept] = '*/*' # It is important we set this, otherwise we get an error.
94
94
  elsif params.delete(:app_auth) || !user_token?
95
95
  unless bearer_token?
96
- @bearer_token = token[:access_token]
96
+ @bearer_token = token
97
97
  Twitter.client.bearer_token = @bearer_token if Twitter.client?
98
98
  end
99
99
  request.headers[:authorization] = bearer_auth_header
@@ -132,7 +132,11 @@ module Twitter
132
132
  end
133
133
 
134
134
  def bearer_auth_header
135
- "Bearer #{@bearer_token}"
135
+ if @bearer_token.is_a?(Twitter::Token) && @bearer_token.token_type == "bearer"
136
+ "Bearer #{@bearer_token.access_token}"
137
+ else
138
+ "Bearer #{@bearer_token}"
139
+ end
136
140
  end
137
141
 
138
142
  def oauth_auth_header(method, path, params={})
@@ -1,4 +1,5 @@
1
1
  require 'forwardable'
2
+ require 'twitter/default'
2
3
  require 'twitter/error/configuration_error'
3
4
 
4
5
  module Twitter
@@ -1,3 +1,5 @@
1
+ require 'twitter/rate_limit'
2
+
1
3
  module Twitter
2
4
  # Custom error class for rescuing from all Twitter errors
3
5
  class Error < StandardError
@@ -55,24 +55,69 @@ module Twitter
55
55
 
56
56
  # Returns a Hash of query parameters for the next result in the search
57
57
  #
58
- # Returned Hash can be merged into the previous search options list
59
- # to easily access the next page
60
- #
61
- # @return [Hash]
58
+ # @note Returned Hash can be merged into the previous search options list to easily access the next page.
59
+ # @return [Hash] The parameters needed to fetch the next page.
62
60
  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?
61
+ if next_results?
62
+ query_string = strip_first_character(@attrs[:search_metadata][:next_results])
63
+ query_string_to_hash(query_string)
64
+ end
64
65
  end
65
66
  alias next_page next_results
66
67
 
67
68
  # Returns a Hash of query parameters for the refresh URL in the search
68
69
  #
69
- # Returned Hash can be merged into the previous search options list
70
- # to easily access the refresh page
71
- #
72
- # @return [Hash]
70
+ # @note Returned Hash can be merged into the previous search options list to easily access the refresh page.
71
+ # @return [Hash] The parameters needed to refresh the page.
73
72
  def refresh_url
74
- Faraday::Utils.parse_nested_query(@attrs[:search_metadata][:refresh_url][1..-1]).inject({}) { |memo, (k,v)| memo[k.to_sym] = v; memo}
73
+ query_string = strip_first_character(@attrs[:search_metadata][:refresh_url])
74
+ query_string_to_hash(query_string)
75
75
  end
76
76
  alias refresh_page refresh_url
77
+
78
+ private
79
+
80
+ # Returns the string with the first character removed
81
+ #
82
+ # @param string [String]
83
+ # @return [String] A copy of string without the first character.
84
+ # @example Returns the query string with the question mark removed
85
+ # strip_first_character("?foo=bar&baz=qux") #=> "foo=bar&baz=qux"
86
+ def strip_first_character(string)
87
+ strip_first_character!(string.dup)
88
+ end
89
+
90
+ # Removes the first character from a string
91
+ #
92
+ # @param string [String]
93
+ # @return [String] The string without the first character.
94
+ # @example Remove the first character from a query string
95
+ # strip_first_character!("?foo=bar&baz=qux") #=> "foo=bar&baz=qux"
96
+ def strip_first_character!(string)
97
+ string[0] = ""
98
+ string
99
+ end
100
+
101
+ # Converts query string to a hash
102
+ #
103
+ # @param query_string [String] The query string of a URL.
104
+ # @return [Hash] The query string converted to a hash (with symbol keys).
105
+ # @example Convert query string to a hash
106
+ # query_string_to_hash("foo=bar&baz=qux") #=> {:foo=>"bar", :baz=>"qux"}
107
+ def query_string_to_hash(query_string)
108
+ symbolize_keys(Faraday::Utils.parse_nested_query(query_string))
109
+ end
110
+
111
+ # Converts hash's keys to symbols
112
+ #
113
+ # @note Does not support nested hashes.
114
+ # @param hash [Hash]
115
+ # @return [Hash] The hash with symbols as keys.
116
+ # @example Convert hash's keys to symbols
117
+ # symbolize_keys({"foo"=>"bar", "baz"=>"qux"}) #=> {:foo=>"bar", :baz=>"qux"}
118
+ def symbolize_keys(hash)
119
+ Hash[hash.map{|key, value| [key.to_sym, value]}]
120
+ end
121
+
77
122
  end
78
123
  end
@@ -4,7 +4,7 @@ require 'twitter/exceptable'
4
4
 
5
5
  module Twitter
6
6
  class User < Twitter::BasicUser
7
- PROFILE_IMAGE_SUFFIX_REGEX = /_normal(\.gif|\.jpe?g|\.png)$/
7
+ PROFILE_IMAGE_SUFFIX_REGEX = /_normal(\.gif|\.jpe?g|\.png)$/i
8
8
  include Twitter::Creatable
9
9
  include Twitter::Exceptable
10
10
  attr_reader :connections, :contributors_enabled, :default_profile,
@@ -2,7 +2,7 @@ module Twitter
2
2
  class Version
3
3
  MAJOR = 4 unless defined? Twitter::Version::MAJOR
4
4
  MINOR = 8 unless defined? Twitter::Version::MINOR
5
- PATCH = 0 unless defined? Twitter::Version::PATCH
5
+ PATCH = 1 unless defined? Twitter::Version::PATCH
6
6
  PRE = nil unless defined? Twitter::Version::PRE
7
7
 
8
8
  class << self
@@ -0,0 +1 @@
1
+ {"count":13845465,"url":"http:\/\/twitter.com\/"}
@@ -44,6 +44,13 @@ describe Twitter::API::OAuth do
44
44
  expect(token.access_token).to eq "AAAA%2FAAA%3DAAAAAAAA"
45
45
  expect(token.token_type).to eq nil
46
46
  end
47
+ context "with a token" do
48
+ it "requests the correct resource" do
49
+ token = Twitter::Token.new(:access_token => "AAAA%2FAAA%3DAAAAAAAA")
50
+ @client.invalidate_token(token)
51
+ expect(a_post("/oauth2/invalidate_token").with(:body => {:access_token => "AAAA%2FAAA%3DAAAAAAAA"})).to have_been_made
52
+ end
53
+ end
47
54
  end
48
55
 
49
56
  end
@@ -111,4 +111,19 @@ describe Twitter::API::Undocumented do
111
111
  end
112
112
  end
113
113
 
114
+ describe "#statuses_activity" do
115
+ before do
116
+ stub_request(:get, "https://cdn.api.twitter.com/1/urls/count.json").with(:query => {:url => "http://twitter.com"}).to_return(:body => fixture("count.json"), :headers => {:content_type => "application/json; charset=utf-8"})
117
+ end
118
+ it "requests the correct resource" do
119
+ @client.tweet_count("http://twitter.com")
120
+ expect(a_request(:get, "https://cdn.api.twitter.com/1/urls/count.json").with(:query => {:url => "http://twitter.com"})).to have_been_made
121
+ end
122
+ it "returns a Tweet count" do
123
+ tweet_count = @client.tweet_count("http://twitter.com")
124
+ expect(tweet_count).to be_an Integer
125
+ expect(tweet_count).to eq 13845465
126
+ end
127
+ end
128
+
114
129
  end
@@ -185,6 +185,14 @@ describe Twitter::User do
185
185
  expect(user.profile_image_url(:mini)).to eq "http://a0.twimg.com/profile_images/1759857427/image1326743606_mini.png"
186
186
  end
187
187
  end
188
+ context "with capitalized file extension" do
189
+ it "returns the correct image" do
190
+ user = Twitter::User.new(:id => 7505382, :profile_image_url_https => "https://si0.twimg.com/profile_images/67759670/DSCN2136_normal.JPG")
191
+ expect(user.profile_image_url(:original)).to eq "http://si0.twimg.com/profile_images/67759670/DSCN2136.JPG"
192
+ expect(user.profile_image_url(:bigger)).to eq "http://si0.twimg.com/profile_images/67759670/DSCN2136_bigger.JPG"
193
+ expect(user.profile_image_url(:mini)).to eq "http://si0.twimg.com/profile_images/67759670/DSCN2136_mini.JPG"
194
+ end
195
+ end
188
196
  end
189
197
 
190
198
  describe "#profile_image_url_https" do
@@ -218,6 +226,14 @@ describe Twitter::User do
218
226
  expect(user.profile_image_url_https(:mini)).to eq "https://a0.twimg.com/profile_images/1759857427/image1326743606_mini.png"
219
227
  end
220
228
  end
229
+ context "with capitalized file extension" do
230
+ it "returns the correct image" do
231
+ user = Twitter::User.new(:id => 7505382, :profile_image_url_https => "https://si0.twimg.com/profile_images/67759670/DSCN2136_normal.JPG")
232
+ expect(user.profile_image_url_https(:original)).to eq "https://si0.twimg.com/profile_images/67759670/DSCN2136.JPG"
233
+ expect(user.profile_image_url_https(:bigger)).to eq "https://si0.twimg.com/profile_images/67759670/DSCN2136_bigger.JPG"
234
+ expect(user.profile_image_url_https(:mini)).to eq "https://si0.twimg.com/profile_images/67759670/DSCN2136_mini.JPG"
235
+ end
236
+ end
221
237
  end
222
238
 
223
239
  describe "#profile_image_url?" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twitter
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.8.0
4
+ version: 4.8.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -40,7 +40,7 @@ cert_chain:
40
40
  U0xxV3ZRUnNCbHlwSGZoczZKSnVMbHlaUEdoVTNSL3YKU2YzbFZLcEJDV2dS
41
41
  cEdUdnk0NVhWcEIrNTl5MzNQSm1FdVExUFRFT1l2UXlhbzlVS01BQWFBTi83
42
42
  cVdRdGpsMApobHc9Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K
43
- date: 2013-06-12 00:00:00.000000000 Z
43
+ date: 2013-06-14 00:00:00.000000000 Z
44
44
  dependencies:
45
45
  - !ruby/object:Gem::Dependency
46
46
  name: faraday
@@ -236,6 +236,7 @@ files:
236
236
  - spec/fixtures/category.json
237
237
  - spec/fixtures/configuration.json
238
238
  - spec/fixtures/contributees.json
239
+ - spec/fixtures/count.json
239
240
  - spec/fixtures/direct_message.json
240
241
  - spec/fixtures/direct_messages.json
241
242
  - spec/fixtures/empty.json
@@ -394,6 +395,7 @@ test_files:
394
395
  - spec/fixtures/category.json
395
396
  - spec/fixtures/configuration.json
396
397
  - spec/fixtures/contributees.json
398
+ - spec/fixtures/count.json
397
399
  - spec/fixtures/direct_message.json
398
400
  - spec/fixtures/direct_messages.json
399
401
  - spec/fixtures/empty.json
metadata.gz.sig CHANGED
@@ -1,2 +1,2 @@
1
- �x����N�
2
- c�ڴ��۝1������P?���KݐnzxA��փ@48ڏD�"S� �1d�T��ꍫ��䦐�T2YDm?�ͷ������?1~2X��L������� &���������[2[�s+n5�ӱ=7��x�Ƞ��w��"و�p3м���>�=�� R ���Q�]p(`�P��?ö߀�j$���)�.��LfM0HcD�ѽ�=�RuȀzR2֓���ꔢ!hzb`uyB
1
+ ���T�@J(H�2�4Q����w}��3ҟ
2
+ .����tbtn�#�F0פR��/˦j���<��ֳ��'T�oRtF0D��#) }&i��Y{�+�^�X�*��+8��Zh)�c���'� �ꙫ�����b��L��j{O$6{{_���1ۙ�����$>0�_���y sO��E%��"P� �9I�������FNOe6g��tUxq(V��gM���ȝ��Hܟthf])�