Skip to content

Commit

Permalink
Restore compatibility with Ruby 1.8.7
Browse files Browse the repository at this point in the history
The Base64 module does not have a strict_encode64 method in Ruby 1.8.
  • Loading branch information
sferik committed Jun 11, 2013
1 parent 0b55611 commit fb63970
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions lib/twitter/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
require 'twitter/error/client_error'
require 'twitter/error/decode_error'
require 'simple_oauth'
require 'base64'
require 'uri'

module Twitter
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/twitter/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit fb63970

Please sign in to comment.