Module: Wechat::Responder::ClassMethods
- Defined in:
- lib/wechat/responder.rb
Instance Attribute Summary collapse
-
#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, &block) ⇒ Object
- #responders(type) ⇒ Object
Instance Attribute Details
#token ⇒ Object
Returns the value of attribute token.
13 14 15 |
# File 'lib/wechat/responder.rb', line 13 def token @token end |
#wechat ⇒ Object
Returns the value of attribute wechat.
13 14 15 |
# File 'lib/wechat/responder.rb', line 13 def wechat @wechat end |
Instance Method Details
#on(message_type, with: nil, respond: nil, &block) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/wechat/responder.rb', line 15 def on , with: nil, respond: nil, &block raise "Unknow message type" unless .in? [:text, :image, :voice, :video, :location, :link, :event, :fallback] config=respond.nil? ? {} : {:respond=>respond} config.merge!(:proc=>block) if block_given? if (with.present? && !.in?([:text, :event])) raise "Only text and event message can take :with parameters" else config.merge!(:with=>with) if with.present? end responders() << config return config end |
#responder_for(message, &block) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/wechat/responder.rb', line 35 def responder_for , &block = [:MsgType].to_sym responders = responders() case when :text yield(* match_responders(responders, [:Content])) when :event yield(* match_responders(responders, [:Event])) else yield(responders.first) end end |
#responders(type) ⇒ Object
30 31 32 33 |
# File 'lib/wechat/responder.rb', line 30 def responders type @responders ||= Hash.new @responders[type] ||= Array.new end |