Class: MosEisley::S3PO::Action

Inherits:
Object
  • Object
show all
Defined in:
lib/s3po/action.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(e) ⇒ Action

Returns a new instance of Action.



30
31
32
33
34
35
36
# File 'lib/s3po/action.rb', line 30

def initialize(e)
  @event = e
  @type = @event[:type].to_sym
  if e[:original_message]
    @original_message = Message.new(e[:original_message])
  end
end

Instance Attribute Details

#eventObject (readonly)

Returns the value of attribute event.



4
5
6
# File 'lib/s3po/action.rb', line 4

def event
  @event
end

#original_messageObject (readonly)

Returns the value of attribute original_message.



4
5
6
# File 'lib/s3po/action.rb', line 4

def original_message
  @original_message
end

#typeObject (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

.pendingObject



12
13
14
15
# File 'lib/s3po/action.rb', line 12

def self.pending
  pending_gc
  @pending
end

.pending_gcObject



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

#actionObject



38
39
40
# File 'lib/s3po/action.rb', line 38

def action
  event[:actions][0]
end

#action_tsObject



69
70
71
# File 'lib/s3po/action.rb', line 69

def action_ts
  event[:action_ts]
end

#action_valueObject



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_idObject



73
74
75
# File 'lib/s3po/action.rb', line 73

def attachment_id
  event[:attachment_id].to_i
end

#callback_idObject



53
54
55
# File 'lib/s3po/action.rb', line 53

def callback_id
  event[:callback_id]
end

#channelObject



57
58
59
# File 'lib/s3po/action.rb', line 57

def channel
  event[:channel][:id]
end

#message_ageObject



93
94
95
# File 'lib/s3po/action.rb', line 93

def message_age
  Time.now.to_i - message_ts.to_i
end

#message_tsObject



65
66
67
# File 'lib/s3po/action.rb', line 65

def message_ts
  event[:message_ts]
end

#original_eventObject



89
90
91
# File 'lib/s3po/action.rb', line 89

def original_event
  Action.pending[callback_id]
end

#response_urlObject



77
78
79
# File 'lib/s3po/action.rb', line 77

def response_url
  event[:response_url]
end

#submissionObject



85
86
87
# File 'lib/s3po/action.rb', line 85

def submission
  event[:submission]
end

#trigger_idObject



81
82
83
# File 'lib/s3po/action.rb', line 81

def trigger_id
  event[:trigger_id]
end

#userObject



61
62
63
# File 'lib/s3po/action.rb', line 61

def user
  event[:user][:id]
end