Class: Fusebox::Response
- Inherits:
-
Object
- Object
- Fusebox::Response
- Defined in:
- lib/fusebox/response.rb
Overview
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)
-
- (Fixnum) code
readonly
Numeric code # of.
-
- (String) detail
readonly
Human-readable description of response, corresponding to #code.
- - (Net::HTTPOK) http_response readonly
-
- (Array<Hash>) records
readonly
Array of records returned by query-type commands, e.g.
Instance Method Summary (collapse)
-
- (Response) initialize(http_response, result_map_type = nil)
constructor
A new instance of Response.
- - (Boolean) success?
Constructor Details
- (Response) initialize(http_response, result_map_type = nil)
A new instance of Response
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
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
14 15 16 |
# File 'lib/fusebox/response.rb', line 14 def detail @detail end |
- (Net::HTTPOK) http_response (readonly)
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'
17 18 19 |
# File 'lib/fusebox/response.rb', line 17 def records @records end |
Instance Method Details
- (Boolean) success?
74 75 76 |
# File 'lib/fusebox/response.rb', line 74 def success? @code == 1 end |