forked from stripe-ruby-mock/stripe-ruby-mock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prices.rb
50 lines (41 loc) · 1.52 KB
/
prices.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
module StripeMock
module RequestHandlers
module Prices
def Prices.included(klass)
klass.add_handler 'post /v1/prices', :new_price
klass.add_handler 'post /v1/prices/(.*)', :update_price
klass.add_handler 'get /v1/prices/(.*)', :get_price
klass.add_handler 'get /v1/prices', :list_prices
end
def new_price(route, method_url, params, headers)
params[:id] ||= new_id('price')
if params[:product_data]
params[:product] = create_product(nil, nil, params[:product_data], nil)[:id] unless params[:product]
params.delete(:product_data)
end
validate_create_price_params(params)
prices[ params[:id] ] = Data.mock_price(params)
end
def update_price(route, method_url, params, headers)
route =~ method_url
assert_existence :price, $1, prices[$1]
prices[$1].merge!(params)
end
def get_price(route, method_url, params, headers)
route =~ method_url
assert_existence :price, $1, prices[$1]
end
def list_prices(route, method_url, params, headers)
limit = params[:limit] ? params[:limit] : 10
price_data = prices.values
validate_list_prices_params(params)
if params.key?(:lookup_keys)
price_data.select! do |price|
params[:lookup_keys].include?(price[:lookup_key])
end
end
Data.mock_list_object(price_data.first(limit), params.merge!(limit: limit))
end
end
end
end