lib/ringcentral_sdk/helpers/fax.rb in ringcentral_sdk-0.0.3 vs lib/ringcentral_sdk/helpers/fax.rb in ringcentral_sdk-0.0.4

- old
+ new

@@ -1,12 +1,12 @@ require 'base64' require 'mime' -require 'mime-types' +require 'mime/types' require 'multi_json' module RingCentralSdk::Helpers - class CreateFaxRequest + class CreateFaxRequest < RingCentralSdk::Helpers::Request attr_reader :msg def initialize(path_params=nil,metadata=nil,options=nil) @msg = MIME::Multipart::Mixed.new @@ -58,53 +58,74 @@ end content_type = (content_type.is_a?(String) && content_type =~ /^[^\/\s]+\/[^\/\s]+/) \ ? content_type : MIME::Types.type_for(file_name).first.content_type + base_name = File.basename(file_name) file_base64 = Base64.encode64(File.binread(file_name)) base64_part = MIME::Text.new(file_base64) base64_part.headers.delete('Content-Id') - base64_part.headers.set('Content-Type',content_type) + base64_part.headers.set('Content-Type', content_type) base64_part.headers.set('Content-Transfer-Encoding','base64') + if base_name.is_a?(String) && base_name.length>0 + base64_part.headers.set('Content-Disposition', "attachment; filename=\"#{base_name}\"") + else + base64_part.headers.set('Content-Disposition', 'attachment') + end @msg.add(base64_part) return true end def add_file_octet_stream(file_name=nil) unless file_name.is_a?(String) && File.file?(file_name) return false end + content_type = (content_type.is_a?(String) && content_type =~ /^[^\/\s]+\/[^\/\s]+/) \ + ? content_type : MIME::Types.type_for(file_name).first.content_type + base_name = File.basename(file_name) file_bytes = File.binread(file_name) file_part = MIME::Application.new(file_bytes) file_part.headers.delete('Content-Id') - file_part.headers.set('Content-Type','application/octet-stream') + file_part.headers.set('Content-Type', content_type) if base_name.is_a?(String) && base_name.length>0 file_part.headers.set('Content-Disposition', "attachment; filename=\"#{base_name}\"") else file_part.headers.set('Content-Disposition', 'attachment') end @msg.add(file_part) return true end + def method() + return 'post' + end + def url() account_id = "~" extension_id = "~" if @path_params.is_a?(Hash) - if @path_params.has?(:account_id) && @path_params[:account_id].length>0 - account_id = @path_params[:account_id] + if @path_params.has_key?(:account_id) + if @path_params[:account_id].is_a?(String) && @path_params[:account_id].length>0 + account_id = @path_params[:account_id] + elsif @path_params[:account_id].is_a?(Integer) && @path_params[:account_id]>0 + account_id = @path_params[:account_id].to_s + end end - if @path_params.has?(:extension_id) && @path_params[:extension_id].length>0 - account_id = @path_params[:extension_id] + if @path_params.has_key?(:extension_id) + if @path_params[:extension_id].is_a?(String) && @path_params[:extension_id].length>0 + extension_id = @path_params[:extension_id] + elsif @path_params[:extension_id].is_a?(Integer) && @path_params[:extension_id]>0 + extension_id = @path_params[:extension_id].to_s + end end end - url = "account/#{account_id}/extension/#{extension_id}/fax" + url = "account/#{account_id.to_s}/extension/#{extension_id.to_s}/fax" return url end def content_type() return @msg.headers.get('Content-Type').to_s \ No newline at end of file