Class: StripeMock::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/stripe_mock/server.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeServer

Returns a new instance of Server.



15
16
17
# File 'lib/stripe_mock/server.rb', line 15

def initialize
  self.clear_data
end

Class Method Details

.start_new(opts) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/stripe_mock/server.rb', line 5

def self.start_new(opts)
  puts "Starting StripeMock server on port #{opts[:port] || 4999}"

  host = opts.fetch :host,'0.0.0.0'
  port = opts.fetch :port, 4999

  DRb.start_service "druby://#{host}:#{port}", Server.new
  DRb.thread.join
end

Instance Method Details

#clear_dataObject



40
41
42
# File 'lib/stripe_mock/server.rb', line 40

def clear_data
  @instance = Instance.new
end

#debug?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/stripe_mock/server.rb', line 80

def debug?
  @instance.debug
end

#destroy_resource(type, id) ⇒ Object



36
37
38
# File 'lib/stripe_mock/server.rb', line 36

def destroy_resource(type, id)
  @instance.send(type).delete(id)
end

#error_queueObject



76
77
78
# File 'lib/stripe_mock/server.rb', line 76

def error_queue
  @instance.error_queue
end

#generate_bank_token(recipient_params) ⇒ Object



60
61
62
# File 'lib/stripe_mock/server.rb', line 60

def generate_bank_token(recipient_params)
  @instance.generate_bank_token(recipient_params)
end

#generate_card_token(card_params) ⇒ Object



56
57
58
# File 'lib/stripe_mock/server.rb', line 56

def generate_card_token(card_params)
  @instance.generate_card_token(card_params)
end

#generate_webhook_event(event_data) ⇒ Object



64
65
66
# File 'lib/stripe_mock/server.rb', line 64

def generate_webhook_event(event_data)
  @instance.generate_webhook_event(event_data)
end

#get_data(key) ⇒ Object



32
33
34
# File 'lib/stripe_mock/server.rb', line 32

def get_data(key)
  @instance.send(key)
end

#global_id_prefixObject



52
53
54
# File 'lib/stripe_mock/server.rb', line 52

def global_id_prefix
  StripeMock.global_id_prefix
end

#mock_request(*args, **kwargs) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/stripe_mock/server.rb', line 19

def mock_request(*args, **kwargs)
  begin
    @instance.mock_request(*args, **kwargs)
  rescue Stripe::InvalidRequestError => e
    {
      :error_raised => 'invalid_request',
      :error_params => [
        e.message, e.param, { http_status: e.http_status, http_body: e.http_body, json_body: e.json_body}
      ]
    }
  end
end

#pingObject



84
85
86
# File 'lib/stripe_mock/server.rb', line 84

def ping
  true
end

#set_account_balance(value) ⇒ Object



72
73
74
# File 'lib/stripe_mock/server.rb', line 72

def (value)
  @instance. = value
end

#set_conversion_rate(value) ⇒ Object



68
69
70
# File 'lib/stripe_mock/server.rb', line 68

def set_conversion_rate(value)
  @instance.conversion_rate = value
end

#set_debug(toggle) ⇒ Object



44
45
46
# File 'lib/stripe_mock/server.rb', line 44

def set_debug(toggle)
  @instance.debug = toggle
end

#set_global_id_prefix(value) ⇒ Object



48
49
50
# File 'lib/stripe_mock/server.rb', line 48

def set_global_id_prefix(value)
  StripeMock.global_id_prefix = value
end

#upsert_stripe_object(object, attributes) ⇒ Object



88
89
90
# File 'lib/stripe_mock/server.rb', line 88

def upsert_stripe_object(object, attributes)
  @instance.upsert_stripe_object(object, attributes)
end