From 87eb52ac0b3160396844aded547acfdfd8d3d170 Mon Sep 17 00:00:00 2001 From: John Wang Date: Sun, 31 May 2015 21:01:16 -0700 Subject: [PATCH] try Ruby 1.8.7 --- lib/ringcentral_sdk/helpers/fax.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/ringcentral_sdk/helpers/fax.rb b/lib/ringcentral_sdk/helpers/fax.rb index ab2a41f..b34c4de 100644 --- a/lib/ringcentral_sdk/helpers/fax.rb +++ b/lib/ringcentral_sdk/helpers/fax.rb @@ -75,9 +75,14 @@ def get_file_part(file_name=nil, content_type=nil, base64_encode=false) raise "File \"#{file_name.to_s}\" does not exist or cannot be read" end + file_bytes = RUBY_VERSION < '1.9' \ + ? File.open(file_name, 'rb') { |f| f.read } \ + : File.open(file_name, 'rb:BINARY') { |f| f.read } + file_part = base64_encode \ - ? MIME::Text.new(Base64.encode64(File.binread(file_name))) \ - : MIME::Application.new(File.binread(file_name)) + ? MIME::Text.new(Base64.encode64(file_bytes)) \ + : MIME::Application.new(file_bytes) + file_part.headers.delete('Content-Id') file_part.headers.set('Content-Type', get_file_content_type(file_name, content_type)) file_part.headers.set('Content-Disposition', get_attachment_content_disposition(file_name))