From fb63970c1bd19792955d092a38b6adf53b558ec7 Mon Sep 17 00:00:00 2001 From: Erik Michaels-Ober Date: Tue, 11 Jun 2013 14:57:04 -0700 Subject: [PATCH] Restore compatibility with Ruby 1.8.7 The Base64 module does not have a strict_encode64 method in Ruby 1.8. --- lib/twitter/client.rb | 7 +++++-- spec/twitter/client_spec.rb | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/twitter/client.rb b/lib/twitter/client.rb index bf37e333c..9affd93ca 100644 --- a/lib/twitter/client.rb +++ b/lib/twitter/client.rb @@ -20,7 +20,6 @@ require 'twitter/error/client_error' require 'twitter/error/decode_error' require 'simple_oauth' -require 'base64' require 'uri' module Twitter @@ -124,10 +123,14 @@ def connection # # @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 diff --git a/spec/twitter/client_spec.rb b/spec/twitter/client_spec.rb index 01949c713..11bc26c34 100644 --- a/spec/twitter/client_spec.rb +++ b/spec/twitter/client_spec.rb @@ -191,7 +191,7 @@ it "creates the correct auth header with supplied consumer_key and consumer_secret" do uri = "/1.1/direct_messages.json" authorization = subject.send(:bearer_token_credentials_auth_header) - expect(authorization).to eq "Basic #{Base64.strict_encode64("CK:CS")}" + expect(authorization).to eq "Basic Q0s6Q1M=" end end end