Class: Alegra::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body, formatter_class_name = 'UnderscoreFormatter') ⇒ Response

Returns a new instance of Response.



6
7
8
9
# File 'lib/alegra/response.rb', line 6

def initialize(body, formatter_class_name='UnderscoreFormatter')
  @body = JSON.parse(body)
  @formatter = Object.const_get("Alegra::Formatters::#{ formatter_class_name }").new
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



4
5
6
# File 'lib/alegra/response.rb', line 4

def body
  @body
end

#formatterObject (readonly)

Returns the value of attribute formatter.



4
5
6
# File 'lib/alegra/response.rb', line 4

def formatter
  @formatter
end

Instance Method Details

#call(options = {}) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/alegra/response.rb', line 11

def call(options={})
  if options[:none]
    JSON.parse(body)
  else
    formatter.call(content: body)
  end
end