Permalink
Browse files

added nested component resource under product families. This appears …

…to be the only way to get pricing information for components
  • Loading branch information...
1 parent 55f1e25 commit bb31f4b144fc11bca7805003fe412cf363965454 @cyoungberg cyoungberg committed Aug 18, 2011
Showing with 43 additions and 0 deletions.
  1. +10 −0 lib/chargify_api_ares.rb
  2. +33 −0 spec/product_families_component_spec.rb
View
@@ -68,6 +68,7 @@ def configure
Subscription::Statement.site = site + "/subscriptions/:subscription_id"
Subscription::Transaction.site = site + "/subscriptions/:subscription_id"
Coupon.site = site + "/product_families/:product_family_id"
+ ProductFamily::Component.site = site + "/product_families/:product_family_id"
end
end
@@ -247,6 +248,15 @@ class ProductFamily < Base
def self.find_by_handle(handle, attributes = {})
ProductFamily.find(:one, :from => :lookup, :handle => handle)
end
+
+ class Component < Base
+ end
+
+ def components(params = {})
+ params.merge!({:product_family_id => self.id})
+ ::Chargify::ProductFamily::Component.find(:all, :params => params)
+ end
+
end
class Usage < Base
@@ -0,0 +1,33 @@
+require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
+
+describe Chargify::Subscription::Component do
+ before(:each) do
+ @product_family = Chargify::ProductFamily.new(:id => 1)
+ @component = Chargify::ProductFamily::Component.new(
+ :id => 2,
+ :name => "Purple Widgets",
+ :pricing_scheme => "per_unit",
+ :product_family_id => 1,
+ :unit_name => "purple widget",
+ :unit_price => 2.99,
+ :kind => "quantity_based_component",
+ :prices => []
+ )
+
+ @product_family_components = [ @component ]
+
+ end
+
+ describe "listing subscription components" do
+ before(:each) do
+ FakeWeb.register_uri(:get, "#{test_domain}/product_families/#{@product_family.id}.xml", :body => @product_family.to_xml)
+ FakeWeb.register_uri(:get, "#{test_domain}/product_families/#{@product_family.id}/components.xml", :body => @product_family_components.to_xml(:root => 'components'))
+ end
+
+ it "returns an array of components from Chargify::ProductFamily.find(1).components" do
+ product_family = Chargify::ProductFamily.find(@product_family.id)
+ product_family.components.should == @product_family_components
+ end
+
+ end
+end

0 comments on commit bb31f4b

Please sign in to comment.