Module: StripeMock::RequestHandlers::Prices
- Included in:
- Instance
- Defined in:
- lib/stripe_mock/request_handlers/prices.rb
Class Method Summary collapse
Instance Method Summary collapse
- #get_price(route, method_url, params, headers) ⇒ Object
- #list_prices(route, method_url, params, headers) ⇒ Object
- #new_price(route, method_url, params, headers) ⇒ Object
- #update_price(route, method_url, params, headers) ⇒ Object
Class Method Details
.included(klass) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/stripe_mock/request_handlers/prices.rb', line 5 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 |
Instance Method Details
#get_price(route, method_url, params, headers) ⇒ Object
30 31 32 33 |
# File 'lib/stripe_mock/request_handlers/prices.rb', line 30 def get_price(route, method_url, params, headers) route =~ method_url assert_existence :price, $1, prices[$1] end |
#list_prices(route, method_url, params, headers) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/stripe_mock/request_handlers/prices.rb', line 35 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 if params.key?(:currency) price_data.select! do |price| params[:currency] == price[:currency] end end if params.key?(:product) price_data.select! do |price| params[:product] == price[:product] end end Data.mock_list_object(price_data.first(limit), params.merge!(limit: limit)) end |
#new_price(route, method_url, params, headers) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/stripe_mock/request_handlers/prices.rb', line 12 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 |
#update_price(route, method_url, params, headers) ⇒ Object
24 25 26 27 28 |
# File 'lib/stripe_mock/request_handlers/prices.rb', line 24 def update_price(route, method_url, params, headers) route =~ method_url assert_existence :price, $1, prices[$1] prices[$1].merge!(params) end |