Class: EZDyn::Response
- Inherits:
-
Object
- Object
- EZDyn::Response
- Defined in:
- lib/ezdyn/response.rb
Overview
Abstraction of a Dyn REST API response.
Instance Method Summary collapse
-
#data ⇒ Hash
The payload data from the response.
-
#delayed? ⇒ Boolean
Do we have to wait for the response?.
-
#error_codes ⇒ Array<String>
All error codes returned by the response.
-
#full_message ⇒ String
Full version of the descriptive response message with log levels and error codes.
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
-
#job_id ⇒ String
The job ID returned by the response.
-
#simple_message ⇒ String
The simple descriptive message of the response from the API.
-
#status ⇒ String
Returns the status message of the response.
-
#success? ⇒ Boolean
Was the response successful?.
Constructor Details
#initialize(response) ⇒ Response
Returns a new instance of Response.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# 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 |
Instance Method Details
#data ⇒ Hash
The payload data from the response.
53 54 55 |
# File 'lib/ezdyn/response.rb', line 53 def data @raw["data"] end |
#delayed? ⇒ Boolean
Do we have to wait for the response?
39 40 41 |
# File 'lib/ezdyn/response.rb', line 39 def delayed? self.status == "delayed" end |
#error_codes ⇒ Array<String>
All error codes returned by the response.
78 79 80 |
# File 'lib/ezdyn/response.rb', line 78 def error_codes @raw["msgs"].collect { |m| m["ERR_CD"] }.compact.uniq end |
#full_message ⇒ String
Full version of the descriptive response message with log levels and error codes.
62 63 64 65 66 |
# File 'lib/ezdyn/response.rb', line 62 def @raw["msgs"].collect do |msg| "[#{msg["SOURCE"]}] #{msg["LVL"]} (#{msg["ERR_CD"]}): #{msg[msg["LVL"]]}" end.join("\n") end |
#job_id ⇒ String
The job ID returned by the response.
46 47 48 |
# File 'lib/ezdyn/response.rb', line 46 def job_id @raw["job_id"] end |
#simple_message ⇒ String
The simple descriptive message of the response from the API.
71 72 73 |
# File 'lib/ezdyn/response.rb', line 71 def @raw["msgs"].collect { |m| m[m["LVL"]] }.join("\n") end |
#status ⇒ String
Returns the status message of the response.
24 25 26 |
# File 'lib/ezdyn/response.rb', line 24 def status @raw["status"] end |
#success? ⇒ Boolean
Was the response successful?
31 32 33 |
# File 'lib/ezdyn/response.rb', line 31 def success? self.status == "success" end |