Module: StripeMock::RequestHandlers::Plans

Included in:
Instance
Defined in:
lib/stripe_mock/request_handlers/plans.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/stripe_mock/request_handlers/plans.rb', line 5

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

Instance Method Details

#delete_plan(route, method_url, params, headers) ⇒ Object



30
31
32
33
# File 'lib/stripe_mock/request_handlers/plans.rb', line 30

def delete_plan(route, method_url, params, headers)
  route =~ method_url
  assert_existence :plan, $1, plans.delete($1)
end

#get_plan(route, method_url, params, headers) ⇒ Object



25
26
27
28
# File 'lib/stripe_mock/request_handlers/plans.rb', line 25

def get_plan(route, method_url, params, headers)
  route =~ method_url
  assert_existence :plan, $1, plans[$1]
end

#list_plans(route, method_url, params, headers) ⇒ Object



35
36
37
38
# File 'lib/stripe_mock/request_handlers/plans.rb', line 35

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

#new_plan(route, method_url, params, headers) ⇒ Object



13
14
15
16
17
# File 'lib/stripe_mock/request_handlers/plans.rb', line 13

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

#update_plan(route, method_url, params, headers) ⇒ Object



19
20
21
22
23
# File 'lib/stripe_mock/request_handlers/plans.rb', line 19

def update_plan(route, method_url, params, headers)
  route =~ method_url
  assert_existence :plan, $1, plans[$1]
  plans[$1].merge!(params)
end