Handler class to process response messages for API unit usage and statistics information.
Methods
- N
- O
- P
Class Public methods
Constructor for ResponseHandler.
Args:
- parent: AdWords::API object to which the ResponseHandler should be tied
Source: show
# File lib/adwords4r.rb, line 320 def initialize(parent) @parent = parent end
Instance Public methods
Handles the callback method. Logs the request data and tracks unit usage.
Args:
- method_name: name for the operation that was invoked
- endpoint: the enodpoint URL the request was sent to
- envelope: the envelope for the SOAP response that was received
Source: show
# File lib/adwords4r.rb, line 332 def on_callback(method_name, endpoint, envelope) units = nil operations = nil response_time = nil request_id = nil header = envelope.header if header.key?('ResponseHeader') header = header['ResponseHeader'].element end @parent.mutex.synchronize do units = parse_header(header['units']) unless units.nil? @parent.last_units = units.to_i @parent.total_units = @parent.total_units + units.to_i end operations = parse_header(header['operations']) response_time = parse_header(header['responseTime']) request_id = parse_header(header['requestId']) end host = URI.parse(endpoint).host data = "host=#{host} method=#{method_name} " + "responseTime=#{response_time} operations=#{operations} " + "units=#{units} requestId=#{request_id}" @parent.unit_logger << data end
Parses the value contained in a SOAP response header.
Args:
- header: an object representing a SOAP header
Returns: The value contained in the header as a string, or nil if the header is nil
Source: show
# File lib/adwords4r.rb, line 372 def parse_header(header) if header.nil? return nil end header_element = header if header.instance_variable_defined?('@element') header_element = header.element end return header_element.text end