Class: WechatPayment::ServiceResult
- Inherits:
-
Object
- Object
- WechatPayment::ServiceResult
- Defined in:
- lib/wechat_payment/service_result.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#error ⇒ Object
Returns the value of attribute error.
-
#message ⇒ Object
Returns the value of attribute message.
-
#message_kind ⇒ Object
Returns the value of attribute message_kind.
-
#message_type ⇒ Object
Returns the value of attribute message_type.
-
#success ⇒ Object
(also: #success?)
Returns the value of attribute success.
Instance Method Summary collapse
- #as_json(options = {}) ⇒ Object
- #failure? ⇒ Boolean
-
#initialize(success: false, data: {}, error: nil, message: nil, message_kind: nil, message_type: nil) ⇒ ServiceResult
constructor
A new instance of ServiceResult.
- #message_kind_prefix ⇒ Object
- #on_failure {|_self| ... } ⇒ Object
- #on_success {|_self| ... } ⇒ Object
Constructor Details
#initialize(success: false, data: {}, error: nil, message: nil, message_kind: nil, message_type: nil) ⇒ ServiceResult
Returns a new instance of ServiceResult.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/wechat_payment/service_result.rb', line 10 def initialize(success: false, data: {}, error: nil, message: nil, message_kind: nil, message_type: nil) self.success = success self.data = (data || {}).with_indifferent_access self.error = error self. = self. = self. = end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
3 4 5 |
# File 'lib/wechat_payment/service_result.rb', line 3 def data @data end |
#error ⇒ Object
Returns the value of attribute error.
3 4 5 |
# File 'lib/wechat_payment/service_result.rb', line 3 def error @error end |
#message ⇒ Object
Returns the value of attribute message.
3 4 5 |
# File 'lib/wechat_payment/service_result.rb', line 3 def @message end |
#message_kind ⇒ Object
Returns the value of attribute message_kind.
3 4 5 |
# File 'lib/wechat_payment/service_result.rb', line 3 def @message_kind end |
#message_type ⇒ Object
Returns the value of attribute message_type.
3 4 5 |
# File 'lib/wechat_payment/service_result.rb', line 3 def @message_type end |
#success ⇒ Object Also known as: success?
Returns the value of attribute success.
3 4 5 |
# File 'lib/wechat_payment/service_result.rb', line 3 def success @success end |
Instance Method Details
#as_json(options = {}) ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/wechat_payment/service_result.rb', line 57 def as_json( = {}) { success: success, data: data, message: , error: error, message_kind: , message_type: } end |
#failure? ⇒ Boolean
27 28 29 |
# File 'lib/wechat_payment/service_result.rb', line 27 def failure? !success? end |
#message_kind_prefix ⇒ Object
49 50 51 |
# File 'lib/wechat_payment/service_result.rb', line 49 def "wechat_payment_" end |
#on_failure {|_self| ... } ⇒ Object
35 36 37 |
# File 'lib/wechat_payment/service_result.rb', line 35 def on_failure yield(self) if failure? end |
#on_success {|_self| ... } ⇒ Object
31 32 33 |
# File 'lib/wechat_payment/service_result.rb', line 31 def on_success yield(self) if success? end |