Class: CZTop::ZAP::Response
- Inherits:
-
Object
- Object
- CZTop::ZAP::Response
- Includes:
- StatusCodes
- Defined in:
- lib/cztop/zap.rb
Overview
Represents a ZAP response.
Defined Under Namespace
Modules: StatusCodes Classes: InternalError, TemporaryError
Constant Summary
Constants included from StatusCodes
StatusCodes::ALL, StatusCodes::AUTHENTICATION_FAILURE, StatusCodes::INTERNAL_ERROR, StatusCodes::SUCCESS, StatusCodes::TEMPORARY_ERROR
Instance Attribute Summary collapse
-
#meta_data ⇒ String?
Returns the meta data, if authentication was successful.
-
#request_id ⇒ String
The original request ID.
-
#status_code ⇒ String
Status code.
-
#status_text ⇒ String
Status explanation.
-
#user_id ⇒ String?
Returns the user ID, if authentication was successful.
-
#version ⇒ String
ZAP version.
Class Method Summary collapse
-
.from_message(msg) ⇒ Response
Crafts a new Response from a message.
Instance Method Summary collapse
-
#initialize(status_code) ⇒ Response
constructor
Initializes a new response.
-
#success? ⇒ Boolean
Whether the authentication was successful.
-
#to_msg ⇒ CZTop::Message
Creates a sendable message from this Response.
Constructor Details
Instance Attribute Details
#meta_data ⇒ String?
Returns the meta data, if authentication was successful.
220 221 222 223 |
# File 'lib/cztop/zap.rb', line 220 def return nil unless success? @meta_data end |
#request_id ⇒ String
Returns the original request ID.
180 181 182 |
# File 'lib/cztop/zap.rb', line 180 def request_id @request_id end |
#status_code ⇒ String
Returns status code.
184 185 186 |
# File 'lib/cztop/zap.rb', line 184 def status_code @status_code end |
#status_text ⇒ String
Returns status explanation.
187 188 189 |
# File 'lib/cztop/zap.rb', line 187 def status_text @status_text end |
#user_id ⇒ String?
Returns the user ID, if authentication was successful.
212 213 214 215 |
# File 'lib/cztop/zap.rb', line 212 def user_id return nil unless success? @user_id end |
#version ⇒ String
Returns ZAP version.
177 178 179 |
# File 'lib/cztop/zap.rb', line 177 def version @version end |
Class Method Details
.from_message(msg) ⇒ Response
Crafts a new CZTop::ZAP::Response from a message.
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/cztop/zap.rb', line 144 def self.(msg) version, # The version frame, which SHALL contain the three octets "1.0". request_id, # The request id, which MAY contain an opaque binary blob. status_code, # The status code, which SHALL contain a string. status_text, # The status text, which MAY contain a string. user_id, # The user id, which SHALL contain a string. = # The meta data, which MAY contain a blob. msg.to_a raise VersionMismatch if version != VERSION case status_code when SUCCESS, AUTHENTICATION_FAILURE # valid codes, nothing to do when TEMPORARY_ERROR raise TemporaryError, status_text when INTERNAL_ERROR raise InternalError, status_text else raise InternalError, "invalid status code" end new(status_code).tap do |r| r.version = version r.request_id = request_id r.status_code = status_code r.status_text = status_text r.user_id = user_id r. = end end |
Instance Method Details
#success? ⇒ Boolean
Returns whether the authentication was successful.
205 206 207 |
# File 'lib/cztop/zap.rb', line 205 def success? @status_code == SUCCESS end |
#to_msg ⇒ CZTop::Message
Creates a sendable message from this CZTop::ZAP::Response.
227 228 229 230 231 |
# File 'lib/cztop/zap.rb', line 227 def to_msg fields = [@version, @request_id, @status_code, @status_text, @user_id, @meta_data].map(&:to_s) CZTop::Message.new(fields) end |