Skip to content

Commit

Permalink
Raw body parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalzambre committed Mar 12, 2021
1 parent 52f68a1 commit 0c76113
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/ecwid_api/entity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 7 additions & 1 deletion spec/api/products_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,10 @@
subject.all.first.sku.should == "NC53090"
end
end
end

describe "#find" do
it "finds product by id" do
subject.find(41316136).sku.should == "NC53090"
end
end
end
27 changes: 27 additions & 0 deletions spec/fixtures/product.json
Original file line number Diff line number Diff line change
@@ -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": "<em>Book:</em> 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": "<p><em>Mechanical and biomechanical considerations of hand splinting. </em><br /> 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, <em>Mechanical Considerations</em>, includes immobilization and mobilization splinting, technical considerations, splinting materials and components. The second section, <em>Biomechanical Considerations</em>, 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.</p>",
"descriptionTruncated": false,
"priceInProductList": 80.95,
"categoryIds": [],
"defaultCategoryId": 0,
"favorites": {
"count": 0,
"displayedCount": "0"
}
}
1 change: 1 addition & 0 deletions spec/helpers/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def faraday_stubs
stub.get("/orders/404") { [404, {"Content-Type" => "application/json"}, nil ] }
stub.get("/classes/1") { [200, {"Content-Type" => "application/json"}, File.read("spec/fixtures/classes.json") ] }
stub.get("/classes/404") { [404, {"Content-Type" => "application/json"}, nil ] }
stub.get("/products/41316136") { [200, {"Content-Type" => "application/json"}, File.read("spec/fixtures/product.json") ] }
end
end

Expand Down

0 comments on commit 0c76113

Please sign in to comment.