forked from stripe-ruby-mock/stripe-ruby-mock
-
Notifications
You must be signed in to change notification settings - Fork 6
/
plans.rb
42 lines (35 loc) · 1.28 KB
/
plans.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
module StripeMock
module RequestHandlers
module Plans
def Plans.included(klass)
klass.add_handler 'post /v1/plans', :new_plan
klass.add_handler 'post /v1/plans/(.*)', :update_plan
klass.add_handler 'get /v1/plans/(.*)', :get_plan
klass.add_handler 'delete /v1/plans/(.*)', :delete_plan
klass.add_handler 'get /v1/plans', :list_plans
end
def new_plan(route, method_url, params, headers)
params[:id] ||= new_id('plan')
validate_create_plan_params(params)
plans[ params[:id] ] = Data.mock_plan(params)
end
def update_plan(route, method_url, params, headers)
route =~ method_url
assert_existence :plan, $1, plans[$1]
plans[$1].merge!(params)
end
def get_plan(route, method_url, params, headers)
route =~ method_url
assert_existence :plan, $1, plans[$1]
end
def delete_plan(route, method_url, params, headers)
route =~ method_url
assert_existence :plan, $1, plans.delete($1)
end
def list_plans(route, method_url, params, headers)
limit = params[:limit] ? params[:limit] : 10
Data.mock_list_object(plans.values.first(limit), params.merge!(limit: limit))
end
end
end
end