Module: EasyPost::Hooks

Defined in:
lib/easypost/hooks.rb

Defined Under Namespace

Classes: RequestContext, ResponseContext

Class Method Summary collapse

Class Method Details

.any_subscribers?(type) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/easypost/hooks.rb', line 22

def self.any_subscribers?(type)
  !subscribers[type].empty?
end

.notify(type, context) ⇒ Object



18
19
20
# File 'lib/easypost/hooks.rb', line 18

def self.notify(type, context)
  subscribers[type].each_value { |subscriber| subscriber.call(context) }
end

.subscribe(type, name, block) ⇒ Object



4
5
6
7
8
# File 'lib/easypost/hooks.rb', line 4

def self.subscribe(type, name, block)
  subscribers[type][name] = block

  name
end

.unsubscribe(type, name) ⇒ Object



10
11
12
# File 'lib/easypost/hooks.rb', line 10

def self.unsubscribe(type, name)
  subscribers[type].delete(name)
end

.unsubscribe_all(type) ⇒ Object



14
15
16
# File 'lib/easypost/hooks.rb', line 14

def self.unsubscribe_all(type)
  subscribers.delete(type)
end