lib/ringcentral_sdk/helpers/fax.rb in ringcentral_sdk-0.4.0 vs lib/ringcentral_sdk/helpers/fax.rb in ringcentral_sdk-0.5.0
- old
+ new
@@ -60,19 +60,18 @@
text_part = MIME::Text.new(text,'plain')
text_part.headers.delete('Content-Id')
@msg.add(text_part)
end
- def add_file(file_name=nil, content_type=nil, base64_encode=false)
+ def add_file(file_name, content_type=nil, base64_encode=false)
file_part = get_file_part(file_name, content_type, base64_encode)
@msg.add(file_part)
return true
end
- def get_file_part(file_name=nil, content_type=nil, base64_encode=false)
-
+ def get_file_part(file_name, content_type=nil, base64_encode=false)
file_bytes = get_file_bytes(file_name)
file_part = base64_encode \
? MIME::Text.new(Base64.encode64(file_bytes)) \
: MIME::Application.new(file_bytes)
@@ -83,20 +82,20 @@
file_part.headers.set('Content-Transfer-Encoding', 'base64') if base64_encode
return file_part
end
def get_file_bytes(file_name=nil)
-
unless File.file?(file_name.to_s)
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_bytes = RUBY_VERSION < '1.9' \ # 1.8.7 removed due to subscription
+ # ? File.open(file_name, 'rb') { |f| f.read } \
+ # : File.open(file_name, 'rb:BINARY') { |f| f.read }
- return file_bytes
+ file_bytes = File.open(file_name, 'rb:BINARY') { |f| f.read }
+ return file_bytes
end
def get_file_content_type(file_name=nil, content_type=nil)
return (content_type.is_a?(String) && content_type =~ /^[^\/\s]+\/[^\/\s]+/) \
? content_type : MIME::Types.type_for(file_name).first.content_type || 'application/octet-stream'
\ No newline at end of file