Class: Rubeetup::RequestResponse

Inherits:
Object
  • Object
show all
Includes:
Utilities
Defined in:
lib/rubeetup/request_response.rb

Overview

Packages a response, and provides for its validation

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utilities

#blank?, #collection_symbolyzer, #present?, #stringify

Constructor Details

#initialize(sender) ⇒ RequestResponse

Returns a new instance of RequestResponse.

Parameters:

  • raw_data (Net::HTTPResponse)

    the raw response from the sender



29
30
31
32
33
34
# File 'lib/rubeetup/request_response.rb', line 29

def initialize(sender)
  @response = sender.response_data
  @request = sender.request
  body =  @response.body
  @parsed_body = blank?(body) ? [] : parse(body)
end

Instance Attribute Details

#parsed_bodyHash{Symbol=>...} (readonly)

Returns parsed_body the JSON-parsed body of the response. It is a Hash with all the keys as Symbols.

Returns:

  • (Hash{Symbol=>...})

    parsed_body the JSON-parsed body of the response. It is a Hash with all the keys as Symbols



19
20
21
# File 'lib/rubeetup/request_response.rb', line 19

def parsed_body
  @parsed_body
end

#requestRubeetup::Request (readonly)

Returns the request which caused this response.

Returns:



24
25
26
# File 'lib/rubeetup/request_response.rb', line 24

def request
  @request
end

#responseNet::HTTPResponse (readonly)

Returns response the raw response from the sender.

Returns:

  • (Net::HTTPResponse)

    response the raw response from the sender



13
14
15
# File 'lib/rubeetup/request_response.rb', line 13

def response
  @response
end

Instance Method Details

#dataArray<Rubeetup::ResponseWrapper>

If the request was successful, then creates a collection of Rubeetup::ResponseWrapper instances.

Returns:



41
42
43
44
45
# File 'lib/rubeetup/request_response.rb', line 41

def data
  fail error_class.new(self), error_message unless success?
  collection = collectionize(parsed_body)
  collection.map {|elem| wrapper_class.new(elem)}
end