diff --git a/lib/shopify_api/countable.rb b/lib/shopify_api/countable.rb index d5408c9b4..fbebbf6da 100644 --- a/lib/shopify_api/countable.rb +++ b/lib/shopify_api/countable.rb @@ -1,7 +1,14 @@ module ShopifyAPI module Countable def count(options = {}) - Integer(get(:count, options)) + data = get(:count, options) + + count = case data + when Hash then data["count"] + else data + end + + Integer(count) end end end diff --git a/test/countable_test.rb b/test/countable_test.rb new file mode 100644 index 000000000..545d6767b --- /dev/null +++ b/test/countable_test.rb @@ -0,0 +1,12 @@ +require 'test_helper' + +class CountableTest < Test::Unit::TestCase + def setup + fake "products/count", :body => '{"count": 16}' + end + + def test_count_products + count = ShopifyAPI::Product.count + assert_equal 16, count + end +end