Class: Imgur::Response

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

Defined Under Namespace

Classes: Error

Constant Summary collapse

BadRequest =
Class.new(Error)
NotFound =
Class.new(Error)
Forbidden =
Class.new(Error)
Unprocessable =
Class.new(Error)
EXCEPTION_MAPPING =
{
  400 => BadRequest,
  403 => Forbidden,
  404 => NotFound,
  422 => Unprocessable,
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status, headers, body) ⇒ Response

Returns a new instance of Response.



24
25
26
# File 'lib/imgur/response.rb', line 24

def initialize(status, headers, body)
  @status, @headers, @body = status, headers, body
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



22
23
24
# File 'lib/imgur/response.rb', line 22

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



22
23
24
# File 'lib/imgur/response.rb', line 22

def headers
  @headers
end

#statusObject (readonly)

Returns the value of attribute status.



22
23
24
# File 'lib/imgur/response.rb', line 22

def status
  @status
end

Instance Method Details

#raise!Object



32
33
34
35
36
37
# File 'lib/imgur/response.rb', line 32

def raise!
  if klass = EXCEPTION_MAPPING[self.status.to_i]
    raise klass.new(self)
  else self
  end
end

#successful?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/imgur/response.rb', line 28

def successful?
  self.status.to_i < 300 && self.status.to_i > 199
end