Class: Strobe::Resources::Application::Multipart

Inherits:
Object
  • Object
show all
Defined in:
lib/strobe/resources/application.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) {|_self| ... } ⇒ Multipart

Returns a new instance of Multipart.

Yields:

  • (_self)

Yield Parameters:



79
80
81
82
83
84
# File 'lib/strobe/resources/application.rb', line 79

def initialize(params)
  @params = params
  @files  = []

  yield self if block_given?
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



77
78
79
# File 'lib/strobe/resources/application.rb', line 77

def params
  @params
end

Instance Method Details

#bodyObject



94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/strobe/resources/application.rb', line 94

def body
  b  = "--#{boundary}\r\n"
  b << part("metadata", "application/json", )
  b << "--#{boundary}\r\n"

  @files.each do |path, type, body|
    b << part("files[]", type, body)
    b << "--#{boundary}\r\n"
  end

  b
end

#file(path, content_type, body) ⇒ Object



86
87
88
# File 'lib/strobe/resources/application.rb', line 86

def file(path, content_type, body)
  @files << [path, content_type, body]
end

#headersObject



90
91
92
# File 'lib/strobe/resources/application.rb', line 90

def headers
  { "Content-Type" => %[multipart/form-data; boundary="#{boundary}"] }
end