Module: StripeMock::RequestHandlers::SubscriptionItems

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



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

def SubscriptionItems.included(klass)
  klass.add_handler 'get /v1/subscription_items', :retrieve_subscription_items
  klass.add_handler 'post /v1/subscription_items/([^/]*)', :update_subscription_item
  klass.add_handler 'post /v1/subscription_items', :create_subscription_items
end

Instance Method Details

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



19
20
21
22
23
24
25
26
# File 'lib/stripe_mock/request_handlers/subscription_items.rb', line 19

def create_subscription_items(route, method_url, params, headers)
  params[:id] ||= new_id('si')

  require_param(:subscription) unless params[:subscription]
  require_param(:plan) unless params[:plan]

  subscriptions_items[params[:id]] = Data.mock_subscription_item(params.merge(plan: plans[params[:plan]]))
end

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



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

def retrieve_subscription_items(route, method_url, params, headers)
  route =~ method_url

  require_param(:subscription) unless params[:subscription]

  Data.mock_list_object(subscriptions_items, params)
end

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



28
29
30
31
32
33
# File 'lib/stripe_mock/request_handlers/subscription_items.rb', line 28

def update_subscription_item(route, method_url, params, headers)
  route =~ method_url

  subscription_item = assert_existence :subscription_item, $1, subscriptions_items[$1]
  subscription_item.merge!(params.merge(plan: plans[params[:plan]]))
end