Class: WeixinAuthorize::ResultHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/weixin_authorize/handler/result_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, en_msg, result = {}) ⇒ ResultHandler

Returns a new instance of ResultHandler.



8
9
10
11
12
13
# File 'lib/weixin_authorize/handler/result_handler.rb', line 8

def initialize(code, en_msg, result={})
  @code   = code   || OK_CODE
  @en_msg = en_msg || OK_MSG
  @cn_msg = GLOBAL_CODES[@code.to_i]
  @result = package_result(result)
end

Instance Attribute Details

#cn_msgObject

Returns the value of attribute cn_msg.



6
7
8
# File 'lib/weixin_authorize/handler/result_handler.rb', line 6

def cn_msg
  @cn_msg
end

#codeObject

Returns the value of attribute code.



6
7
8
# File 'lib/weixin_authorize/handler/result_handler.rb', line 6

def code
  @code
end

#en_msgObject

Returns the value of attribute en_msg.



6
7
8
# File 'lib/weixin_authorize/handler/result_handler.rb', line 6

def en_msg
  @en_msg
end

#resultObject

Returns the value of attribute result.



6
7
8
# File 'lib/weixin_authorize/handler/result_handler.rb', line 6

def result
  @result
end

Instance Method Details

#full_error_messageObject Also known as: full_error_messages, errors



28
29
30
# File 'lib/weixin_authorize/handler/result_handler.rb', line 28

def full_error_message
  full_message if !is_ok?
end

#full_messageObject Also known as: full_messages

e.g.: 45009: api freq out of limit(接口调用超过限制)



23
24
25
# File 'lib/weixin_authorize/handler/result_handler.rb', line 23

def full_message
  "#{code}: #{en_msg}(#{cn_msg})."
end

#is_ok?Boolean Also known as: ok?

This method is to valid the current request if is true or is false

Returns:

  • (Boolean)


16
17
18
# File 'lib/weixin_authorize/handler/result_handler.rb', line 16

def is_ok?
  code == OK_CODE
end