class RingCentralSdk::REST::Request::Multipart

Multipart is a base request helper class for multipart/mixed messages

Constants

CONTENT_ID_HEADER
DEFAULT_BASE64_ENCODE
DEFAULT_CONTENT_ID_DISABLE
DEFAULT_ID
DEFAULT_METHOD

Attributes

account_id[R]
extension_id[R]
method[RW]
mime[R]
mime_part_params[RW]

Public Class Methods

new(opts = {}) click to toggle source
# File lib/ringcentral_sdk/rest/request/multipart.rb, line 25
def initialize(opts = {})
  @mime = MIME::Multipart::Mixed.new
  @mime.headers.delete CONTENT_ID_HEADER

  @method = opts[:method] ||= DEFAULT_METHOD
  set_url(opts[:url]) if opts.key? :url

  @mime_part_params = {
    base64_encode: opts[:base64_encode] ||= DEFAULT_BASE64_ENCODE,
    content_id_disable: opts[:content_id_disable] ||= DEFAULT_CONTENT_ID_DISABLE
  }

  path_params(opts)
end

Public Instance Methods

add_file(file_path_or_part, opts = {}) click to toggle source
# File lib/ringcentral_sdk/rest/request/multipart.rb, line 71
def add_file(file_path_or_part, opts = {})
  if file_path_or_part.is_a? MIME::Media
    @mime.add file_path_or_part
  else
    @mime.add MIMEBuilder::Filepath.new(
      file_path_or_part,
      @mime_part_params.merge(opts).merge({is_attachment: true})
    ).mime
  end
  self
end
add_files(files = [], opts = {}) click to toggle source
# File lib/ringcentral_sdk/rest/request/multipart.rb, line 83
def add_files(files = [], opts = {})
  files.each do |f|
    add_file f, opts
  end
  self
end
add_json(data, opts = {}) click to toggle source
# File lib/ringcentral_sdk/rest/request/multipart.rb, line 45
def add_json(data, opts = {})
  if data.is_a? MIME::Media
    @mime.add data
  else
    @mime.add MIMEBuilder::JSON.new(
      data,
      @mime_part_params.merge(opts)
    ).mime
  end
  self
end
add_metadata(data, opts = {}) click to toggle source
# File lib/ringcentral_sdk/rest/request/multipart.rb, line 57
def add_metadata(data, opts = {})
  add_json(data, opts)
  self
end
add_part(part) click to toggle source
# File lib/ringcentral_sdk/rest/request/multipart.rb, line 90
def add_part(part)
  @mime.add part
  self
end
add_text(text = nil, opts = {}) click to toggle source
# File lib/ringcentral_sdk/rest/request/multipart.rb, line 62
def add_text(text = nil, opts = {})
  return if text.nil? || text.to_s.empty?
  @mime.add MIMEBuilder::Text.new(
    text,
    @mime_part_params.merge(opts)
  ).mime
  self
end
body() click to toggle source
# File lib/ringcentral_sdk/rest/request/multipart.rb, line 108
def body
  @mime.body.to_s
end
content_type() click to toggle source
# File lib/ringcentral_sdk/rest/request/multipart.rb, line 104
def content_type
  @mime.headers.get('Content-Type').to_s
end
path_params(opts = {}) click to toggle source
# File lib/ringcentral_sdk/rest/request/multipart.rb, line 40
def path_params(opts = {})
  @account_id = opts[:account_id] ||= opts[:accountId] ||= DEFAULT_ID
  @extension_id = opts[:extension_id] ||= opts[:extensionId] ||= DEFAULT_ID
end
set_url(url) click to toggle source
# File lib/ringcentral_sdk/rest/request/multipart.rb, line 99
def set_url(url)
  @_url = url
  self
end
url() click to toggle source
# File lib/ringcentral_sdk/rest/request/multipart.rb, line 95
def url
  @_url
end