Class: Amigo::Event

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, name, payload) ⇒ Event

Returns a new instance of Event.



262
263
264
265
266
# File 'lib/amigo.rb', line 262

def initialize(id, name, payload)
  @id = id
  @name = name
  @payload = payload.map { |p| self.safe_stringify(p) }
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



260
261
262
# File 'lib/amigo.rb', line 260

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



260
261
262
# File 'lib/amigo.rb', line 260

def name
  @name
end

#payloadObject (readonly)

Returns the value of attribute payload.



260
261
262
# File 'lib/amigo.rb', line 260

def payload
  @payload
end

Class Method Details

.create(topic, payload) ⇒ Webhookdb::Event

Parameters:

  • topic (String)
  • payload (Array)

Returns:

  • (Webhookdb::Event)


251
252
253
# File 'lib/amigo.rb', line 251

def self.create(topic, payload)
  return self.new(SecureRandom.uuid, topic, payload)
end

.from_json(o) ⇒ Webhookdb::Event

Returns:

  • (Webhookdb::Event)


256
257
258
# File 'lib/amigo.rb', line 256

def self.from_json(o)
  return self.new(o["id"], o["name"], o["payload"])
end

Instance Method Details

#as_json(_opts = {}) ⇒ Object



278
279
280
281
282
283
284
# File 'lib/amigo.rb', line 278

def as_json(_opts={})
  return {
    "id" => self.id,
    "name" => self.name,
    "payload" => self.payload,
  }
end

#inspectObject



268
269
270
271
272
273
274
275
276
# File 'lib/amigo.rb', line 268

def inspect
  return "#<%p:%#0x [%s] %s %p>" % [
    self.class,
    self.object_id * 2,
    self.id,
    self.name,
    self.payload,
  ]
end

#to_json(opts = {}) ⇒ Object



286
287
288
# File 'lib/amigo.rb', line 286

def to_json(opts={})
  return JSON.dump(self.as_json(opts))
end