Class: Moip::Webhooks
- Inherits:
-
Object
- Object
- Moip::Webhooks
- Defined in:
- lib/moip/webhooks.rb
Overview
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.
-
#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.
4 5 6 |
# File 'lib/moip/webhooks.rb', line 4 def date @date end |
#env ⇒ Object
Returns the value of attribute env.
4 5 6 |
# File 'lib/moip/webhooks.rb', line 4 def env @env end |
#event ⇒ Object
Returns the value of attribute event.
4 5 6 |
# File 'lib/moip/webhooks.rb', line 4 def event @event end |
#resource ⇒ Object
Returns the value of attribute resource.
4 5 6 |
# File 'lib/moip/webhooks.rb', line 4 def resource @resource end |
Class Method Details
.build(params) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/moip/webhooks.rb', line 40 def build params object = new params.each do |key, value| object.send("#{key}=".to_sym, value) if object.respond_to? key.to_sym end object end |
.listen(json) {|hook| ... } ⇒ Object
50 51 52 53 54 |
# File 'lib/moip/webhooks.rb', line 50 def listen(json, &block) hook = build json yield hook hook.run end |
Instance Method Details
#events ⇒ Object
6 7 8 |
# File 'lib/moip/webhooks.rb', line 6 def events @events ||= [] end |
#on(event, kind, &block) ⇒ Object
10 11 12 13 14 |
# File 'lib/moip/webhooks.rb', line 10 def on event, kind, &block hash = {} hash[event] = { :kind => kind, :runnable => block } self.events << hash end |
#run ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/moip/webhooks.rb', line 16 def run event = self.event.split(".")[0] kind = self.event.split(".")[1] action = nil self.events.each do |hash| e_sym = event.to_sym if hash.has_key? e_sym if hash[e_sym][:kind].to_s == kind action = hash[e_sym][:runnable] end end end action.call if action.is_a? Proc end |