Class: Amigo::Event
- Inherits:
-
Object
- Object
- Amigo::Event
- Defined in:
- lib/amigo.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
Class Method Summary collapse
Instance Method Summary collapse
- #as_json(_opts = {}) ⇒ Object
-
#initialize(id, name, payload) ⇒ Event
constructor
A new instance of Event.
- #inspect ⇒ Object
- #to_json(opts = {}) ⇒ Object
Constructor Details
#initialize(id, name, payload) ⇒ Event
Returns a new instance of Event.
273 274 275 276 277 |
# File 'lib/amigo.rb', line 273 def initialize(id, name, payload) @id = id @name = name @payload = payload.map { |p| self.safe_stringify(p) } end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
271 272 273 |
# File 'lib/amigo.rb', line 271 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
271 272 273 |
# File 'lib/amigo.rb', line 271 def name @name end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
271 272 273 |
# File 'lib/amigo.rb', line 271 def payload @payload end |
Class Method Details
.create(topic, payload) ⇒ Webhookdb::Event
262 263 264 |
# File 'lib/amigo.rb', line 262 def self.create(topic, payload) return self.new(SecureRandom.uuid, topic, payload) end |
.from_json(o) ⇒ Webhookdb::Event
267 268 269 |
# File 'lib/amigo.rb', line 267 def self.from_json(o) return self.new(o["id"], o["name"], o["payload"]) end |
Instance Method Details
#as_json(_opts = {}) ⇒ Object
289 290 291 292 293 294 295 |
# File 'lib/amigo.rb', line 289 def as_json(_opts={}) return { "id" => self.id, "name" => self.name, "payload" => self.payload, } end |
#inspect ⇒ Object
279 280 281 282 283 284 285 286 287 |
# File 'lib/amigo.rb', line 279 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
297 298 299 |
# File 'lib/amigo.rb', line 297 def to_json(opts={}) return JSON.dump(self.as_json(opts)) end |