Class: OldApiResource::Mocks::MockResponse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body, opts = {}, &block) ⇒ MockResponse

Returns a new instance of MockResponse.



132
133
134
135
136
137
138
139
# File 'lib/old_api_resource/mocks.rb', line 132

def initialize(body, opts = {}, &block)     
  opts = opts.reverse_merge({:headers => {}, :status_code => 200})
  @body = body
  @headers = opts[:headers]
  @code = opts[:status_code]
  @format = (opts[:format] || :json)
  @block = block if block_given?
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



131
132
133
# File 'lib/old_api_resource/mocks.rb', line 131

def block
  @block
end

#bodyObject (readonly)

Returns the value of attribute body.

Raises:

  • (Exception)


131
132
133
# File 'lib/old_api_resource/mocks.rb', line 131

def body
  @body
end

#codeObject (readonly)

Returns the value of attribute code.



131
132
133
# File 'lib/old_api_resource/mocks.rb', line 131

def code
  @code
end

#formatObject (readonly)

Returns the value of attribute format.



131
132
133
# File 'lib/old_api_resource/mocks.rb', line 131

def format
  @format
end

#headersObject (readonly)

Returns the value of attribute headers.



131
132
133
# File 'lib/old_api_resource/mocks.rb', line 131

def headers
  @headers
end

Instance Method Details

#[](key) ⇒ Object



143
144
145
# File 'lib/old_api_resource/mocks.rb', line 143

def [](key)
  @headers[key]
end

#[]=(key, val) ⇒ Object



140
141
142
# File 'lib/old_api_resource/mocks.rb', line 140

def []=(key, val)
  @headers[key] = val
end

#body_as_objectObject



152
153
154
# File 'lib/old_api_resource/mocks.rb', line 152

def body_as_object
  return @body
end

#generate_response(params) ⇒ Object



156
157
158
# File 'lib/old_api_resource/mocks.rb', line 156

def generate_response(params)
  @body = @body.instance_exec(params, &self.block) if self.block
end