Class: Blockspring::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/blockspring.rb

Instance Method Summary collapse

Constructor Details

#initializeResponse

Returns a new instance of Response.



202
203
204
205
206
207
# File 'lib/blockspring.rb', line 202

def initialize
  @result = {
    :_blockspring_spec => true,
    :_errors => []
  }
end

Instance Method Details

#addErrorOutput(title, message = nil) ⇒ Object



228
229
230
231
232
233
234
235
236
# File 'lib/blockspring.rb', line 228

def addErrorOutput(title, message = nil)
  @result[:_errors].push({
    title: title,
    message: message
    }
  )

  return self
end

#addFileOutput(name, filepath) ⇒ Object



214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/blockspring.rb', line 214

def addFileOutput(name, filepath)
  filename = File.basename(filepath)
  b64_file_contents = Base64.strict_encode64(File.read(filepath))
  mime_type_object = MIME::Types.of(filename).last
  mime_type = mime_type_object ? mime_type_object.content_type : nil

  @result[name] = {
    :filename => filename,
    :"content-type" => mime_type,
    :data => b64_file_contents
  }
  return self
end

#addOutput(name, value = nil) ⇒ Object



209
210
211
212
# File 'lib/blockspring.rb', line 209

def addOutput(name, value = nil)
  @result[name] = value
  return self
end

#endObject



238
239
240
# File 'lib/blockspring.rb', line 238

def end
  puts @result.to_json
end