Class: Moip::Assinaturas::Webhooks
- Inherits:
-
Object
- Object
- Moip::Assinaturas::Webhooks
- Defined in:
- lib/moip-assinaturas/webhooks.rb
Instance Attribute Summary collapse
-
#date ⇒ Object
Returns the value of attribute date.
-
#env ⇒ Object
Returns the value of attribute env.
-
#event ⇒ Object
Returns the value of attribute event.
-
#events ⇒ Object
Returns the value of attribute events.
-
#model ⇒ Object
Returns the value of attribute model.
-
#resource ⇒ Object
Returns the value of attribute resource.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#date ⇒ Object
Returns the value of attribute date.
3 4 5 |
# File 'lib/moip-assinaturas/webhooks.rb', line 3 def date @date end |
#env ⇒ Object
Returns the value of attribute env.
3 4 5 |
# File 'lib/moip-assinaturas/webhooks.rb', line 3 def env @env end |
#event ⇒ Object
Returns the value of attribute event.
3 4 5 |
# File 'lib/moip-assinaturas/webhooks.rb', line 3 def event @event end |
#events ⇒ Object
Returns the value of attribute events.
3 4 5 |
# File 'lib/moip-assinaturas/webhooks.rb', line 3 def events @events end |
#model ⇒ Object
Returns the value of attribute model.
3 4 5 |
# File 'lib/moip-assinaturas/webhooks.rb', line 3 def model @model end |
#resource ⇒ Object
Returns the value of attribute resource.
3 4 5 |
# File 'lib/moip-assinaturas/webhooks.rb', line 3 def resource @resource end |
Class Method Details
.build(json) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/moip-assinaturas/webhooks.rb', line 6 def build(json) object = new object.model = get_model(json['event']) object.event = get_event(json['event']) object.events = {} object.date = json['date'] object.env = json['env'] object.resource = json['resource'] object end |
.listen(params) {|hook| ... } ⇒ Object
18 19 20 21 22 |
# File 'lib/moip-assinaturas/webhooks.rb', line 18 def listen(params, &block) hook = build(params) yield hook hook.run end |
Instance Method Details
#missing(&block) ⇒ Object
48 49 50 |
# File 'lib/moip-assinaturas/webhooks.rb', line 48 def missing(&block) events[:missing] = block end |
#on(model, on_events, &block) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/moip-assinaturas/webhooks.rb', line 34 def on(model, on_events, &block) unless events[model] events[model] = {} end (on_events.is_a?(Array) ? on_events : [on_events]).each do |event| unless events[model][event] events[model][event] = [] end events[model][event] = block end end |
#run ⇒ Object
52 53 54 55 |
# File 'lib/moip-assinaturas/webhooks.rb', line 52 def run return events[model][event].call(event) if (events[model] && events[model][event]) events[:missing].call(model, event) if events[:missing] end |