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.
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
#id ⇒ Object (readonly)
Returns the value of attribute id.
260 261 262 |
# File 'lib/amigo.rb', line 260 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
260 261 262 |
# File 'lib/amigo.rb', line 260 def name @name end |
#payload ⇒ Object (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
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
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 |
#inspect ⇒ Object
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 |