twitter 5.6.0 → 5.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. data.tar.gz.sig +0 -0
  2. data/.yardopts +1 -0
  3. data/CHANGELOG.md +8 -0
  4. data/README.md +3 -3
  5. data/Rakefile +1 -1
  6. data/lib/twitter/base.rb +0 -8
  7. data/lib/twitter/client.rb +2 -1
  8. data/lib/twitter/cursor.rb +2 -15
  9. data/lib/twitter/error.rb +90 -18
  10. data/lib/twitter/geo_results.rb +0 -10
  11. data/lib/twitter/request.rb +4 -4
  12. data/lib/twitter/rest/api.rb +43 -0
  13. data/lib/twitter/rest/client.rb +10 -44
  14. data/lib/twitter/rest/direct_messages.rb +138 -0
  15. data/lib/twitter/rest/favorites.rb +108 -0
  16. data/lib/twitter/rest/friends_and_followers.rb +281 -0
  17. data/lib/twitter/rest/help.rb +56 -0
  18. data/lib/twitter/rest/lists.rb +497 -0
  19. data/lib/twitter/rest/oauth.rb +65 -0
  20. data/lib/twitter/rest/places_and_geo.rb +84 -0
  21. data/lib/twitter/rest/request/multipart_with_file.rb +5 -5
  22. data/lib/twitter/rest/response/parse_json.rb +2 -4
  23. data/lib/twitter/rest/response/raise_error.rb +24 -15
  24. data/lib/twitter/rest/saved_searches.rb +93 -0
  25. data/lib/twitter/rest/search.rb +37 -0
  26. data/lib/twitter/rest/spam_reporting.rb +27 -0
  27. data/lib/twitter/rest/suggested_users.rb +49 -0
  28. data/lib/twitter/rest/timelines.rb +200 -0
  29. data/lib/twitter/rest/trends.rb +57 -0
  30. data/lib/twitter/rest/tweets.rb +309 -0
  31. data/lib/twitter/rest/undocumented.rb +49 -0
  32. data/lib/twitter/rest/users.rb +383 -0
  33. data/lib/twitter/rest/utils.rb +205 -0
  34. data/lib/twitter/search_results.rb +2 -13
  35. data/lib/twitter/trend_results.rb +0 -10
  36. data/lib/twitter/version.rb +1 -1
  37. data/spec/helper.rb +1 -1
  38. data/spec/twitter/error_spec.rb +26 -42
  39. data/spec/twitter/rest/{api/direct_messages_spec.rb → direct_messages_spec.rb} +1 -1
  40. data/spec/twitter/rest/{api/favorites_spec.rb → favorites_spec.rb} +1 -1
  41. data/spec/twitter/rest/{api/friends_and_followers_spec.rb → friends_and_followers_spec.rb} +1 -1
  42. data/spec/twitter/rest/{api/geo_spec.rb → geo_spec.rb} +1 -1
  43. data/spec/twitter/rest/{api/help_spec.rb → help_spec.rb} +1 -1
  44. data/spec/twitter/rest/{api/lists_spec.rb → lists_spec.rb} +1 -1
  45. data/spec/twitter/rest/{api/oauth_spec.rb → oauth_spec.rb} +4 -8
  46. data/spec/twitter/rest/{api/saved_searches_spec.rb → saved_searches_spec.rb} +1 -1
  47. data/spec/twitter/rest/{api/search_spec.rb → search_spec.rb} +1 -1
  48. data/spec/twitter/rest/{api/spam_reporting_spec.rb → spam_reporting_spec.rb} +1 -1
  49. data/spec/twitter/rest/{api/suggested_users_spec.rb → suggested_users_spec.rb} +1 -1
  50. data/spec/twitter/rest/{api/timelines_spec.rb → timelines_spec.rb} +1 -1
  51. data/spec/twitter/rest/{api/trends_spec.rb → trends_spec.rb} +1 -1
  52. data/spec/twitter/rest/{api/tweets_spec.rb → tweets_spec.rb} +74 -5
  53. data/spec/twitter/rest/{api/undocumented_spec.rb → undocumented_spec.rb} +1 -1
  54. data/spec/twitter/rest/{api/users_spec.rb → users_spec.rb} +5 -5
  55. data/spec/twitter/tweet_spec.rb +1 -1
  56. data/twitter.gemspec +0 -1
  57. metadata +247 -237
  58. metadata.gz.sig +0 -0
  59. checksums.yaml +0 -7
  60. checksums.yaml.gz.sig +0 -0
  61. data/lib/twitter/error/already_favorited.rb +0 -10
  62. data/lib/twitter/error/already_posted.rb +0 -10
  63. data/lib/twitter/error/already_retweeted.rb +0 -10
  64. data/lib/twitter/error/bad_gateway.rb +0 -10
  65. data/lib/twitter/error/bad_request.rb +0 -10
  66. data/lib/twitter/error/configuration_error.rb +0 -8
  67. data/lib/twitter/error/forbidden.rb +0 -10
  68. data/lib/twitter/error/gateway_timeout.rb +0 -10
  69. data/lib/twitter/error/internal_server_error.rb +0 -10
  70. data/lib/twitter/error/not_acceptable.rb +0 -10
  71. data/lib/twitter/error/not_found.rb +0 -10
  72. data/lib/twitter/error/request_timeout.rb +0 -10
  73. data/lib/twitter/error/service_unavailable.rb +0 -10
  74. data/lib/twitter/error/too_many_requests.rb +0 -12
  75. data/lib/twitter/error/unauthorized.rb +0 -10
  76. data/lib/twitter/error/unprocessable_entity.rb +0 -10
  77. data/lib/twitter/rest/api/direct_messages.rb +0 -140
  78. data/lib/twitter/rest/api/favorites.rb +0 -115
  79. data/lib/twitter/rest/api/friends_and_followers.rb +0 -284
  80. data/lib/twitter/rest/api/help.rb +0 -58
  81. data/lib/twitter/rest/api/lists.rb +0 -500
  82. data/lib/twitter/rest/api/oauth.rb +0 -67
  83. data/lib/twitter/rest/api/places_and_geo.rb +0 -86
  84. data/lib/twitter/rest/api/saved_searches.rb +0 -95
  85. data/lib/twitter/rest/api/search.rb +0 -39
  86. data/lib/twitter/rest/api/spam_reporting.rb +0 -29
  87. data/lib/twitter/rest/api/suggested_users.rb +0 -51
  88. data/lib/twitter/rest/api/timelines.rb +0 -202
  89. data/lib/twitter/rest/api/trends.rb +0 -58
  90. data/lib/twitter/rest/api/tweets.rb +0 -297
  91. data/lib/twitter/rest/api/undocumented.rb +0 -51
  92. data/lib/twitter/rest/api/users.rb +0 -383
  93. data/lib/twitter/rest/api/utils.rb +0 -212
data.tar.gz.sig CHANGED
Binary file
data/.yardopts CHANGED
@@ -11,4 +11,5 @@ README.md
11
11
  examples/AllTweets.md
12
12
  examples/Configuration.md
13
13
  examples/RateLimiting.md
14
+ examples/Search.md
14
15
  examples/Update.md
@@ -1,3 +1,11 @@
1
+ 5.7.0
2
+ -----
3
+ * [Remove `Twitter::Base.from_response` method](https://github.com/sferik/twitter/commit/6f9a352adaa5eee0611fa8d2e45fc7349b5cecae)
4
+ * [Remove `Twitter::REST::API` namespace](https://github.com/sferik/twitter/commit/f9c4e8214bfe0e4cbd13681a6454956f2c6ac21b)
5
+ * [Remove `descendants_tracker`](https://github.com/sferik/twitter/commit/4cbcb0fc58c55b84b642bc7c66085bb581e9b20a)
6
+ * [Remove unused `HTTP_STATUS_CODE` constants](https://github.com/sferik/twitter/commit/b45d89bc96f11079b31976f14ade4f89d50b4dc9)
7
+ * [Remove `Twitter::Error#cause`](https://github.com/sferik/twitter/commit/a5748b925aa3220e7388311bd0228a62d45d09a4)
8
+
1
9
  5.6.0
2
10
  -----
3
11
  * [Replace custom `Twitter::NullObject` with `Naught`](https://github.com/sferik/twitter/commit/bc3990e3588f889569f1c92e465c329c508ce32e)
data/README.md CHANGED
@@ -381,7 +381,7 @@ at the beginning:
381
381
  * `#list_remove_members` is now `#remove_list_members`
382
382
  * `#list_add_member` is now `#add_list_member`
383
383
  * `#list_add_members` is now `#add_list_members`
384
- * `#lists_owned` is now `#owned_list`
384
+ * `#lists_owned` is now `#owned_lists`
385
385
  * `#saved_search_create` is now `#create_saved_search`
386
386
  * `#saved_search_destroy` is now `#destroy_saved_search`
387
387
  * `#status_destroy` is now `#destroy_status`
@@ -547,10 +547,10 @@ client.mentions_timeline
547
547
  ```ruby
548
548
  client.status(27558893223)
549
549
  ```
550
- **Collect the 3 most recent marriage proposals to @justinbieber**
550
+ **Collect the three most recent marriage proposals to @justinbieber**
551
551
 
552
552
  ```ruby
553
- client.search("to:justinbieber marry me", :count => 3, :result_type => "recent").take(3).collect do |tweet|
553
+ client.search("to:justinbieber marry me", :result_type => "recent").take(3).collect do |tweet|
554
554
  "#{tweet.user.screen_name}: #{tweet.text}"
555
555
  end
556
556
  ```
data/Rakefile CHANGED
@@ -31,7 +31,7 @@ end
31
31
 
32
32
  require 'yardstick/rake/verify'
33
33
  Yardstick::Rake::Verify.new do |verify|
34
- verify.threshold = 59.8
34
+ verify.threshold = 59.7
35
35
  end
36
36
 
37
37
  task :default => [:spec, :rubocop, :verify_measurements]
@@ -15,14 +15,6 @@ module Twitter
15
15
  deprecate_alias :to_hsh, :to_h
16
16
 
17
17
  class << self
18
- # Construct an object from a response hash
19
- #
20
- # @param response [Hash]
21
- # @return [Twitter::Base]
22
- def from_response(response = {})
23
- new(response[:body])
24
- end
25
-
26
18
  # Define methods that retrieve the value from attributes
27
19
  #
28
20
  # @param attrs [Array, Symbol]
@@ -1,5 +1,6 @@
1
1
  require 'addressable/uri'
2
2
  require 'simple_oauth'
3
+ require 'twitter/error'
3
4
  require 'twitter/utils'
4
5
  require 'twitter/version'
5
6
 
@@ -59,7 +60,7 @@ module Twitter
59
60
  def validate_credential_type!
60
61
  credentials.each do |credential, value|
61
62
  next if value.nil?
62
- fail(Error::ConfigurationError.new("Invalid #{credential} specified: #{value.inspect} must be a string or symbol.")) unless value.is_a?(String) || value.is_a?(Symbol)
63
+ fail(Twitter::Error::ConfigurationError.new("Invalid #{credential} specified: #{value.inspect} must be a string or symbol.")) unless value.is_a?(String) || value.is_a?(Symbol)
63
64
  end
64
65
  end
65
66
 
@@ -10,19 +10,6 @@ module Twitter
10
10
  deprecate_alias :to_hash, :to_h
11
11
  deprecate_alias :to_hsh, :to_h
12
12
 
13
- class << self
14
- # Construct a new Cursor object from a response hash
15
- #
16
- # @param response [Hash]
17
- # @param key [String, Symbol] The key to fetch the data from the response
18
- # @param klass [Class] The class to instantiate objects in the response
19
- # @param request [Twitter::Request]
20
- # @return [Twitter::Cursor]
21
- def from_response(response, key, klass, request)
22
- new(response[:body], key, klass, request)
23
- end
24
- end
25
-
26
13
  # Initializes a new Cursor
27
14
  #
28
15
  # @param attrs [Hash]
@@ -56,8 +43,8 @@ module Twitter
56
43
 
57
44
  # @return [Hash]
58
45
  def fetch_next_page
59
- response = @client.send(@request_method, @path, @options.merge(:cursor => next_cursor))
60
- self.attrs = response[:body]
46
+ response = @client.send(@request_method, @path, @options.merge(:cursor => next_cursor)).body
47
+ self.attrs = response
61
48
  end
62
49
 
63
50
  # @param attrs [Hash]
@@ -1,15 +1,12 @@
1
- require 'descendants_tracker'
2
1
  require 'twitter/rate_limit'
3
2
 
4
3
  module Twitter
5
4
  # Custom error class for rescuing from all Twitter errors
6
5
  class Error < StandardError
7
- extend DescendantsTracker
8
- attr_reader :cause, :code, :rate_limit
9
- alias_method :wrapped_exception, :cause
6
+ attr_reader :code, :rate_limit
10
7
 
11
8
  # If error code is missing see https://dev.twitter.com/docs/error-codes-responses
12
- module Codes
9
+ module Code
13
10
  AUTHENTICATION_PROBLEM = 32
14
11
  RESOURCE_NOT_FOUND = 34
15
12
  SUSPENDED_ACCOUNT = 64
@@ -20,6 +17,7 @@ module Twitter
20
17
  OVER_CAPACITY = 130
21
18
  INTERNAL_ERROR = 131
22
19
  OAUTH_TIMESTAMP_OUT_OF_RANGE = 135
20
+ ALREADY_FAVORITED = 139
23
21
  FOLLOW_ALREADY_REQUESTED = 160
24
22
  FOLLOW_LIMIT_EXCEEDED = 161
25
23
  PROTECTED_STATUS = 179
@@ -29,23 +27,42 @@ module Twitter
29
27
  LOGIN_VERIFICATION_NEEDED = 231
30
28
  ENDPOINT_RETIRED = 251
31
29
  end
30
+ Codes = Code # rubocop:disable ConstantName
32
31
 
33
32
  class << self
34
33
  # Create a new error from an HTTP response
35
34
  #
36
- # @param response [Hash]
35
+ # @param response [Faraday::Response]
37
36
  # @return [Twitter::Error]
38
- def from_response(response = {})
39
- error, code = parse_error(response[:body])
40
- new(error, response[:response_headers], code)
37
+ def from_response(response)
38
+ message, code = parse_error(response.body)
39
+ new(message, response.response_headers, code)
41
40
  end
42
41
 
43
42
  # @return [Hash]
44
43
  def errors
45
- @errors ||= descendants.inject({}) do |hash, klass|
46
- hash[klass::HTTP_STATUS_CODE] = klass
47
- hash
48
- end
44
+ @errors ||= {
45
+ 400 => Twitter::Error::BadRequest,
46
+ 401 => Twitter::Error::Unauthorized,
47
+ 403 => Twitter::Error::Forbidden,
48
+ 404 => Twitter::Error::NotFound,
49
+ 406 => Twitter::Error::NotAcceptable,
50
+ 408 => Twitter::Error::RequestTimeout,
51
+ 422 => Twitter::Error::UnprocessableEntity,
52
+ 429 => Twitter::Error::TooManyRequests,
53
+ 500 => Twitter::Error::InternalServerError,
54
+ 502 => Twitter::Error::BadGateway,
55
+ 503 => Twitter::Error::ServiceUnavailable,
56
+ 504 => Twitter::Error::GatewayTimeout,
57
+ }
58
+ end
59
+
60
+ def forbidden_messages
61
+ @forbidden_messages ||= {
62
+ 'Status is a duplicate.' => Twitter::Error::DuplicateStatus,
63
+ 'You have already favorited this status.' => Twitter::Error::AlreadyFavorited,
64
+ 'sharing is not permissible for this status (Share validations failed)' => Twitter::Error::AlreadyRetweeted,
65
+ }
49
66
  end
50
67
 
51
68
  private
@@ -73,14 +90,69 @@ module Twitter
73
90
  # Initializes a new Error object
74
91
  #
75
92
  # @param exception [Exception, String]
76
- # @param response_headers [Hash]
93
+ # @param rate_limit [Hash]
77
94
  # @param code [Integer]
78
95
  # @return [Twitter::Error]
79
- def initialize(exception = $ERROR_INFO, response_headers = {}, code = nil)
80
- @rate_limit = RateLimit.new(response_headers)
81
- @cause = exception
96
+ def initialize(message = '', rate_limit = {}, code = nil)
97
+ super(message)
98
+ @rate_limit = Twitter::RateLimit.new(rate_limit)
82
99
  @code = code
83
- exception.respond_to?(:message) ? super(exception.message) : super(exception.to_s)
84
100
  end
101
+
102
+ class ConfigurationError < ::ArgumentError; end
103
+
104
+ # Raised when Twitter returns a 4xx HTTP status code
105
+ class ClientError < self; end
106
+
107
+ # Raised when Twitter returns the HTTP status code 400
108
+ class BadRequest < ClientError; end
109
+
110
+ # Raised when Twitter returns the HTTP status code 401
111
+ class Unauthorized < ClientError; end
112
+
113
+ # Raised when Twitter returns the HTTP status code 403
114
+ class Forbidden < ClientError; end
115
+
116
+ # Raised when a Tweet has already been favorited
117
+ class AlreadyFavorited < Forbidden; end
118
+
119
+ # Raised when a Tweet has already been retweeted
120
+ class AlreadyRetweeted < Forbidden; end
121
+
122
+ # Raised when a Tweet has already been posted
123
+ class DuplicateStatus < Forbidden; end
124
+ AlreadyPosted = DuplicateStatus # rubocop:disable ConstantName
125
+
126
+ # Raised when Twitter returns the HTTP status code 404
127
+ class NotFound < ClientError; end
128
+
129
+ # Raised when Twitter returns the HTTP status code 406
130
+ class NotAcceptable < ClientError; end
131
+
132
+ # Raised when Twitter returns the HTTP status code 408
133
+ class RequestTimeout < ClientError; end
134
+
135
+ # Raised when Twitter returns the HTTP status code 422
136
+ class UnprocessableEntity < ClientError; end
137
+
138
+ # Raised when Twitter returns the HTTP status code 429
139
+ class TooManyRequests < ClientError; end
140
+ EnhanceYourCalm = TooManyRequests # rubocop:disable ConstantName
141
+ RateLimited = TooManyRequests # rubocop:disable ConstantName
142
+
143
+ # Raised when Twitter returns a 5xx HTTP status code
144
+ class ServerError < self; end
145
+
146
+ # Raised when Twitter returns the HTTP status code 500
147
+ class InternalServerError < ServerError; end
148
+
149
+ # Raised when Twitter returns the HTTP status code 502
150
+ class BadGateway < ServerError; end
151
+
152
+ # Raised when Twitter returns the HTTP status code 503
153
+ class ServiceUnavailable < ServerError; end
154
+
155
+ # Raised when Twitter returns the HTTP status code 504
156
+ class GatewayTimeout < ServerError; end
85
157
  end
86
158
  end
@@ -10,16 +10,6 @@ module Twitter
10
10
  deprecate_alias :to_hash, :to_h
11
11
  deprecate_alias :to_hsh, :to_h
12
12
 
13
- class << self
14
- # Construct a new GeoResults object from a response hash
15
- #
16
- # @param response [Hash]
17
- # @return [Twitter::Base]
18
- def from_response(response = {})
19
- new(response[:body])
20
- end
21
- end
22
-
23
13
  # Initializes a new GeoResults object
24
14
  #
25
15
  # @param attrs [Hash]
@@ -19,27 +19,27 @@ module Twitter
19
19
 
20
20
  # @return [Hash]
21
21
  def perform
22
- @client.send(@request_method, @path, @options)
22
+ @client.send(@request_method, @path, @options).body
23
23
  end
24
24
 
25
25
  # @param klass [Class]
26
26
  # @param request [Twitter::Request]
27
27
  # @return [Object]
28
28
  def perform_with_object(klass)
29
- klass.from_response(perform)
29
+ klass.new(perform)
30
30
  end
31
31
 
32
32
  # @param collection_name [Symbol]
33
33
  # @param klass [Class]
34
34
  # @return [Twitter::Cursor]
35
35
  def perform_with_cursor(collection_name, klass = nil)
36
- Twitter::Cursor.from_response(perform, collection_name.to_sym, klass, self)
36
+ Twitter::Cursor.new(perform, collection_name.to_sym, klass, self)
37
37
  end
38
38
 
39
39
  # @param klass [Class]
40
40
  # @return [Array]
41
41
  def perform_with_objects(klass)
42
- perform[:body].collect do |element|
42
+ perform.collect do |element|
43
43
  klass.new(element)
44
44
  end
45
45
  end
@@ -0,0 +1,43 @@
1
+ require 'twitter/rest/direct_messages'
2
+ require 'twitter/rest/favorites'
3
+ require 'twitter/rest/friends_and_followers'
4
+ require 'twitter/rest/help'
5
+ require 'twitter/rest/lists'
6
+ require 'twitter/rest/oauth'
7
+ require 'twitter/rest/places_and_geo'
8
+ require 'twitter/rest/saved_searches'
9
+ require 'twitter/rest/search'
10
+ require 'twitter/rest/spam_reporting'
11
+ require 'twitter/rest/suggested_users'
12
+ require 'twitter/rest/timelines'
13
+ require 'twitter/rest/trends'
14
+ require 'twitter/rest/tweets'
15
+ require 'twitter/rest/undocumented'
16
+ require 'twitter/rest/users'
17
+
18
+ module Twitter
19
+ module REST
20
+ module API
21
+ [
22
+ Twitter::REST::DirectMessages,
23
+ Twitter::REST::Favorites,
24
+ Twitter::REST::FriendsAndFollowers,
25
+ Twitter::REST::Help,
26
+ Twitter::REST::Lists,
27
+ Twitter::REST::OAuth,
28
+ Twitter::REST::PlacesAndGeo,
29
+ Twitter::REST::SavedSearches,
30
+ Twitter::REST::Search,
31
+ Twitter::REST::SpamReporting,
32
+ Twitter::REST::SuggestedUsers,
33
+ Twitter::REST::Timelines,
34
+ Twitter::REST::Trends,
35
+ Twitter::REST::Tweets,
36
+ Twitter::REST::Undocumented,
37
+ Twitter::REST::Users,
38
+ ].each do |klass|
39
+ include klass
40
+ end
41
+ end
42
+ end
43
+ end
@@ -5,24 +5,7 @@ require 'json'
5
5
  require 'timeout'
6
6
  require 'twitter/client'
7
7
  require 'twitter/error'
8
- require 'twitter/error/configuration_error'
9
- require 'twitter/error/request_timeout'
10
- require 'twitter/rest/api/direct_messages'
11
- require 'twitter/rest/api/favorites'
12
- require 'twitter/rest/api/friends_and_followers'
13
- require 'twitter/rest/api/help'
14
- require 'twitter/rest/api/lists'
15
- require 'twitter/rest/api/oauth'
16
- require 'twitter/rest/api/places_and_geo'
17
- require 'twitter/rest/api/saved_searches'
18
- require 'twitter/rest/api/search'
19
- require 'twitter/rest/api/spam_reporting'
20
- require 'twitter/rest/api/suggested_users'
21
- require 'twitter/rest/api/timelines'
22
- require 'twitter/rest/api/trends'
23
- require 'twitter/rest/api/tweets'
24
- require 'twitter/rest/api/undocumented'
25
- require 'twitter/rest/api/users'
8
+ require 'twitter/rest/api'
26
9
  require 'twitter/rest/request/multipart_with_file'
27
10
  require 'twitter/rest/response/parse_json'
28
11
  require 'twitter/rest/response/raise_error'
@@ -34,22 +17,7 @@ module Twitter
34
17
  # @note All methods have been separated into modules and follow the same grouping used in {http://dev.twitter.com/doc the Twitter API Documentation}.
35
18
  # @see http://dev.twitter.com/pages/every_developer
36
19
  class Client < Twitter::Client
37
- include Twitter::REST::API::DirectMessages
38
- include Twitter::REST::API::Favorites
39
- include Twitter::REST::API::FriendsAndFollowers
40
- include Twitter::REST::API::Help
41
- include Twitter::REST::API::Lists
42
- include Twitter::REST::API::OAuth
43
- include Twitter::REST::API::PlacesAndGeo
44
- include Twitter::REST::API::SavedSearches
45
- include Twitter::REST::API::Search
46
- include Twitter::REST::API::SpamReporting
47
- include Twitter::REST::API::SuggestedUsers
48
- include Twitter::REST::API::Timelines
49
- include Twitter::REST::API::Trends
50
- include Twitter::REST::API::Tweets
51
- include Twitter::REST::API::Undocumented
52
- include Twitter::REST::API::Users
20
+ include Twitter::REST::API
53
21
  attr_accessor :bearer_token
54
22
  attr_writer :connection_options, :middleware
55
23
  ENDPOINT = 'https://api.twitter.com'
@@ -91,13 +59,14 @@ module Twitter
91
59
 
92
60
  # Perform an HTTP GET request
93
61
  def get(path, params = {})
94
- request(:get, path, params)
62
+ headers = request_headers(:get, path, params)
63
+ request(:get, path, params, headers)
95
64
  end
96
65
 
97
66
  # Perform an HTTP POST request
98
67
  def post(path, params = {})
99
- signature_params = params.values.any? { |value| value.respond_to?(:to_io) } ? {} : params
100
- request(:post, path, params, signature_params)
68
+ headers = params.values.any? { |value| value.respond_to?(:to_io) } ? request_headers(:post, path, params, {}) : request_headers(:post, path, params)
69
+ request(:post, path, params, headers)
101
70
  end
102
71
 
103
72
  # @return [Boolean]
@@ -119,11 +88,8 @@ module Twitter
119
88
  @connection ||= Faraday.new(ENDPOINT, connection_options)
120
89
  end
121
90
 
122
- def request(method, path, params = {}, signature_params = params)
123
- response = connection.send(method.to_sym, path, params) do |request|
124
- request.headers.update(request_headers(method, path, params, signature_params))
125
- end
126
- response.env
91
+ def request(method, path, params = {}, headers = {})
92
+ connection.send(method.to_sym, path, params) { |request| request.headers.update(headers) }.env
127
93
  rescue Faraday::Error::TimeoutError, Timeout::Error => error
128
94
  raise(Twitter::Error::RequestTimeout.new(error))
129
95
  rescue Faraday::Error::ClientError, JSON::ParserError => error
@@ -138,12 +104,12 @@ module Twitter
138
104
  headers[:authorization] = bearer_token_credentials_auth_header
139
105
  headers[:content_type] = 'application/x-www-form-urlencoded; charset=UTF-8'
140
106
  else
141
- headers[:authorization] = auth_token(method, path, params, signature_params)
107
+ headers[:authorization] = auth_header(method, path, params, signature_params)
142
108
  end
143
109
  headers
144
110
  end
145
111
 
146
- def auth_token(method, path, params = {}, signature_params = params)
112
+ def auth_header(method, path, params = {}, signature_params = params)
147
113
  if !user_token?
148
114
  @bearer_token = token unless bearer_token?
149
115
  bearer_auth_header