class Fusebox::Response

@see www.fusemail.com/support/administration-api/httphttps-response Fusemail Response documentation

Constants

CSV_MAPS

Column name mapping for CSV data returned by report and reportmail request types

Attributes

code[R]

@return [Fixnum] Numeric code # of

detail[R]

@return [String] Human-readable description of response, corresponding to {#code}

http_response[R]

@return [Net::HTTPOK]

records[R]

@return [Array<Hash>] Array of records returned by query-type commands, e.g. ‘report’

Public Class Methods

new(http_response, result_map_type = nil) click to toggle source

@param [Net::HTTPOK] http_response Response from {Net::HTTP.post_form_with_ssl} @param [Fusebox::Request::CSV_MAPS.keys] result_map_type Which CSV_MAPS to use to map map column names of CSV results (for report and reportmail types)

# File lib/fusebox/response.rb, line 58
def initialize (http_response, result_map_type = nil)
  @http_response = http_response
  records = http_response.body.split(/[\r\n]/)
  code, @detail = records.shift.split('||')
  @code = code.to_i

  if result_map_type
    raise ArgumentError, "result_map_type: #{result_map_type} does not exist in CSV_MAPS" unless CSV_MAPS[result_map_type]
    @records = records.map do |line|
      Hash[CSV_MAPS[result_map_type].zip(CSV.parse_line(line))]
    end
  end

end

Public Instance Methods

success?() click to toggle source

@return [Boolean]

# File lib/fusebox/response.rb, line 74
def success?
  @code == 1
end