Class: Fusebox::Response

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

Overview

See Also:

Constant Summary

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

- (Response) initialize(http_response, result_map_type = nil)

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

- (Fixnum) code (readonly)

Numeric code # of

Returns:

  • (Fixnum)

    Numeric code # of



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

def code
  @code
end

- (String) detail (readonly)

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

- (Net::HTTPOK) http_response (readonly)

Returns:

  • (Net::HTTPOK)


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

def http_response
  @http_response
end

- (Array<Hash>) records (readonly)

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

- (Boolean) success?

Returns:

  • (Boolean)


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

def success?
  @code == 1
end