Class: Trav3::Response

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/trav3/response/response.rb

Overview

The results from queries return either Success or RequestError which both repsond with Hash like query methods for the JSON data or the Net::HTTP resonse object methods.

The Response classes Success and RequestError forward method calls for all of the instance methods of a ResponseCollection to the collection. And many of the methods calls for the Net::HTTP response are also available on this class and those method calls are forwarded to the response.

Direct Known Subclasses

RequestError, Success

Instance Method Summary collapse

Constructor Details

#initialize(travis, response) ⇒ Response

Returns a new instance of Response



115
116
117
118
119
120
121
122
123
124
# File 'lib/trav3/response/response.rb', line 115

def initialize(travis, response)
  @travis = travis
  @response = response
  @collection = begin
                  result = JSON.parse(response&.body || '{}')
                  ResponseCollection.new(travis, result)
                rescue JSON::ParserError
                  response.error!
                end
end

Instance Method Details

#[]Object

Forwards to :@collection



58
# File 'lib/trav3/response/response.rb', line 58

def_delegators :@collection, *ResponseCollection.instance_methods(false)

#bodyObject

Forwards to :@response

See Also:

  • Net::HTTPResponse#body


111
112
113
114
# File 'lib/trav3/response/response.rb', line 111

def_delegators :@response, :body, :code, :code_type, :decode_content,
:each_header, :entity, :get_fields, :header, :http_version,
:message, :msg, :read_body, :read_header, :reading_body, :response,
:uri, :value

#codeObject

Forwards to :@response

See Also:

  • Net::HTTPResponse#code


111
112
113
114
# File 'lib/trav3/response/response.rb', line 111

def_delegators :@response, :body, :code, :code_type, :decode_content,
:each_header, :entity, :get_fields, :header, :http_version,
:message, :msg, :read_body, :read_header, :reading_body, :response,
:uri, :value

#code_typeObject

Forwards to :@response

See Also:

  • Net::HTTPResponse#code_type


111
112
113
114
# File 'lib/trav3/response/response.rb', line 111

def_delegators :@response, :body, :code, :code_type, :decode_content,
:each_header, :entity, :get_fields, :header, :http_version,
:message, :msg, :read_body, :read_header, :reading_body, :response,
:uri, :value

#countObject

Forwards to :@collection.



58
# File 'lib/trav3/response/response.rb', line 58

def_delegators :@collection, *ResponseCollection.instance_methods(false)

#decode_contentObject

Forwards to :@response

See Also:

  • Net::HTTPResponse#decode_content


111
112
113
114
# File 'lib/trav3/response/response.rb', line 111

def_delegators :@response, :body, :code, :code_type, :decode_content,
:each_header, :entity, :get_fields, :header, :http_version,
:message, :msg, :read_body, :read_header, :reading_body, :response,
:uri, :value

#digObject

Forwards to :@collection



58
# File 'lib/trav3/response/response.rb', line 58

def_delegators :@collection, *ResponseCollection.instance_methods(false)

#eachObject

Forwards to :@collection



58
# File 'lib/trav3/response/response.rb', line 58

def_delegators :@collection, *ResponseCollection.instance_methods(false)

#each_headerObject

Forwards to :@response

See Also:

  • Net::HTTPHeader#each_header


111
112
113
114
# File 'lib/trav3/response/response.rb', line 111

def_delegators :@response, :body, :code, :code_type, :decode_content,
:each_header, :entity, :get_fields, :header, :http_version,
:message, :msg, :read_body, :read_header, :reading_body, :response,
:uri, :value

#empty?Object

Forwards to :@collection.



58
# File 'lib/trav3/response/response.rb', line 58

def_delegators :@collection, *ResponseCollection.instance_methods(false)

#entityObject

Forwards to :@response

See Also:

  • Net::HTTPResponse#entity


111
112
113
114
# File 'lib/trav3/response/response.rb', line 111

def_delegators :@response, :body, :code, :code_type, :decode_content,
:each_header, :entity, :get_fields, :header, :http_version,
:message, :msg, :read_body, :read_header, :reading_body, :response,
:uri, :value

#failure?Boolean

This method is abstract.

Returns:

  • (Boolean)

Raises:



137
138
139
# File 'lib/trav3/response/response.rb', line 137

def failure?
  raise Unimplemented
end

#fetchObject

Forwards to :@collection



58
# File 'lib/trav3/response/response.rb', line 58

def_delegators :@collection, *ResponseCollection.instance_methods(false)

#firstObject

Forwards to :@collection



58
# File 'lib/trav3/response/response.rb', line 58

def_delegators :@collection, *ResponseCollection.instance_methods(false)

#followObject

Forwards to :@collection



58
# File 'lib/trav3/response/response.rb', line 58

def_delegators :@collection, *ResponseCollection.instance_methods(false)

#get_fieldsObject

Forwards to :@response

See Also:

  • Net::HTTPHeader#get_fields


111
112
113
114
# File 'lib/trav3/response/response.rb', line 111

def_delegators :@response, :body, :code, :code_type, :decode_content,
:each_header, :entity, :get_fields, :header, :http_version,
:message, :msg, :read_body, :read_header, :reading_body, :response,
:uri, :value

#has_key?Object

Forwards to :@collection.



58
# File 'lib/trav3/response/response.rb', line 58

def_delegators :@collection, *ResponseCollection.instance_methods(false)

#hash?Object

Forwards to :@collection



58
# File 'lib/trav3/response/response.rb', line 58

def_delegators :@collection, *ResponseCollection.instance_methods(false)

#headerObject

Forwards to :@response

See Also:

  • Net::HTTPResponse#header


111
112
113
114
# File 'lib/trav3/response/response.rb', line 111

def_delegators :@response, :body, :code, :code_type, :decode_content,
:each_header, :entity, :get_fields, :header, :http_version,
:message, :msg, :read_body, :read_header, :reading_body, :response,
:uri, :value

#http_versionObject

Forwards to :@response

See Also:

  • Net::HTTPResponse#http_version


111
112
113
114
# File 'lib/trav3/response/response.rb', line 111

def_delegators :@response, :body, :code, :code_type, :decode_content,
:each_header, :entity, :get_fields, :header, :http_version,
:message, :msg, :read_body, :read_header, :reading_body, :response,
:uri, :value

#inspectObject

Class name and keys of response



127
128
129
# File 'lib/trav3/response/response.rb', line 127

def inspect
  "<#{self.class} Response: keys = #{keys}>"
end

#key?Object

Forwards to :@collection.



58
# File 'lib/trav3/response/response.rb', line 58

def_delegators :@collection, *ResponseCollection.instance_methods(false)

#keysObject

Forwards to :@collection.



58
# File 'lib/trav3/response/response.rb', line 58

def_delegators :@collection, *ResponseCollection.instance_methods(false)

#lastObject

Forwards to :@collection



58
# File 'lib/trav3/response/response.rb', line 58

def_delegators :@collection, *ResponseCollection.instance_methods(false)

#messageObject

Forwards to :@response

See Also:

  • Net::HTTPResponse#message


111
112
113
114
# File 'lib/trav3/response/response.rb', line 111

def_delegators :@response, :body, :code, :code_type, :decode_content,
:each_header, :entity, :get_fields, :header, :http_version,
:message, :msg, :read_body, :read_header, :reading_body, :response,
:uri, :value

#msgObject

Forwards to :@response

See Also:

  • Net::HTTPResponse#msg


111
112
113
114
# File 'lib/trav3/response/response.rb', line 111

def_delegators :@response, :body, :code, :code_type, :decode_content,
:each_header, :entity, :get_fields, :header, :http_version,
:message, :msg, :read_body, :read_header, :reading_body, :response,
:uri, :value

#read_bodyObject

Forwards to :@response

See Also:

  • Net::HTTPResponse#read_body


111
112
113
114
# File 'lib/trav3/response/response.rb', line 111

def_delegators :@response, :body, :code, :code_type, :decode_content,
:each_header, :entity, :get_fields, :header, :http_version,
:message, :msg, :read_body, :read_header, :reading_body, :response,
:uri, :value

#read_headerObject

Forwards to :@response

See Also:

  • Net::HTTPResponse#read_header


111
112
113
114
# File 'lib/trav3/response/response.rb', line 111

def_delegators :@response, :body, :code, :code_type, :decode_content,
:each_header, :entity, :get_fields, :header, :http_version,
:message, :msg, :read_body, :read_header, :reading_body, :response,
:uri, :value

#reading_bodyObject

Forwards to :@response

See Also:

  • Net::HTTPResponse#reading_body


111
112
113
114
# File 'lib/trav3/response/response.rb', line 111

def_delegators :@response, :body, :code, :code_type, :decode_content,
:each_header, :entity, :get_fields, :header, :http_version,
:message, :msg, :read_body, :read_header, :reading_body, :response,
:uri, :value

#responseObject

Forwards to :@response

See Also:

  • Net::HTTPResponse#response


111
112
113
114
# File 'lib/trav3/response/response.rb', line 111

def_delegators :@response, :body, :code, :code_type, :decode_content,
:each_header, :entity, :get_fields, :header, :http_version,
:message, :msg, :read_body, :read_header, :reading_body, :response,
:uri, :value

#success?Boolean

This method is abstract.

Returns:

  • (Boolean)

Raises:



132
133
134
# File 'lib/trav3/response/response.rb', line 132

def success?
  raise Unimplemented
end

#uriObject

Forwards to :@response

See Also:

  • Net::HTTPResponse#uri


111
112
113
114
# File 'lib/trav3/response/response.rb', line 111

def_delegators :@response, :body, :code, :code_type, :decode_content,
:each_header, :entity, :get_fields, :header, :http_version,
:message, :msg, :read_body, :read_header, :reading_body, :response,
:uri, :value

#valueObject

Forwards to :@response

See Also:

  • Net::HTTPResponse#value


111
112
113
114
# File 'lib/trav3/response/response.rb', line 111

def_delegators :@response, :body, :code, :code_type, :decode_content,
:each_header, :entity, :get_fields, :header, :http_version,
:message, :msg, :read_body, :read_header, :reading_body, :response,
:uri, :value

#valuesObject

Forwards to :@collection.



58
# File 'lib/trav3/response/response.rb', line 58

def_delegators :@collection, *ResponseCollection.instance_methods(false)