Class: MosEisley::S3PO::Action
- Inherits:
-
Object
- Object
- MosEisley::S3PO::Action
- Defined in:
- lib/s3po/action.rb
Instance Attribute Summary collapse
-
#event ⇒ Object
readonly
Returns the value of attribute event.
-
#original_message ⇒ Object
readonly
Returns the value of attribute original_message.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #action ⇒ Object
- #action_ts ⇒ Object
- #action_value ⇒ Object
- #attachment_id ⇒ Object
- #callback_id ⇒ Object
- #channel ⇒ Object
-
#initialize(e) ⇒ Action
constructor
A new instance of Action.
- #message_age ⇒ Object
- #message_ts ⇒ Object
- #original_event ⇒ Object
- #response_url ⇒ Object
- #submission ⇒ Object
- #trigger_id ⇒ Object
- #user ⇒ Object
Constructor Details
Instance Attribute Details
#event ⇒ Object (readonly)
Returns the value of attribute event.
4 5 6 |
# File 'lib/s3po/action.rb', line 4 def event @event end |
#original_message ⇒ Object (readonly)
Returns the value of attribute original_message.
4 5 6 |
# File 'lib/s3po/action.rb', line 4 def @original_message end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
4 5 6 |
# File 'lib/s3po/action.rb', line 4 def type @type end |
Class Method Details
.add_pending(act) ⇒ Object
6 7 8 9 10 |
# File 'lib/s3po/action.rb', line 6 def self.add_pending(act) pending_gc @pending ||= {} @pending[act.callback_id] = act end |
.pending ⇒ Object
12 13 14 15 |
# File 'lib/s3po/action.rb', line 12 def self.pending pending_gc @pending end |
.pending_gc ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/s3po/action.rb', line 17 def self.pending_gc return unless @pending return if @gc_running @gc_running = true delkeys = [] @pending.each do |id, act| ts = Time.at(act.action_ts.to_f) delkeys << id if Time.now - ts > 60 * 30 end delkeys.each { |k| @pending.delete(k) } @gc_running = false end |
Instance Method Details
#action ⇒ Object
38 39 40 |
# File 'lib/s3po/action.rb', line 38 def action event[:actions][0] end |
#action_ts ⇒ Object
69 70 71 |
# File 'lib/s3po/action.rb', line 69 def action_ts event[:action_ts] end |
#action_value ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/s3po/action.rb', line 42 def action_value v = nil case action[:type].to_sym when :button v = action[:value] when :select v = action[:selected_options][0][:value] end return v end |
#attachment_id ⇒ Object
73 74 75 |
# File 'lib/s3po/action.rb', line 73 def event[:attachment_id].to_i end |
#callback_id ⇒ Object
53 54 55 |
# File 'lib/s3po/action.rb', line 53 def callback_id event[:callback_id] end |
#channel ⇒ Object
57 58 59 |
# File 'lib/s3po/action.rb', line 57 def channel event[:channel][:id] end |
#message_age ⇒ Object
93 94 95 |
# File 'lib/s3po/action.rb', line 93 def Time.now.to_i - .to_i end |
#message_ts ⇒ Object
65 66 67 |
# File 'lib/s3po/action.rb', line 65 def event[:message_ts] end |
#original_event ⇒ Object
89 90 91 |
# File 'lib/s3po/action.rb', line 89 def original_event Action.pending[callback_id] end |
#response_url ⇒ Object
77 78 79 |
# File 'lib/s3po/action.rb', line 77 def response_url event[:response_url] end |
#submission ⇒ Object
85 86 87 |
# File 'lib/s3po/action.rb', line 85 def submission event[:submission] end |
#trigger_id ⇒ Object
81 82 83 |
# File 'lib/s3po/action.rb', line 81 def trigger_id event[:trigger_id] end |
#user ⇒ Object
61 62 63 |
# File 'lib/s3po/action.rb', line 61 def user event[:user][:id] end |