Class: WechatPayment::ServiceResult

Inherits:
Object
  • Object
show all
Defined in:
lib/wechat_payment/service_result.rb

Direct Known Subclasses

FailureResult, SuccessResult

Instance Attribute Summary collapse

Instance Method Summary collapse

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.message = message
  self.message_type = message_type
  self.message_kind = message_kind
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



3
4
5
# File 'lib/wechat_payment/service_result.rb', line 3

def data
  @data
end

#errorObject

Returns the value of attribute error.



3
4
5
# File 'lib/wechat_payment/service_result.rb', line 3

def error
  @error
end

#messageObject

Returns the value of attribute message.



3
4
5
# File 'lib/wechat_payment/service_result.rb', line 3

def message
  @message
end

#message_kindObject

Returns the value of attribute message_kind.



3
4
5
# File 'lib/wechat_payment/service_result.rb', line 3

def message_kind
  @message_kind
end

#message_typeObject

Returns the value of attribute message_type.



3
4
5
# File 'lib/wechat_payment/service_result.rb', line 3

def message_type
  @message_type
end

#successObject 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(options = {})
  {
    success: success,
    data: data,
    message: message,
    error: error,
    message_kind: message_kind,
    message_type: message_type
  }
end

#failure?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/wechat_payment/service_result.rb', line 27

def failure?
  !success?
end

#message_kind_prefixObject



49
50
51
# File 'lib/wechat_payment/service_result.rb', line 49

def message_kind_prefix
  "wechat_payment_"
end

#on_failure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



35
36
37
# File 'lib/wechat_payment/service_result.rb', line 35

def on_failure
  yield(self) if failure?
end

#on_success {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



31
32
33
# File 'lib/wechat_payment/service_result.rb', line 31

def on_success
  yield(self) if success?
end