Class: Reynard::Http::Response
- Inherits:
 - 
      Object
      
        
- Object
 - Reynard::Http::Response
 
 
- Extended by:
 - Forwardable
 
- Defined in:
 - lib/reynard/http/response.rb
 
Overview
Wraps an HTTP response and returns an object when it can find a definition for the response in the specification.
Instance Method Summary collapse
- 
  
    
      #client_error?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
True when the response code is in the 4xx range.
 - 
  
    
      #informational?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
True when the response code is in the 1xx range.
 - 
  
    
      #initialize(specification:, inflector:, request_context:, http_response:)  ⇒ Response 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of Response.
 - 
  
    
      #object  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Instantiates an object based on the schema that fits the response.
 - 
  
    
      #parsed_body  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Returns the parsed response body.
 - 
  
    
      #redirection?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
True when the response code is in the 3xx range.
 - 
  
    
      #server_error?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
True when the response code is in the 5xx range.
 - 
  
    
      #success?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
True when the response code is in the 2xx range.
 
Constructor Details
#initialize(specification:, inflector:, request_context:, http_response:) ⇒ Response
Returns a new instance of Response.
      11 12 13 14 15 16  | 
    
      # File 'lib/reynard/http/response.rb', line 11 def initialize(specification:, inflector:, request_context:, http_response:) @specification = specification @inflector = inflector @request_context = request_context @http_response = http_response end  | 
  
Instance Method Details
#client_error? ⇒ Boolean
True when the response code is in the 4xx range.
      34 35 36  | 
    
      # File 'lib/reynard/http/response.rb', line 34 def client_error? code.start_with?('4') end  | 
  
#informational? ⇒ Boolean
True when the response code is in the 1xx range.
      19 20 21  | 
    
      # File 'lib/reynard/http/response.rb', line 19 def informational? code.start_with?('1') end  | 
  
#object ⇒ Object
Instantiates an object based on the schema that fits the response.
      51 52 53 54 55  | 
    
      # File 'lib/reynard/http/response.rb', line 51 def object return @object if defined?(@object) @object = build_object end  | 
  
#parsed_body ⇒ Object
Returns the parsed response body.
      44 45 46 47 48  | 
    
      # File 'lib/reynard/http/response.rb', line 44 def parsed_body return @parsed_body if defined?(@parsed_body) @parsed_body = MultiJson.load(@http_response.body) end  | 
  
#redirection? ⇒ Boolean
True when the response code is in the 3xx range.
      29 30 31  | 
    
      # File 'lib/reynard/http/response.rb', line 29 def redirection? code.start_with?('3') end  | 
  
#server_error? ⇒ Boolean
True when the response code is in the 5xx range.
      39 40 41  | 
    
      # File 'lib/reynard/http/response.rb', line 39 def server_error? code.start_with?('5') end  | 
  
#success? ⇒ Boolean
True when the response code is in the 2xx range.
      24 25 26  | 
    
      # File 'lib/reynard/http/response.rb', line 24 def success? code.start_with?('2') end  |