lib/twitter/client.rb in twitter-4.7.0 vs lib/twitter/client.rb in twitter-4.8.0

- old
+ new

@@ -18,11 +18,10 @@ require 'twitter/api/users' require 'twitter/configurable' require 'twitter/error/client_error' require 'twitter/error/decode_error' require 'simple_oauth' -require 'base64' require 'uri' module Twitter # Wrapper for the Twitter REST API # @@ -84,11 +83,11 @@ # # @param method [Symbol] # @param path [String] # @param params [Hash] # @return [Proc] - def request_setup(method, path, params) + def request_setup(method, path, params, signature_params) Proc.new do |request| if params.delete(:bearer_token_request) request.headers[:authorization] = bearer_token_credentials_auth_header request.headers[:content_type] = 'application/x-www-form-urlencoded; charset=UTF-8' request.headers[:accept] = '*/*' # It is important we set this, otherwise we get an error. @@ -97,17 +96,17 @@ @bearer_token = token[:access_token] Twitter.client.bearer_token = @bearer_token if Twitter.client? end request.headers[:authorization] = bearer_auth_header else - request.headers[:authorization] = oauth_auth_header(method, path, params).to_s + request.headers[:authorization] = oauth_auth_header(method, path, signature_params).to_s end end end def request(method, path, params={}, signature_params=params) - request_setup = request_setup(method, path, params) + request_setup = request_setup(method, path, params, signature_params) connection.send(method.to_sym, path, params, &request_setup).env rescue Faraday::Error::ClientError raise Twitter::Error::ClientError rescue MultiJson::DecodeError raise Twitter::Error::DecodeError @@ -122,11 +121,15 @@ # Generates authentication header for a bearer token request # # @return [String] def bearer_token_credentials_auth_header - basic_auth_token = Base64.strict_encode64("#{@consumer_key}:#{@consumer_secret}") + basic_auth_token = encode_value("#{@consumer_key}:#{@consumer_secret}") "Basic #{basic_auth_token}" + end + + def encode_value(value) + [value].pack("m0").gsub("\n", '') end def bearer_auth_header "Bearer #{@bearer_token}" end