Class: Lita::GoogleActivity

Inherits:
Object
  • Object
show all
Defined in:
lib/lita/google_activity.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(time:, actor:, ip:, name:, params:) ⇒ GoogleActivity

Returns a new instance of GoogleActivity.



20
21
22
23
24
25
26
# File 'lib/lita/google_activity.rb', line 20

def initialize(time:, actor:, ip:, name:, params:)
  @time = time
  @actor = actor
  @ip = ip
  @name = name
  @params = params
end

Instance Attribute Details

#actorObject (readonly)

Returns the value of attribute actor.



3
4
5
# File 'lib/lita/google_activity.rb', line 3

def actor
  @actor
end

#ipObject (readonly)

Returns the value of attribute ip.



3
4
5
# File 'lib/lita/google_activity.rb', line 3

def ip
  @ip
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/lita/google_activity.rb', line 3

def name
  @name
end

#paramsObject (readonly)

Returns the value of attribute params.



3
4
5
# File 'lib/lita/google_activity.rb', line 3

def params
  @params
end

#timeObject (readonly)

Returns the value of attribute time.



3
4
5
# File 'lib/lita/google_activity.rb', line 3

def time
  @time
end

Class Method Details

.from_api(item) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/lita/google_activity.rb', line 5

def self.from_api(item)
  item.events.map { |event|
    GoogleActivity.new(
      time: item.id.time,
      actor: item.actor.email,
      ip: item.ip_address,
      name: event.name,
      params: event.parameters.inject({}) { |accum, param|
        accum[param.name] = param.value
        accum
      }
    )
  }
end

Instance Method Details

#to_msgObject



32
33
34
35
36
37
38
39
# File 'lib/lita/google_activity.rb', line 32

def to_msg
  <<~EOF
    Date: #{@time.httpdate}
    Admin User: #{@actor}
    Action: #{@name.capitalize.gsub('_', ' ')}
    #{values}
  EOF
end

#to_sObject



28
29
30
# File 'lib/lita/google_activity.rb', line 28

def to_s
  @actor
end