Module: Wechat::Responder::ClassMethods
- Defined in:
- lib/wechat/responder.rb
Instance Attribute Summary collapse
-
#agentid ⇒ Object
Returns the value of attribute agentid.
-
#corpid ⇒ Object
Returns the value of attribute corpid.
-
#encoding_aes_key ⇒ Object
Returns the value of attribute encoding_aes_key.
-
#encrypt_mode ⇒ Object
Returns the value of attribute encrypt_mode.
-
#skip_verify_ssl ⇒ Object
Returns the value of attribute skip_verify_ssl.
-
#token ⇒ Object
Returns the value of attribute token.
-
#wechat ⇒ Object
Returns the value of attribute wechat.
Instance Method Summary collapse
- #on(message_type, with: nil, respond: nil, &block) ⇒ Object
- #responder_for(message) ⇒ Object
- #user_defined_responders(type) ⇒ Object
Instance Attribute Details
#agentid ⇒ Object
Returns the value of attribute agentid.
15 16 17 |
# File 'lib/wechat/responder.rb', line 15 def agentid @agentid end |
#corpid ⇒ Object
Returns the value of attribute corpid.
15 16 17 |
# File 'lib/wechat/responder.rb', line 15 def corpid @corpid end |
#encoding_aes_key ⇒ Object
Returns the value of attribute encoding_aes_key.
15 16 17 |
# File 'lib/wechat/responder.rb', line 15 def encoding_aes_key @encoding_aes_key end |
#encrypt_mode ⇒ Object
Returns the value of attribute encrypt_mode.
15 16 17 |
# File 'lib/wechat/responder.rb', line 15 def encrypt_mode @encrypt_mode end |
#skip_verify_ssl ⇒ Object
Returns the value of attribute skip_verify_ssl.
15 16 17 |
# File 'lib/wechat/responder.rb', line 15 def skip_verify_ssl @skip_verify_ssl end |
#token ⇒ Object
Returns the value of attribute token.
15 16 17 |
# File 'lib/wechat/responder.rb', line 15 def token @token end |
#wechat ⇒ Object
Returns the value of attribute wechat.
15 16 17 |
# File 'lib/wechat/responder.rb', line 15 def wechat @wechat end |
Instance Method Details
#on(message_type, with: nil, respond: nil, &block) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/wechat/responder.rb', line 17 def on(, with: nil, respond: nil, &block) fail 'Unknow message type' unless [:text, :image, :voice, :video, :location, :link, :event, :fallback].include?() config = respond.nil? ? {} : { respond: respond } config.merge!(proc: block) if block_given? if with.present? && ![:text, :event].include?() fail 'Only text and event message can take :with parameters' else config.merge!(with: with) if with.present? end user_defined_responders() << config config end |
#responder_for(message) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/wechat/responder.rb', line 37 def responder_for() = [:MsgType].to_sym responders = user_defined_responders() case when :text yield(* match_responders(responders, [:Content])) when :event if 'click' == [:Event] yield(* match_responders(responders, [:EventKey])) elsif %w(scancode_push scancode_waitmsg).include? [:Event] yield(* match_responders(responders, event: 'scancode', event_key: [:EventKey], scan_type: [:ScanCodeInfo][:ScanType], scan_result: [:ScanCodeInfo][:ScanResult])) elsif 'batch_job_result' == [:Event] yield(* match_responders(responders, event: 'batch_job', batch_job: [:BatchJob])) else yield(* match_responders(responders, [:Event])) end else yield(responders.first) end end |
#user_defined_responders(type) ⇒ Object
32 33 34 35 |
# File 'lib/wechat/responder.rb', line 32 def user_defined_responders(type) @responders ||= {} @responders[type] ||= [] end |