Class: ISO8583::MKB::Request
- Inherits:
-
Object
- Object
- ISO8583::MKB::Request
- Defined in:
- lib/iso8583-mkb/request.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#retries ⇒ Object
Returns the value of attribute retries.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(transaction) ⇒ Request
constructor
A new instance of Request.
- #status_description ⇒ Object
- #submit(&complete) ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(transaction) ⇒ Request
Returns a new instance of Request.
22 23 24 25 26 27 28 29 |
# File 'lib/iso8583-mkb/request.rb', line 22 def initialize(transaction) @retries = 4 @timeout = 60 @retry_with = nil @complete = nil @request = nil @transaction = transaction end |
Instance Attribute Details
#request ⇒ Object (readonly)
Returns the value of attribute request.
17 18 19 |
# File 'lib/iso8583-mkb/request.rb', line 17 def request @request end |
#retries ⇒ Object
Returns the value of attribute retries.
19 20 21 |
# File 'lib/iso8583-mkb/request.rb', line 19 def retries @retries end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
17 18 19 |
# File 'lib/iso8583-mkb/request.rb', line 17 def status @status end |
#timeout ⇒ Object
Returns the value of attribute timeout.
20 21 22 |
# File 'lib/iso8583-mkb/request.rb', line 20 def timeout @timeout end |
Class Method Details
.build_class ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/iso8583-mkb/request.rb', line 4 def build_class [ const_get(:MANDATORY), const_get(:OPTIONAL) ].each do |hash| hash.each do |key, iso8583_name| attr_accessor key.intern end end const_get(:RESPONSE).each do |iso8583_name, key| attr_reader key.intern end end |
Instance Method Details
#status_description ⇒ Object
35 36 37 |
# File 'lib/iso8583-mkb/request.rb', line 35 def status_description Errors.error @status end |
#submit(&complete) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/iso8583-mkb/request.rb', line 39 def submit(&complete) translated_fields = {} self.class.const_get(:MANDATORY).each do |key, iso8583_name| value = instance_variable_get :"@#{key}" if value.nil? raise "required attribute #{key} (#{iso8583_name}) is not specified" end translated_fields[iso8583_name] = value end self.class.const_get(:OPTIONAL).each do |key, iso8583_name| value = instance_variable_get :"@#{key}" unless value.nil? translated_fields[iso8583_name] = value end end @request = @transaction.request do || .mti = self.class.const_get(:MTI) translated_fields.each do |key, value| [key] = value end .to_b # to validate encoding of the fields end @retry_with = [ self.class.const_get(:REPEAT_MTI), translated_fields ] @complete = complete @request.start @timeout, &method(:request_completed) end |