Class: Fusebox::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/fusebox/response.rb

Overview

Constant Summary collapse

CSV_MAPS =

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

{
  :report_basic => [
    :username,
    :internal_account_id,
    :status,
    :password,
    :account_plan
  ],

  :report_extended => [
    :username,
    :internal_account_id,
    :status,
    :password,
    :account_plan,
    :creation_date,
    :first_name,
    :last_name,
    :company_name,
    :street_1,
    :street_2,
    :city,
    :state,
    :phone,
    :disk_usage
  ],

  :reportmail => [
    :username,
    :internal_account_id,
    :email_type,
    :email_name,
    :email_destination
  ]
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_response, result_map_type = nil) ⇒ Response

Returns a new instance of Response.

Parameters:

  • http_response (Net::HTTPOK)
  • result_map_type (Fusebox::Request::CSV_MAPS.keys) (defaults to: nil)

    Which CSV_MAPS to use to map map column names of CSV results (for report and reportmail types)


58
59
60
61
62
63
64
65
66
67
68
69
70
71
# 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

Instance Attribute Details

#codeFixnum (readonly)

Returns Numeric code # of.

Returns:

  • (Fixnum)

    Numeric code # of


11
12
13
# File 'lib/fusebox/response.rb', line 11

def code
  @code
end

#detailString (readonly)

Returns Human-readable description of response, corresponding to #code.

Returns:

  • (String)

    Human-readable description of response, corresponding to #code


14
15
16
# File 'lib/fusebox/response.rb', line 14

def detail
  @detail
end

#http_responseNet::HTTPOK (readonly)

Returns:

  • (Net::HTTPOK)

8
9
10
# File 'lib/fusebox/response.rb', line 8

def http_response
  @http_response
end

#recordsArray<Hash> (readonly)

Returns Array of records returned by query-type commands, e.g. 'report'.

Returns:

  • (Array<Hash>)

    Array of records returned by query-type commands, e.g. 'report'


17
18
19
# File 'lib/fusebox/response.rb', line 17

def records
  @records
end

Instance Method Details

#success?Boolean

Returns:

  • (Boolean)

74
75
76
# File 'lib/fusebox/response.rb', line 74

def success?
  @code == 1
end