Module: VcrStripeWebhook

Defined in:
lib/vcr_stripe_webhook.rb,
lib/vcr_stripe_webhook/error.rb,
lib/vcr_stripe_webhook/event.rb,
lib/vcr_stripe_webhook/server.rb,
lib/vcr_stripe_webhook/waiter.rb,
lib/vcr_stripe_webhook/version.rb,
lib/vcr_stripe_webhook/stripe_cli.rb,
lib/vcr_stripe_webhook/configuration.rb,
lib/vcr_stripe_webhook/event_cassette.rb,
lib/vcr_stripe_webhook/event_receiver.rb

Defined Under Namespace

Classes: CassetteDataError, Configuration, Error, Event, EventCassette, EventReceiver, EventTypeWaiter, EventWaitTimeout, ProcWaiter, Server, StripeCLI

Constant Summary collapse

VERSION =
"0.3.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.current_event_cassetteObject (readonly)

Returns the value of attribute current_event_cassette.



13
14
15
# File 'lib/vcr_stripe_webhook.rb', line 13

def current_event_cassette
  @current_event_cassette
end

.loggerObject



24
25
26
# File 'lib/vcr_stripe_webhook.rb', line 24

def logger
  @logger ||= Logger.new("log/vcr_stripe_webhook.log")
end

.serverObject (readonly)

Returns the value of attribute server.



13
14
15
# File 'lib/vcr_stripe_webhook.rb', line 13

def server
  @server
end

Class Method Details

.configurationObject



20
21
22
# File 'lib/vcr_stripe_webhook.rb', line 20

def configuration
  @configuration ||= VcrStripeWebhook::Configuration.new
end

.receive_webhook_event(event_type, timeout: configuration.timeout, &block) ⇒ Object



51
52
53
54
# File 'lib/vcr_stripe_webhook.rb', line 51

def receive_webhook_event(event_type, timeout: configuration.timeout, &block)
  events = receive_webhook_events(event_types: [event_type], timeout: timeout, &block)
  events.find { |event| event.type == event_type }
end

.receive_webhook_events(event_types: nil, wait_until: nil, timeout: configuration.timeout, &block) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/vcr_stripe_webhook.rb', line 38

def receive_webhook_events(event_types: nil, wait_until: nil, timeout: configuration.timeout, &block)
  raise "No event cassette inserted." if current_event_cassette.nil?
  raise "event_types or wait_until must be passed as an argument." if event_types.nil? && wait_until.nil?

  waiter =
    if event_types
      EventTypeWaiter.new(event_types)
    else
      ProcWaiter.new(wait_until)
    end
  current_event_cassette.wait_for_events(waiter, timeout: timeout, &block)
end

.stopObject



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

def stop
  EventReceiver.terminate
end

.use_cassette(name, options = {}, &block) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/vcr_stripe_webhook.rb', line 28

def use_cassette(name, options = {}, &block)
  VCR.use_cassette(name, options) do |vcr_cassette|
    @current_event_cassette = EventCassette.new(name, vcr_cassette, vcr_cassette.recording?)
    EventReceiver.instance.use_cassette(@current_event_cassette, &block)
    @current_event_cassette.serialize if @current_event_cassette.recording?
  ensure
    @current_event_cassette = nil
  end
end