class EZDyn::Response

Abstraction of a Dyn REST API response.

Public Class Methods

new(response) click to toggle source

@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

data() click to toggle source

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
delayed?() click to toggle source

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
error_codes() click to toggle source

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_message() click to toggle source

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
job_id() click to toggle source

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
simple_message() click to toggle source

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
status() click to toggle source

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
success?() click to toggle source

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