Class: RingCentralSdk::REST::Request::Fax

Inherits:
Base
  • Object
show all
Defined in:
lib/ringcentral_sdk/rest/request/fax.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#headers, #params

Constructor Details

#initialize(opts = {}) ⇒ Fax



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/ringcentral_sdk/rest/request/fax.rb', line 14

def initialize(opts={})
   = true

  @msg = MIME::Multipart::Mixed.new
  @msg.headers.delete('Content-Id')

  add_path(opts)
  add_part_meta(opts)
  add_part_text(opts[:text])
  add_parts(opts[:files])
  add_parts(opts[:parts])
end

Instance Attribute Details

#account_idObject (readonly)

Returns the value of attribute account_id.



11
12
13
# File 'lib/ringcentral_sdk/rest/request/fax.rb', line 11

def 
  @account_id
end

#extension_idObject (readonly)

Returns the value of attribute extension_id.



12
13
14
# File 'lib/ringcentral_sdk/rest/request/fax.rb', line 12

def extension_id
  @extension_id
end

#msgObject (readonly)

Returns the value of attribute msg.



9
10
11
# File 'lib/ringcentral_sdk/rest/request/fax.rb', line 9

def msg
  @msg
end

Instance Method Details

#add_part_meta(opts = {}) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ringcentral_sdk/rest/request/fax.rb', line 32

def add_part_meta(opts={})
  meta =  opts
  json = MultiJson.encode meta
  json = Base64.encode64(json) if 
  json_part = MIME::Text.new(json)
  json_part.headers.delete('Content-Id')
  json_part.headers.set('Content-Type', 'application/json')
  json_part.headers.set('Content-Transfer-Encoding', 'base64') if 
  @msg.add(json_part)
  true
end

#add_part_text(text = nil, opts = {}) ⇒ Object



67
68
69
70
71
72
# File 'lib/ringcentral_sdk/rest/request/fax.rb', line 67

def add_part_text(text=nil, opts={})
  return unless !text.nil? && text.to_s.length>0
  opts[:content_id_disable] = true
  text_part = MIMEBuilder::Text.new(text, opts)
  @msg.add(text_part.mime)
end

#add_parts(parts = []) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/ringcentral_sdk/rest/request/fax.rb', line 74

def add_parts(parts=[])
  return if parts.nil?
  unless parts.is_a?(Array)
    raise 'invalid parameter[0]. needs to be an array'
  end
  parts.each do |part|
    if part.is_a?(String)
      file_part = MIMEBuilder::Filepath.new(part)
      @msg.add(file_part.mime)
    elsif part.is_a? Hash
      part[:content_id_disable] = true
      part[:is_attachment] = true
      if part.key? :filename
        file_part = MIMEBuilder::Filepath.new(part[:filename], part)
        @msg.add(file_part.mime)
      elsif part.key? :text
        text_part = MIMEBuilder::Text.new(part[:text], part)
        @msg.add(text_part.mime)
      end
    end
  end
end

#add_path(opts = {}) ⇒ Object



27
28
29
30
# File 'lib/ringcentral_sdk/rest/request/fax.rb', line 27

def add_path(opts={})
  @account_id = opts[:accountId] ||= '~'
  @extension_id = opts[:extensionId] ||= '~'
end

#bodyObject



109
110
111
# File 'lib/ringcentral_sdk/rest/request/fax.rb', line 109

def body()
  @msg.body.to_s
end

#content_typeObject



105
106
107
# File 'lib/ringcentral_sdk/rest/request/fax.rb', line 105

def content_type()
  @msg.headers.get('Content-Type').to_s
end

#create_metadata(opts = {}) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/ringcentral_sdk/rest/request/fax.rb', line 44

def (opts={})
  meta = {}
  return meta unless opts.is_a?(Hash)

  inf = RingCentralSdk::REST::Request::Inflator::ContactInfo.new
  meta[:to] = inf.inflate_to_array opts[:to]

  processed = {
    accountId: 1,
    extensionId: 1,
    to: 1,
    text: 1,
    files: 1,
    parts: 1
  }

  opts.each do |k,v|
    meta[k] = v unless processed.key?(k)
  end

  meta
end

#methodObject



97
98
99
# File 'lib/ringcentral_sdk/rest/request/fax.rb', line 97

def method()
  'post'
end

#urlObject



101
102
103
# File 'lib/ringcentral_sdk/rest/request/fax.rb', line 101

def url()
  "account/#{@account_id.to_s}/extension/#{@extension_id.to_s}/fax"
end