Class: RingCentralSdk::Helpers::CreateFaxRequest
- Inherits:
-
Object
- Object
- RingCentralSdk::Helpers::CreateFaxRequest
- Defined in:
- lib/ringcentral_sdk/helpers/fax.rb
Instance Attribute Summary collapse
-
#msg ⇒ Object
readonly
Returns the value of attribute msg.
Instance Method Summary collapse
- #add_file_base64(file_name = nil, content_type = nil) ⇒ Object
- #add_file_octet_stream(file_name = nil) ⇒ Object
- #add_file_text(text = nil, charset = 'UTF-8') ⇒ Object
- #add_metadata(json = nil) ⇒ Object
- #body ⇒ Object
- #content_type ⇒ Object
-
#initialize(path_params = nil, metadata = nil, options = nil) ⇒ CreateFaxRequest
constructor
A new instance of CreateFaxRequest.
- #url ⇒ Object
Constructor Details
#initialize(path_params = nil, metadata = nil, options = nil) ⇒ CreateFaxRequest
Returns a new instance of CreateFaxRequest.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ringcentral_sdk/helpers/fax.rb', line 10 def initialize(path_params=nil,=nil,=nil) @msg = MIME::Multipart::Mixed.new @msg.headers.delete('Content-Id') @path_params = path_params if .is_a?(Hash) || .is_a?(String) () end if .is_a?(Hash) if .has_key?(:file_name) if .has_key?(:base64_encode) && [:base64_encode] add_file_base64([:file_name],[:file_content_type]) else add_file_octet_stream([:file_name]) end elsif .has_key?(:text) add_file_text([:text]) end end end |
Instance Attribute Details
#msg ⇒ Object (readonly)
Returns the value of attribute msg.
8 9 10 |
# File 'lib/ringcentral_sdk/helpers/fax.rb', line 8 def msg @msg end |
Instance Method Details
#add_file_base64(file_name = nil, content_type = nil) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/ringcentral_sdk/helpers/fax.rb', line 55 def add_file_base64(file_name=nil,content_type=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 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-Transfer-Encoding','base64') @msg.add(base64_part) return true end |
#add_file_octet_stream(file_name = nil) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/ringcentral_sdk/helpers/fax.rb', line 74 def add_file_octet_stream(file_name=nil) unless file_name.is_a?(String) && File.file?(file_name) return false end 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') 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 |
#add_file_text(text = nil, charset = 'UTF-8') ⇒ Object
48 49 50 51 52 53 |
# File 'lib/ringcentral_sdk/helpers/fax.rb', line 48 def add_file_text(text=nil,charset='UTF-8') return unless text.is_a?(String) text_part = MIME::Text.new(text,'plain') text_part.headers.delete('Content-Id') @msg.add(text_part) end |
#add_metadata(json = nil) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ringcentral_sdk/helpers/fax.rb', line 34 def (json=nil) if json.is_a?(Hash) json = MultiJson.encode(json) end if json.is_a?(String) json_part = MIME::Text.new(json) json_part.headers.delete('Content-Id') json_part.headers.set('Content-Type','application/json') @msg.add(json_part) return true end return false end |
#body ⇒ Object
114 115 116 |
# File 'lib/ringcentral_sdk/helpers/fax.rb', line 114 def body() return @msg.body.to_s end |
#content_type ⇒ Object
110 111 112 |
# File 'lib/ringcentral_sdk/helpers/fax.rb', line 110 def content_type() return @msg.headers.get('Content-Type').to_s end |
#url ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/ringcentral_sdk/helpers/fax.rb', line 95 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] end if @path_params.has?(:extension_id) && @path_params[:extension_id].length>0 account_id = @path_params[:extension_id] end end url = "account/#{account_id}/extension/#{extension_id}/fax" return url end |