diff --git a/lib/ecwid_api/entity.rb b/lib/ecwid_api/entity.rb index 0378c2b..e38cbd3 100644 --- a/lib/ecwid_api/entity.rb +++ b/lib/ecwid_api/entity.rb @@ -89,8 +89,9 @@ def ecwid_accessor(*attrs) # opts - A Hash of options # :client - The EcwidApi::Client creating the Entity # - def initialize(data, opts={}) - @client, @data = opts[:client], data + def initialize(data, opts = {}) + @client = opts[:client] + @data = data.is_a?(String) ? JSON.parse(data) : data @new_data = {} end diff --git a/spec/api/products_spec.rb b/spec/api/products_spec.rb index 6567e04..48d5fe7 100644 --- a/spec/api/products_spec.rb +++ b/spec/api/products_spec.rb @@ -17,4 +17,10 @@ subject.all.first.sku.should == "NC53090" end end -end \ No newline at end of file + + describe "#find" do + it "finds product by id" do + subject.find(41316136).sku.should == "NC53090" + end + end +end diff --git a/spec/fixtures/product.json b/spec/fixtures/product.json new file mode 100644 index 0000000..b97e467 --- /dev/null +++ b/spec/fixtures/product.json @@ -0,0 +1,27 @@ +{ + "id": 41316136, + "sku": "NC53090", + "smallThumbnailUrl": "http://images-cdn.ecwid.com/images/4881025/242429875.jpg", + "thumbnailUrl": "http://images-cdn.ecwid.com/images/4881025/242429874.jpg", + "imageUrl": "http://images-cdn.ecwid.com/images/4881025/245156912.jpg", + "originalImageUrl": "http://images-cdn.ecwid.com/images/4881025/245156911.jpg", + "unlimited": true, + "inStock": true, + "name": "Book: Therapeutic Hand Splints: A Rational Approach", + "price": 80.95, + "weight": 0.063, + "url": "http://preview.myncmstore.com/em-Book-em-Therapeutic-Hand-Splints-A-Rational-Approach-p-41316136", + "created": "2014-09-13 01:45:38 -0700", + "updated": "2014-10-15 09:01:31 -0700", + "productClassId": 0, + "enabled": false, + "description": "
Mechanical and biomechanical considerations of hand splinting.
This book takes an in-depth look into the design, manufacture and application of splints for the upper limb and specifically the hand. The first section, Mechanical Considerations, includes immobilization and mobilization splinting, technical considerations, splinting materials and components. The second section, Biomechanical Considerations, addresses anatomical shape and positioning, volume control and pressure, and biokinematic and biokinetic systems. Includes numerous photographs and illustrations. Soft cover, 214 pages. Written by Paul Van Lede, MS, OT and Griet van Veldhoven, OT. Copyright 1998.