Class: SocketLabs::InjectionApi::Core::Serialization::AttachmentJson

Inherits:
Object
  • Object
show all
Defined in:
lib/socketlabs/injectionapi/core/serialization/attachment_json.rb

Overview

Represents a message attachment in the form of a byte array. To be serialized into JSON string before sending to the Injection Api.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAttachmentJson

Initializes a new instance of the AttachmentJson class



25
26
27
28
29
30
31
# File 'lib/socketlabs/injectionapi/core/serialization/attachment_json.rb', line 25

def initialize
  @name = nil
  @mime_type = nil
  @content_id = nil
  @content = nil
  @custom_headers = Array.new
end

Instance Attribute Details

#contentObject

Content of an Attachment. The BASE64 encoded str.



20
21
22
# File 'lib/socketlabs/injectionapi/core/serialization/attachment_json.rb', line 20

def content
  @content
end

#content_idObject

ContentId for an Attachment.



18
19
20
# File 'lib/socketlabs/injectionapi/core/serialization/attachment_json.rb', line 18

def content_id
  @content_id
end

#custom_headersObject

the list of custom headers added to the attachment.



22
23
24
# File 'lib/socketlabs/injectionapi/core/serialization/attachment_json.rb', line 22

def custom_headers
  @custom_headers
end

#mime_typeObject

the MIME type of the attachment.



16
17
18
# File 'lib/socketlabs/injectionapi/core/serialization/attachment_json.rb', line 16

def mime_type
  @mime_type
end

#nameObject

the name of attachment



14
15
16
# File 'lib/socketlabs/injectionapi/core/serialization/attachment_json.rb', line 14

def name
  @name
end

Instance Method Details

#to_hashhash

build json hash for AttachmentJson



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/socketlabs/injectionapi/core/serialization/attachment_json.rb', line 35

def to_hash
  json =
  {
    :name=> @name,
    :content=> @content,
    :contentType=> @mime_type
  }
  unless @content_id.nil? || @content_id.empty?
    json[:contentId] = @content_id
  end
  unless @custom_headers.nil? || @custom_headers.length == 0
    e = Array.new
    @custom_headers.each do |value|
      e.push(value.to_hash)
    end
    json[:customHeaders] = e
  end
  json
end