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.
241 242 243 244 245 |
# File 'lib/cztop/zap.rb', line 241 def return nil unless success? @meta_data end |
#request_id ⇒ String
Returns the original request ID.
196 197 198 |
# File 'lib/cztop/zap.rb', line 196 def request_id @request_id end |
#status_code ⇒ String
Returns status code.
200 201 202 |
# File 'lib/cztop/zap.rb', line 200 def status_code @status_code end |
#status_text ⇒ String
Returns status explanation.
203 204 205 |
# File 'lib/cztop/zap.rb', line 203 def status_text @status_text end |
#user_id ⇒ String?
Returns the user ID, if authentication was successful.
231 232 233 234 235 |
# File 'lib/cztop/zap.rb', line 231 def user_id return nil unless success? @user_id end |
#version ⇒ String
Returns ZAP version.
193 194 195 |
# File 'lib/cztop/zap.rb', line 193 def version @version end |
Class Method Details
.from_message(msg) ⇒ Response
Crafts a new CZTop::ZAP::Response from a message.
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/cztop/zap.rb', line 160 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.
223 224 225 |
# File 'lib/cztop/zap.rb', line 223 def success? @status_code == SUCCESS end |
#to_msg ⇒ CZTop::Message
Creates a sendable message from this CZTop::ZAP::Response.
250 251 252 253 254 |
# File 'lib/cztop/zap.rb', line 250 def to_msg fields = [@version, @request_id, @status_code, @status_text, @user_id, @meta_data].map(&:to_s) CZTop::Message.new(fields) end |