lib/chargify/product.rb in jsmestad-chargify-0.3.0.pre5 vs lib/chargify/product.rb in jsmestad-chargify-0.3.0.pre6
- old
+ new
@@ -6,17 +6,29 @@
def all
result = api_request(:get, "/products.json")
result.map{|p| Hashie::Mash.new p['product']}
end
- def find(id)
+ def find!(id)
return all if id == :all
result = api_request(:get, "/products/#{id}.json")
Hashie::Mash.new(result).product
end
-
+
+ def find(id)
+ find!(id)
+ rescue Chargify::Error::Base => e
+ return nil
+ end
+
def find_by_handle(handle)
+ find_by_handle!(handle)
+ rescue Chargify::Error::Base => e
+ return nil
+ end
+
+ def find_by_handle!(handle)
result = api_request(:get, "/products/handle/#{handle}.json")
Hashie::Mash.new(result).product
end
end