Class: NetObserver::Base

Inherits:
Object
  • Object
show all
Includes:
Observable, Singleton
Defined in:
lib/net_observer/base.rb

Overview

Base Class ==

Basic object for observing network communication. It is singleton, as it doesn't make sense to have more then one object which observe network. Object is observable, so anyone could attach own object which contain update method for all network objects.

Parameters for update command in observers:

@param(Symbol) type of request, can be :request or :response

@param(Net::HttpRequest) request send or received from network

@param(String) body body used/received in request

@param(Net::HTTP,Net::HTTPS) connection connection on which is called method

See Also:

  • for example usage

Instance Method Summary (collapse)

Instance Method Details

- (Object) request_data(connection, request, body)

internal method for network hook



29
30
31
32
# File 'lib/net_observer/base.rb', line 29

def request_data(connection, request,body)
	changed
	notify_observers(:request,request,body, connection)
end

- (Object) response_data(connection, response)

internal method for network hook



35
36
37
38
39
# File 'lib/net_observer/base.rb', line 35

def response_data(connection, response)
	changed
	body = response.respond_to?(:body) ? response.body : ""
	notify_observers(:response,response,body, connection)
end