Module: SquareEvent

Defined in:
lib/square_event.rb,
lib/square_event/event.rb,
lib/square_event/engine.rb,
lib/square_event/errors.rb,
lib/square_event/version.rb,
lib/square_event/webhook.rb,
app/controllers/square_event/webhook_controller.rb

Defined Under Namespace

Classes: Engine, Error, Event, Namespace, NotificationAdapter, SignatureVerificationError, SquareEventError, UnauthorizedError, Webhook, WebhookController

Constant Summary collapse

VERSION =
"1.0.2"

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.adapterObject

Returns the value of attribute adapter.



8
9
10
# File 'lib/square_event.rb', line 8

def adapter
  @adapter
end

.backendObject

Returns the value of attribute backend.



8
9
10
# File 'lib/square_event.rb', line 8

def backend
  @backend
end

.event_filterObject

Returns the value of attribute event_filter.



8
9
10
# File 'lib/square_event.rb', line 8

def event_filter
  @event_filter
end

.namespaceObject

Returns the value of attribute namespace.



8
9
10
# File 'lib/square_event.rb', line 8

def namespace
  @namespace
end

.notification_urlObject

Returns the value of attribute notification_url.



8
9
10
# File 'lib/square_event.rb', line 8

def notification_url
  @notification_url
end

.signing_secretObject

Returns the value of attribute signing_secret.



8
9
10
# File 'lib/square_event.rb', line 8

def signing_secret
  @signing_secret
end

Class Method Details

.all(callable = nil, &block) ⇒ Object



26
27
28
29
# File 'lib/square_event.rb', line 26

def all(callable = nil, &block)
  callable ||= block
  subscribe nil, callable
end

.configure(&block) ⇒ Object Also known as: setup

Raises:

  • (ArgumentError)


10
11
12
13
# File 'lib/square_event.rb', line 10

def configure(&block)
  raise ArgumentError, "must provide a block" unless block_given?
  block.arity.zero? ? instance_eval(&block) : yield(self)
end

.instrument(event) ⇒ Object



16
17
18
19
# File 'lib/square_event.rb', line 16

def instrument(event)
  event = event_filter.call(event)
  backend.instrument namespace.call(event.type), event if event
end

.listening?(name) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
# File 'lib/square_event.rb', line 31

def listening?(name)
  namespaced_name = namespace.call(name)
  backend.notifier.listening?(namespaced_name)
end

.subscribe(name, callable = nil, &block) ⇒ Object



21
22
23
24
# File 'lib/square_event.rb', line 21

def subscribe(name, callable = nil, &block)
  callable ||= block
  backend.subscribe namespace.to_regexp(name), adapter.call(callable)
end

Instance Method Details

#[]=(key, value) ⇒ Object



66
67
# File 'lib/square_event.rb', line 66

def []=(key, value) 
end