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.



139
140
141
142
143
144
# File 'lib/blockspring.rb', line 139

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

Instance Method Details

#addErrorOutput(title, message = nil) ⇒ Object



165
166
167
168
169
170
171
172
173
# File 'lib/blockspring.rb', line 165

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

  return self
end

#addFileOutput(name, filepath) ⇒ Object



151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/blockspring.rb', line 151

def addFileOutput(name, filepath)
  filename = File.basename(filepath)
  b64_file_contents = Base64.strict_encode64(File.read(filepath))
  mime_type_object = MIME::Types.of(filename).first
  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



146
147
148
149
# File 'lib/blockspring.rb', line 146

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

#endObject



175
176
177
# File 'lib/blockspring.rb', line 175

def end
  puts @result.to_json
end