Class: Praxis::MultipartPart

Inherits:
Object
  • Object
show all
Defined in:
lib/praxis/multipart/part.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body, headers = {}, filename: nil) ⇒ MultipartPart

Returns a new instance of MultipartPart.



8
9
10
11
12
# File 'lib/praxis/multipart/part.rb', line 8

def initialize(body, headers={}, filename: nil)
  @body = body
  @headers = headers
  @filename = filename
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



4
5
6
# File 'lib/praxis/multipart/part.rb', line 4

def body
  @body
end

#filenameObject

Returns the value of attribute filename.



6
7
8
# File 'lib/praxis/multipart/part.rb', line 6

def filename
  @filename
end

#headersObject

Returns the value of attribute headers.



5
6
7
# File 'lib/praxis/multipart/part.rb', line 5

def headers
  @headers
end

Instance Method Details

#content_typeMediaTypeIdentifier

Determine the content type of this response.

Returns:



17
18
19
# File 'lib/praxis/multipart/part.rb', line 17

def content_type
  MediaTypeIdentifier.load(headers['Content-Type']).freeze
end

#content_type=(identifier) ⇒ String

TODO:

DRY this out (also used in Response)

Set the content type for this response.

Parameters:

Returns:

  • (String)


26
27
28
# File 'lib/praxis/multipart/part.rb', line 26

def content_type=(identifier)
  headers['Content-Type'] = MediaTypeIdentifier.load(identifier).to_s
end

#encode!Object



34
35
36
37
38
39
# File 'lib/praxis/multipart/part.rb', line 34

def encode!
  case @body
  when Hash, Array
    @body = JSON.pretty_generate(@body)
  end
end

#statusObject



30
31
32
# File 'lib/praxis/multipart/part.rb', line 30

def status
  @headers['Status'].to_i
end