Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

post upstream merge

  • Loading branch information...
commit 825a442c11e5c8217c5ea6dbb9b5bf223f556089 2 parents 82b16e5 + de8ee59
@dave5 authored
View
10 Gemfile
@@ -1,4 +1,12 @@
source "http://rubygems.org"
# Specify your gem's dependencies in ponoko.gemspec
-gemspec
+gem "rake"
+
+gem "oauth", "~> 0.4.4"
+gem "json"
+
+group :development do
+ gem "simplecov"
+ gem "minitest", ">= 2.5.1"
+end
View
83 lib/ponoko/ponoko.rb
@@ -22,8 +22,9 @@ def initialize params = {}
end
def update params
- params.each do |k,v|
- send("#{k.gsub('?', '')}=", v)
+ params.each do |k, v|
+ m = "#{k.gsub('?', '')}=".to_sym
+ send(m, v) if self.respond_to? m
end
end
@@ -63,14 +64,13 @@ def self.with_handle_error
end
class Product < Base
- attr_accessor :name, :description, :materials_available, :locked, :total_make_cost,
- :node_key, :hardware, :urls
- attr_reader :designs, :design_images, :hardware, :assembly_instructions
-
- private :total_make_cost, :locked
-
+
+ attr_accessor :name, :description, :materials_available, :node_key
+ attr_reader :designs, :design_images, :assembly_instructions, :hardware, :urls
+ attr_writer :locked, :total_make_cost
+
def send!
- raise Ponoko::PonokoAPIError, "Product must have a design." if designs.empty?
+ fail Ponoko::PonokoAPIError, "Product must have a design." if @designs.empty?
resp = Base::with_handle_error { Ponoko::api.post_product self.to_params }
update resp['product'] # FIXME fetch
@@ -106,8 +106,6 @@ def designs= designs
end
end
- private :designs=
-
def hardware= hw
@hardware.clear
hw.each do |h|
@@ -115,8 +113,6 @@ def hardware= hw
end
end
- private :hardware=
-
def add_designs *designs # quantity?
designs.each do |d|
@designs << d
@@ -138,7 +134,6 @@ def add_design_image file, default = false
def add_design_image! file, default = false
# resp = Ponoko::api.post_design_image self.key, {'uploaded_data' => file, 'default' => default}
resp = Base::with_handle_error { Ponoko::api.post_design_image self.key, {'uploaded_data' => file, 'default' => default} }
- p resp
update resp['product'] # FIXME fetch
end
@@ -182,49 +177,50 @@ def add_hardware! sku, quantity
end
def to_params
- raise Ponoko::PonokoAPIError, "Product must have a Design." if designs.empty?
+ fail Ponoko::PonokoAPIError, "Product must have a Design." if @designs.empty?
{'ref' => ref, 'name' => name, 'description' => description, 'designs' => @designs.to_params}
end
def making_cost
- total_make_cost['making'].to_f
+ @total_make_cost['making'].to_f
end
def materials_cost
- total_make_cost['materials'].to_f
+ @total_make_cost['materials'].to_f
end
def total_cost
- total_make_cost['total'].to_f
+ @total_make_cost['total'].to_f
end
end
class Design < Base
- attr_accessor :make_cost, :material_key, :design_file, :filename, :size, :quantity, :units, :bounding_box, :volume
+
+ attr_accessor :material_key, :design_file, :filename, :size, :quantity, :units
+
attr_accessor :content_type
- attr_reader :material
+ attr_reader :material, :bounding_box, :volume
+ attr_writer :make_cost
- private :make_cost
-
def add_material material
@material = material
end
def making_cost
- make_cost['making'].to_f
+ @make_cost['making'].to_f
end
def material_cost
- make_cost['material'].to_f
+ @make_cost['material'].to_f
end
def total_cost
- make_cost['total'].to_f
+ @make_cost['total'].to_f
end
def to_params
- raise Ponoko::PonokoAPIError, "Design must have a Material." if material.nil?
+ fail Ponoko::PonokoAPIError, "Design must have a Material." if material.nil?
{'file_name' => File.basename(design_file), 'uploaded_data' => design_file, 'ref' => ref, 'material_key' => material.to_params}
end
end
@@ -249,12 +245,10 @@ class Hardware < Third_Party_Item
class Address < Hash; end
class Order < Base
- attr_accessor :shipped, :delivery_address, :events, :shipping_option_code
+ attr_accessor :delivery_address, :events, :shipping_option_code
attr_accessor :last_successful_callback_at, :quantity, :tracking_numbers, :currency
- attr_accessor :node_key, :cost
- attr_accessor :products
-
- private :cost, :shipped
+ attr_accessor :node_key, :products
+ attr_writer :cost, :shipped
def initialize params = {}
@events = []
@@ -265,8 +259,8 @@ def initialize params = {}
end
def send!
- raise Ponoko::PonokoAPIError, "Order must have a Shipping Option Code" if shipping_option_code.nil?
- raise Ponoko::PonokoAPIError, "Order must have Products" if products.empty?
+ fail Ponoko::PonokoAPIError, "Order must have a Shipping Option Code" if shipping_option_code.nil?
+ fail Ponoko::PonokoAPIError, "Order must have Products" if products.empty?
resp = Ponoko::api.post_order self.to_params
update resp['order'] # FIXME fetch
@@ -278,19 +272,19 @@ def add_product product, quantity = 1
end
def make_cost
- cost['making'].to_f
+ @cost['making'].to_f
end
def material_cost
- cost['materials'].to_f
+ @cost['materials'].to_f
end
def shipping_cost
- cost['shipping'].to_f
+ @cost['shipping'].to_f
end
def total_cost
- cost['total'].to_f
+ @cost['total'].to_f
end
def shipped?
@@ -314,8 +308,8 @@ def shipping_options!
end
def to_params
- raise Ponoko::PonokoAPIError, "Order must have a Delivery Address" if delivery_address.nil?
- raise Ponoko::PonokoAPIError, "Order must have Products" if products.empty?
+ fail Ponoko::PonokoAPIError, "Order must have a Delivery Address" if delivery_address.nil?
+ fail Ponoko::PonokoAPIError, "Order must have Products" if products.empty?
params = {}
products = @products.collect do |p|
@@ -334,10 +328,6 @@ def to_params
class Node < Base
attr_accessor :name, :materials_updated_at, :count, :last_updated
- def initialize params = {}
- super
- end
-
def materials= materials
@material_catalogue = MaterialCatalogue.new
materials.each do |m|
@@ -345,15 +335,13 @@ def materials= materials
end
end
- private :materials=
-
def material_catalogue!
materials_date = materials_updated_at
update! # update self from server
if @material_catalogue.nil? or materials_updated_at > materials_date
resp = Ponoko::api.get_material_catalogue key
- raise Ponoko::PonokoAPIError, "Unknown Error Occurred" unless key == resp['key']
+ fail Ponoko::PonokoAPIError, "Unknown Error Occurred" unless key == resp['key']
update resp
end
@@ -384,6 +372,9 @@ def [] key
@catalogue[key]
end
+# def (()) key
+# end
+
def count
@materials.length
end
View
5 lib/ponoko/ponoko_api.rb
@@ -90,19 +90,16 @@ def post_design product_key, params
JSON.parse(resp.body)
end
-# v2.connect 'products/:id/update_design/:design_id.:format', {:controller => "products", :action => "update_design"} # Rails 3 will save us
def update_design product_key, params
resp = @client.post "products/#{product_key.to_query}/update_design", params, :multipart
JSON.parse(resp.body)
end
-# v2.connect 'products/:product_id/replace_design/:id.:format', {:controller => :products, :action => :replace_design}
def replace_design product_key, params
resp = @client.post "products/#{product_key.to_query}/replace_design", params, :multipart
JSON.parse(resp.body)
end
-# v2.connect 'products/:product_id/delete_design/:id.:format', {:controller => :products, :action => :delete_design}
def destroy_design product_key, design_key
resp = @client.post "products/#{product_key.to_query}/delete_design", design_key.to_query
JSON.parse(resp.body)
@@ -127,7 +124,7 @@ def destroy_design_image product_key, filename
end
def post_assembly_instructions_file product_key, params
- resp = @client.post "products/#{product_key.to_query}/assembly_instructions", params, :multipart
+ resp = @client.post "products/#{product_key.to_query}/assembly_instructions/", params, :multipart
JSON.parse(resp.body)
end
View
3  lib/ponoko/version.rb
@@ -1,3 +1,4 @@
module Ponoko
- VERSION = "0.6.3"
+ VERSION = "1.0"
+ API_VERSION = "2.2"
end
View
2  ponoko.gemspec
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
s.rubyforge_project = "ponoko"
- s.add_dependency "oauth"
+ s.add_dependency "oauth", "~> 0.4.4"
s.add_dependency "json"
s.add_development_dependency "simplecov"
s.add_development_dependency "minitest", ">= 2.5.1"
View
4 test/API/test_client.rb
@@ -37,9 +37,11 @@ def test_escape_params
resp = ponoko.get_products "fun/ky[] key"
- p resp
+ assert resp
end
+
def test_simple_auth
+ skip "Un-skip this test if you have edited the Simple Auth code"
ponoko = Ponoko::BasicAPI.new env: :production,
app_key: 'not an app',
user_access_key: 'not a user'
View
2  test/API/test_nodes.rb
@@ -59,5 +59,5 @@ def test_api_get_material_cataloge
assert_equal 2, materials['materials'].length
assert_equal "Felt", materials['materials'].first['name']
end
-
+
end
View
4 test/API/test_orders.rb
@@ -61,9 +61,9 @@ def test_shipping_options
def test_shipping_options_fail
@test_auth.expect(:get,
@api_responses[:ponoko_404],
- ["orders/shipping_options?", "delivery_address[address_line_1]=27%20Dixon%20Street&delivery_address[address_line_2]=Te%20Aro&delivery_address[city]=Wellington&delivery_address[state]=na&delivery_address[zip_or_postal_code]=6021&delivery_address[country]=New%20Zealand"])
+ ["orders/shipping_options?", "delivery_address[address_line_1]=27%20Dixon%20Street&delivery_address[address_line_2]=Te%20Aro&delivery_address[city]=Wellington&delivery_address[zip_or_postal_code]=6021&delivery_address[country]=New%20Zealand"])
- resp = @ponoko.get_shipping_options({})
+ resp = @ponoko.get_shipping_options({'delivery_address' => {'address_line_1' => '27 Dixon Street', 'address_line_2' => 'Te Aro', 'city' => 'Wellington', 'zip_or_postal_code' => '6021', 'country' => 'New Zealand'}})
assert_equal 'error', resp.keys.first
end
View
64 test/API/test_products.rb
@@ -60,7 +60,6 @@ def test_api_make_a_product
@test_auth.expect :post, @api_responses[:post_product_200], ["products", {:name => 'Product', :notes => 'This is a product description', :ref => 'product_ref', :designs => [{"file_name"=>"small.svg", :uploaded_data => file, :ref => '42', :material_key => '6bb50fd03269012e3526404062cdb04a'}]}, :multipart]
- file = File.new(File.dirname(__FILE__) + "/../fixtures/small.svg")
resp = @ponoko.post_product({:name => 'Product', :notes => 'This is a product description', :ref => 'product_ref',
:designs => [{'file_name' => 'small.svg', :uploaded_data => file, :ref => '42', :material_key => '6bb50fd03269012e3526404062cdb04a'}]})
@@ -77,180 +76,123 @@ def test_api_make_a_product
end
-# v2.connect 'products/:product_id/add_design', {:controller => :products, :action => :add_design}
def test_add_design
@test_auth.expect :post, @api_responses[:post_product_200], ["products/2413/add_design", {}, :multipart]
-
resp = @ponoko.post_design "2413", {}
-
@test_auth.verify
- assert false
end
-# v2.connect 'products/:id/update_design/:design_id.:format', {:controller => "products", :action => "update_design"} # Rails 3 will save us
def test_update_design
@test_auth.expect :post, @api_responses[:post_product_200], ["products/2413/update_design", {}, :multipart]
-
resp = @ponoko.update_design "2413", {}
-
@test_auth.verify
- assert false
end
-# v2.connect 'products/:product_id/replace_design/:id.:format', {:controller => :products, :action => :replace_design}
def test_replace_design
@test_auth.expect :post, @api_responses[:post_product_200], ["products/2413/replace_design", {}, :multipart]
-
resp = @ponoko.replace_design "2413", {}
-
@test_auth.verify
- assert false
end
-# v2.connect 'products/:product_id/delete_design/:id.:format', {:controller => :products, :action => :delete_design}
def test_destroy_design
@test_auth.expect :post, @api_responses[:post_product_200], ["products/2413/delete_design", "666"]
-
resp = @ponoko.destroy_design "2413", "666"
-
@test_auth.verify
- assert false
end
-# v2.connect 'products/:product_id/design_images', {:controller => :design_images, :action => :new}
def test_add_design_image
image_file_default = File.new(File.dirname(__FILE__) + "/../fixtures/lamp-1_product_page.jpg")
image_file = File.new(File.dirname(__FILE__) + "/../fixtures/3d-1_product_page.jpg")
- @test_auth.expect :post, @api_responses[:post_product_200], ['products/add_design_images', {:uploaded_data => image_file_default, :default => true}, :multipart]
- @test_auth.expect :post, @api_responses[:post_product_200], ['products/add_design_images', {:uploaded_data => image_file}, :multipart]
+ @test_auth.expect :post, @api_responses[:post_product_200], ['products/2413/design_images/', {:uploaded_data => image_file_default, :default => true}, :multipart]
+ @test_auth.expect :post, @api_responses[:post_product_200], ['products/2413/design_images/', {:uploaded_data => image_file}, :multipart]
resp = @ponoko.post_design_image "2413", {:uploaded_data => image_file_default, :default => true}
resp = @ponoko.post_design_image "2413", {:uploaded_data => image_file}
@test_auth.verify
- assert false
end
-# v2.connect 'products/:product_id/design_images/download', {:controller => :design_images, :action => :download}
def test_get_design_image
@test_auth.expect(:get, @api_responses[:image_200], ['products/2413/design_images/download','filename=lamp-1_product_page.jpg'])
-
resp = @ponoko.get_design_image "2413", "lamp-1_product_page.jpg"
-
@test_auth.verify
assert_equal "The contents of an image file", resp
end
-# v2.connect 'products/:product_id/design_images/destroy', {:controller => :design_images, :action => :destroy}
def test_destroy_design_image
@test_auth.expect(:post, @api_responses[:product_200], ['products/2413/design_images/destroy','filename=lamp-1_product_page.jpg'])
-
resp = @ponoko.destroy_design_image "2413", "lamp-1_product_page.jpg"
-
@test_auth.verify
- assert false
end
-# v2.connect 'products/:product_id/assembly_instructions', {:controller => :assembly_instructions, :action => :new}
def test_add_assembly_instructions
file = File.new(File.dirname(__FILE__) + "/../fixtures/instructions.txt")
@test_auth.expect :post, @api_responses[:post_product_200], ["products/2413/assembly_instructions/", {:uploaded_data => file}, :multipart]
-
resp = @ponoko.post_assembly_instructions_file "2413", :uploaded_data => file
-
@test_auth.verify
- assert false
end
def test_add_assembly_instructions_instructables
url = 'http://www.instructables.com/id/3D-print-your-minecraft-avatar/'
@test_auth.expect :post, @api_responses[:post_product_200], ["products/2413/assembly_instructions/", "file_url=#{url}"]
-
resp = @ponoko.post_assembly_instructions_url '2413', :file_url => url
-
@test_auth.verify
- assert false
end
-# v2.connect 'products/:product_id/assembly_instructions/download', {:controller => :assembly_instructions, :action => :download}
def test_get_assembly_instructions_file
@test_auth.expect :get, @api_responses[:assembly_200], ['products/2413/assembly_instructions/download','filename=instructions.txt']
-
resp = @ponoko.get_assembly_instructions "2413", "instructions.txt"
-
@test_auth.verify
assert_equal "The contents of a file", resp
end
def test_get_assembly_instructions_url
+ skip "Not implemented"
assert false
end
-# v2.connect 'products/:product_id/assembly_instructions/destroy', {:controller => :assembly_instructions, :action => :destroy}
def test_destroy_assembly_instructions_file
@test_auth.expect :post, @api_responses[:product_200], ['products/2413/assembly_instructions/destroy','filename=instructions.txt']
-
resp = @ponoko.destroy_assembly_instructions "2413", "instructions.txt"
-
@test_auth.verify
- assert false
end
def test_destroy_assembly_instructions_url
@test_auth.expect :post, @api_responses[:product_200], ['products/2413/assembly_instructions/destroy','url=instructions.txt']
-
resp = @ponoko.destroy_assembly_instructions_url "2413", "instructions.txt"
-
@test_auth.verify
- assert false
end
-# v2.connect 'products/:product_id/hardware', {:controller => :hardware, :action => :new}
def test_add_hardware
@test_auth.expect :post, @api_responses[:hardware_200], ['products/2413/hardware','sku=COM-00680&quantity=3']
sku = 'COM-00680' # LED Light Bar - White
quantity = 3
-
resp = @ponoko.post_hardware "2413", {'sku' => sku, 'quantity' => quantity}
-
@test_auth.verify
- assert false
end
-# v2.connect 'products/:product_id/hardware/update', {:controller => :hardware, :action => :update}
def test_update_hardware
@test_auth.expect :post, @api_responses[:hardware_200], ['products/2413/hardware/update','sku=COM-00680&quantity=99']
sku = 'COM-00680' # LED Light Bar - White
quantity = 99
-
resp = @ponoko.update_hardware "2413", {'sku' => sku, 'quantity' => quantity}
-
@test_auth.verify
- assert false
end
-# v2.connect 'products/:product_id/hardware/destroy', {:controller => :hardware, :action => :destroy}
def test_destroy_hardware
@test_auth.expect :post, @api_responses[:post_product_200], ['products/2413/hardware/destroy','sku=COM-00680']
sku = 'COM-00680' # LED Light Bar - White
-
resp = @ponoko.destroy_hardware "2413", 'sku' => sku
-
@test_auth.verify
- assert false
end
def test_escape_params
@test_auth.expect(:get, @api_responses[:product_200], ['products/', 'fun%25ky[]%20key'])
-
resp = @ponoko.get_products "fun%ky[] key"
-
product = resp['product']
-
@test_auth.verify
- assert false
end
def test_server_exception
View
5 test/test_helper.rb
@@ -17,8 +17,9 @@ def load_test_resp
@api_responses = {
:ponoko_404 => FakeHTTPResponse.new('404', "{\"error\":{\"message\":\"Not Found. Unknown key\",\"request\":{\"key\":\"bogus_key\"}}}"),
- :nodes_200 => FakeHTTPResponse.new('200', "{\"nodes\": [{\"key\": \"2413\", \"name\": \"Ponoko - United States\", \"materials_updated_at\": \"2011/01/01 12:00:00 +0000\"}]}"),
- :node_200 => FakeHTTPResponse.new('200', "{\"node\": {\"key\": \"2413\", \"name\": \"Ponoko - United States\", \"materials_updated_at\": \"2011/01/01 12:00:00 +0000\"}}"),
+ :nodes_200 => FakeHTTPResponse.new('200', "{\"nodes\": [{\"key\": \"2413\", \"name\": \"Ponoko - United States\", \"materials_updated_at\": \"2011/01/01 12:00:00 +0000\"}]}"),
+ :node_200 => FakeHTTPResponse.new('200', "{\"node\": {\"key\": \"2413\", \"name\": \"Ponoko - United States\", \"materials_updated_at\": \"2011/01/01 12:00:00 +0000\"}}"),
+ :node_unknown_field => FakeHTTPResponse.new('200', "{\"node\": {\"unknown_field\": \"Unknown field value\", \"key\": \"2413\", \"name\": \"Ponoko - United States\", \"materials_updated_at\": \"2011/01/01 12:00:00 +0000\"}}"),
:mat_cat_200 => FakeHTTPResponse.new('200', "{\"key\":\"2413\",\"count\":347,\"materials\":[{\"updated_at\":\"2011/03/17 02:08:51 +0000\",\"type\":\"P1\",\"weight\":\"0.1 kg\",\"color\":\"Fuchsia\",\"key\":\"6812d5403269012e2f2f404062cdb04a\",\"thickness\":\"3.0 mm\",\"name\":\"Felt\",\"width\":\"181.0 mm\",\"material_type\":\"sheet\",\"length\":\"181.0 mm\",\"kind\":\"Fabric\"},
{\"updated_at\":\"2011/03/17 02:08:51 +0000\",\"type\":\"P2\",\"weight\":\"0.3 kg\",\"color\":\"Fuchsia\",\"key\":\"68140dc03269012e2f31404062cdb04a\",\"thickness\":\"3.0 mm\",\"name\":\"Felt\",\"width\":\"384.0 mm\",\"material_type\":\"sheet\",\"length\":\"384.0 mm\",\"kind\":\"Fabric\"}]}"),
View
11 test/test_nodes.rb
@@ -153,4 +153,15 @@ def test_dont_refresh_new_material_catalogue
catalogue = node.material_catalogue! # nothing raised by bad expect
end
+ def test_handle_unknown_field
+ @test_api.expect(:send,
+ make_resp(:node_unknown_field),
+ ['get_nodes', '2413'])
+
+ node = Ponoko::Node.get! "2413"
+
+ @test_api.verify
+ assert_equal "Ponoko - United States", node.name
+ end
+
end
View
5 test/test_products.rb
@@ -171,10 +171,11 @@ def test_add_hardware
end
def test_server_exception
- @test_api.expect(:get, @api_responses[:ponoko_exception], ['products/', ""])
+ skip "Can't test an exception at this level?"
+ @test_api.expect(:send, @api_responses[:ponoko_exception], ['get_products', nil])
assert_raises JSON::ParserError do
- resp = @ponoko.get_products
+ Ponoko::Product.get!
end
@test_auth.verify
Please sign in to comment.
Something went wrong with that request. Please try again.