module StripeMock::RequestHandlers::Products
Public Class Methods
included(base)
click to toggle source
# File lib/stripe_mock/request_handlers/products.rb, line 4 def self.included(base) base.add_handler 'post /v1/products', :create_product base.add_handler 'get /v1/products/(.*)', :retrieve_product base.add_handler 'post /v1/products/(.*)', :update_product base.add_handler 'get /v1/products', :list_products base.add_handler 'delete /v1/products/(.*)', :destroy_product end
Public Instance Methods
create_product(_route, _method_url, params, _headers)
click to toggle source
# File lib/stripe_mock/request_handlers/products.rb, line 12 def create_product(_route, _method_url, params, _headers) params[:id] ||= new_id('prod') validate_create_product_params(params) products[params[:id]] = Data.mock_product(params) end
destroy_product(route, method_url, _params, _headers)
click to toggle source
# File lib/stripe_mock/request_handlers/products.rb, line 35 def destroy_product(route, method_url, _params, _headers) id = method_url.match(route).captures.first assert_existence :product, id, products[id] products.delete(id) { id: id, object: 'product', deleted: true } end
list_products(_route, _method_url, params, _headers)
click to toggle source
# File lib/stripe_mock/request_handlers/products.rb, line 30 def list_products(_route, _method_url, params, _headers) limit = params[:limit] || 10 Data.mock_list_object(products.values.take(limit), params) end
retrieve_product(route, method_url, _params, _headers)
click to toggle source
# File lib/stripe_mock/request_handlers/products.rb, line 18 def retrieve_product(route, method_url, _params, _headers) id = method_url.match(route).captures.first assert_existence :product, id, products[id] end
update_product(route, method_url, params, _headers)
click to toggle source
# File lib/stripe_mock/request_handlers/products.rb, line 23 def update_product(route, method_url, params, _headers) id = method_url.match(route).captures.first product = assert_existence :product, id, products[id] product.merge!(params) end