Permalink
Browse files

Merge pull request #4 from dave5/master

Updated the test fixtures to include all the new attributes
  • Loading branch information...
2 parents 30f33e9 + 65e3e94 commit a47d7d3ee914f4a1a688c70fcb14a09bbf758398 @hmaddocks committed Apr 2, 2012
View
@@ -4,5 +4,5 @@ Gemfile.lock
pkg/*
coverage
.DS_Store
-
+.rvmrc
*.bbprojectd/
View
@@ -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
@@ -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,17 +106,13 @@ def designs= designs
end
end
- private :designs=
-
def hardware= hw
@hardware.clear
hw.each do |h|
add_hardware Hardware.new(h), 1
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,26 +328,20 @@ 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|
@material_catalogue.make_material m
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
@@ -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
@@ -1,3 +1,4 @@
module Ponoko
- VERSION = "0.6.3"
+ VERSION = "1.0"
+ API_VERSION = "2.2"
end
View
@@ -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"
@@ -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'
@@ -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
@@ -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
Oops, something went wrong.

0 comments on commit a47d7d3

Please sign in to comment.