class EZDyn::Response
Abstraction of a Dyn REST API response.
Public Class Methods
@private
# File lib/ezdyn/response.rb, line 5 def initialize(response) @response = response EZDyn.debug { "API RESPONSE: #{@response.body}" } if @response.body =~ %r{^/REST/Job/[0-9]+$} EZDyn.debug { "Response delayed! Try again later!" } @raw = { "status" => "delayed", "job_id" => @response.body.split('/').last, "msgs" => [], "data" => {}, } else @raw = JSON.parse(@response.body) end end
Public Instance Methods
The payload data from the response.
@return [Hash] The payload data of the response.
# File lib/ezdyn/response.rb, line 53 def data @raw["data"] end
Do we have to wait for the response?
@return [Boolean] Returns true if the response is delayed and you
must wait and try again.
# File lib/ezdyn/response.rb, line 39 def delayed? self.status == "delayed" end
All error codes returned by the response.
@return [Array<String>] An array of error codes returned by the response.
# File lib/ezdyn/response.rb, line 78 def error_codes @raw["msgs"].collect { |m| m["ERR_CD"] }.compact.uniq end
Full version of the descriptive response message with log levels and error codes.
@return [String] Full descriptive message of the response with error
codes and log levels.
# File lib/ezdyn/response.rb, line 62 def full_message @raw["msgs"].collect do |msg| "[#{msg["SOURCE"]}] #{msg["LVL"]} (#{msg["ERR_CD"]}): #{msg[msg["LVL"]]}" end.join("\n") end
The job ID returned by the response.
@return [String] The job ID of the response.
# File lib/ezdyn/response.rb, line 46 def job_id @raw["job_id"] end
The simple descriptive message of the response from the API.
@return [String] Descriptive message of the response.
# File lib/ezdyn/response.rb, line 71 def simple_message @raw["msgs"].collect { |m| m[m["LVL"]] }.join("\n") end
Returns the status message of the response.
@return [String] The status field of the response.
# File lib/ezdyn/response.rb, line 24 def status @raw["status"] end
Was the response successful?
@return [Boolean] Returns true if the response was successful.
# File lib/ezdyn/response.rb, line 31 def success? self.status == "success" end