magento-api 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Manifest +28 -0
- data/README.rdoc +12 -0
- data/Rakefile +14 -0
- data/config/magento.yml +6 -0
- data/init.rb +1 -0
- data/lib/abstract.rb +42 -0
- data/lib/category.rb +96 -0
- data/lib/configuration.rb +21 -0
- data/lib/country.rb +9 -0
- data/lib/customer.rb +39 -0
- data/lib/customer_address.rb +32 -0
- data/lib/customer_groups.rb +8 -0
- data/lib/extensions.rb +16 -0
- data/lib/inventory.rb +32 -0
- data/lib/invoice.rb +6 -0
- data/lib/magento.rb +24 -0
- data/lib/order.rb +44 -0
- data/lib/product.rb +4 -0
- data/lib/product_images.rb +4 -0
- data/lib/product_types.rb +4 -0
- data/lib/region.rb +14 -0
- data/lib/server.rb +4 -0
- data/lib/shipment.rb +48 -0
- data/magento-api.gemspec +31 -0
- data/test/test_customer.rb +28 -0
- data/test/test_helper.rb +8 -0
- data/test/test_inventory.rb +30 -0
- data/test/test_magento.rb +0 -0
- data/test/test_order.rb +32 -0
- metadata +110 -0
data/Manifest
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
config/magento.yml
|
2
|
+
init.rb
|
3
|
+
lib/abstract.rb
|
4
|
+
lib/category.rb
|
5
|
+
lib/configuration.rb
|
6
|
+
lib/country.rb
|
7
|
+
lib/customer.rb
|
8
|
+
lib/customer_address.rb
|
9
|
+
lib/customer_groups.rb
|
10
|
+
lib/extensions.rb
|
11
|
+
lib/inventory.rb
|
12
|
+
lib/invoice.rb
|
13
|
+
lib/magento.rb
|
14
|
+
lib/order.rb
|
15
|
+
lib/product.rb
|
16
|
+
lib/product_images.rb
|
17
|
+
lib/product_types.rb
|
18
|
+
lib/region.rb
|
19
|
+
lib/server.rb
|
20
|
+
lib/shipment.rb
|
21
|
+
Rakefile
|
22
|
+
README.rdoc
|
23
|
+
test/test_customer.rb
|
24
|
+
test/test_helper.rb
|
25
|
+
test/test_inventory.rb
|
26
|
+
test/test_magento.rb
|
27
|
+
test/test_order.rb
|
28
|
+
Manifest
|
data/README.rdoc
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
== Magento ===================
|
2
|
+
|
3
|
+
This is a simple gem which wraps Magento XMLRPC calls with Ruby classes.
|
4
|
+
This allows for you to integrate your Magento Shopping Cart into your Rails Application.
|
5
|
+
|
6
|
+
== Usage =====================
|
7
|
+
|
8
|
+
See Rdoc
|
9
|
+
|
10
|
+
== Issues ====================
|
11
|
+
|
12
|
+
A patch needs to be applied to XMLRPC for this to work.
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
|
5
|
+
Echoe.new('magento-api', '0.1.0') do |p|
|
6
|
+
p.description = "Rubygem for connecting to a Magento store via the Magento Core API"
|
7
|
+
p.url = ""
|
8
|
+
p.author = "Tim Matheson"
|
9
|
+
p.email = "me@timmatheson.com"
|
10
|
+
p.ignore_pattern = ["tmp/*","script/*"]
|
11
|
+
p.development_dependencies = []
|
12
|
+
end
|
13
|
+
|
14
|
+
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
|
data/config/magento.yml
ADDED
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'magento'
|
data/lib/abstract.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
module Magento
|
2
|
+
class Abstract
|
3
|
+
attr_accessor :attributes
|
4
|
+
|
5
|
+
def initialize(attributes = {})
|
6
|
+
@connection = Magento::Connection.new
|
7
|
+
@attributes = attributes.dup
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.connect
|
11
|
+
@connection ||= Magento::Connection.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.first
|
15
|
+
return nil unless respond_to?(:list)
|
16
|
+
n = 0
|
17
|
+
while list(n)[0] == nil
|
18
|
+
n+=1
|
19
|
+
end
|
20
|
+
return list(n)[0]
|
21
|
+
end
|
22
|
+
|
23
|
+
def object_attributes=(new_attributes)
|
24
|
+
return if new_attributes.nil?
|
25
|
+
attributes = new_attributes.dup
|
26
|
+
attributes.stringify_keys!
|
27
|
+
attributes.each do |k, v|
|
28
|
+
send(k + "=", v)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.commit(method, *args)
|
33
|
+
connect
|
34
|
+
@connection.call(method, args)
|
35
|
+
end
|
36
|
+
|
37
|
+
def method_missing(method, *args)
|
38
|
+
return nil unless @attributes
|
39
|
+
@attributes[method.to_s]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/category.rb
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'magento'
|
2
|
+
module Magento
|
3
|
+
class Category < Abstract
|
4
|
+
def current_store(store_view = nil)
|
5
|
+
connect
|
6
|
+
@connection.call("category.currentStore",store_view)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.tree(category_id = nil, store_view = nil)
|
10
|
+
connect
|
11
|
+
fields = [category_id,store_view].compact
|
12
|
+
if fields.empty?
|
13
|
+
@connection.call("category.level")
|
14
|
+
else
|
15
|
+
@connection.call("category.level",fields)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.level(website = nil, store_view = nil, parent_category = nil)
|
20
|
+
connect
|
21
|
+
fields = [website,store_view,parent_category].compact
|
22
|
+
if fields.empty?
|
23
|
+
@connection.call("category.level")
|
24
|
+
else
|
25
|
+
@connection.call("category.level",fields)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.find(category_id, store_view = nil, *args)
|
30
|
+
connect
|
31
|
+
fields = [store_view].compact
|
32
|
+
if fields.empty?
|
33
|
+
@connection.call("category.info",category_id)
|
34
|
+
else
|
35
|
+
@connection.call("category.info",category_id,fields,args)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.create(parent_id, category_data, store_view = nil)
|
40
|
+
connect
|
41
|
+
if store_view.nil?
|
42
|
+
@connection.call("category.create", parent_id, category_data)
|
43
|
+
else
|
44
|
+
@connection.call("category.create", parent_id, category_data, store_view)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.update(parent_id, category_data, store_view = nil)
|
49
|
+
connect
|
50
|
+
if store_view.nil?
|
51
|
+
@connection.call("category.update", parent_id, category_data)
|
52
|
+
else
|
53
|
+
@connection.call("category.update", parent_id, category_data, store_view)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.move(category_id, parent_id, after_id)
|
58
|
+
connect
|
59
|
+
@connection.call("category.move", category_id, parent_id, after_id)
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.delete(category_id)
|
63
|
+
connect
|
64
|
+
@connection.call("category.delete",category_id)
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.assigned_products(category_id, store_id)
|
68
|
+
connect
|
69
|
+
@connection.call("category.assignedProducts",category_id, store_id)
|
70
|
+
end
|
71
|
+
|
72
|
+
def assigned_products(store_id)
|
73
|
+
if store_id
|
74
|
+
Category.assigned_products(self.id, store_id)
|
75
|
+
else
|
76
|
+
Category.assigned_products(self.id)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def assign_product(product_id)
|
81
|
+
connect
|
82
|
+
@connection.call("category.assignProduct",self.id, product_id)
|
83
|
+
end
|
84
|
+
|
85
|
+
def update_product(product_id, position = 1)
|
86
|
+
connect
|
87
|
+
@connection.call("category.updateProduct",self.id, product_id, position)
|
88
|
+
end
|
89
|
+
|
90
|
+
def remove_product(product_id)
|
91
|
+
connect
|
92
|
+
@connection.call("category.removeProduct",self.id, product_id)
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
module Magento
|
3
|
+
class Configuration
|
4
|
+
attr_accessor :username, :api_key, :host, :path, :port
|
5
|
+
|
6
|
+
CONFIG_PATH = File.dirname(__FILE__) + "/../config/magento.yml"
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
raise ConfigurationException, "Missing configuration file" unless File.exists?(CONFIG_PATH)
|
10
|
+
options = YAML.load_file(CONFIG_PATH)
|
11
|
+
@username = options["username"]
|
12
|
+
@api_key = options["api_key"]
|
13
|
+
@host = options["host"]
|
14
|
+
@path = options["path"]
|
15
|
+
@port = options["port"]
|
16
|
+
yield self if block_given?
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class ConfigurationException; end;
|
21
|
+
end
|
data/lib/country.rb
ADDED
data/lib/customer.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'magento'
|
2
|
+
require 'abstract'
|
3
|
+
|
4
|
+
module Magento
|
5
|
+
class Customer < Abstract
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
connect
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.find(*args)
|
12
|
+
connect
|
13
|
+
@connection.call("customer.info",args)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.list(*args)
|
17
|
+
connect
|
18
|
+
customers = @connection.call("customer.list",args)
|
19
|
+
customer_list = []
|
20
|
+
customers.each do |customer|
|
21
|
+
customer_list.push(customer.to_struct(self.class.to_s))
|
22
|
+
end
|
23
|
+
customer_list
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.create(*args)
|
27
|
+
connect
|
28
|
+
@connection.call("customer.create",args)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.delete(customer_id = nil)
|
32
|
+
raise CustomerException, "Invalid customer id" if customer_id.nil?
|
33
|
+
connect
|
34
|
+
@connection.call("customer.delete",customer_id)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class CustomerException < StandardError; end;
|
39
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'magento'
|
2
|
+
module Magento
|
3
|
+
class CustomerAddress < Abstract
|
4
|
+
|
5
|
+
def self.list(customer_address_id)
|
6
|
+
connect
|
7
|
+
@connection.call("customer_address.list", customer_address_id)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.find(customer_address_id)
|
11
|
+
connect
|
12
|
+
@connection.call("customer_address.info", customer_address_id)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.create(address_attributes)
|
16
|
+
connect
|
17
|
+
@connection.call("customer_address.create", address_attributes)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.update(address_attributes)
|
21
|
+
connect
|
22
|
+
@connection.call("customer_address.update", address_attributes)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.delete(customer_address_id)
|
26
|
+
connect
|
27
|
+
@connection.call("customer_address.delete",customer_address_id)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
puts Magento::CustomerAddress.list
|
data/lib/extensions.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
class Hash
|
2
|
+
def to_struct(struct_name)
|
3
|
+
Struct.new(struct_name,*keys).new(*values)
|
4
|
+
end
|
5
|
+
|
6
|
+
def stringify_keys!
|
7
|
+
keys.each do |key|
|
8
|
+
self[key.to_s] = delete(key)
|
9
|
+
end
|
10
|
+
self
|
11
|
+
end
|
12
|
+
|
13
|
+
def method_missing(method, *args)
|
14
|
+
self["#{method}"]
|
15
|
+
end
|
16
|
+
end
|
data/lib/inventory.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'magento'
|
2
|
+
module Magento
|
3
|
+
class Inventory < Abstract
|
4
|
+
def new(attributes = {})
|
5
|
+
attributes.each do |attr, val|
|
6
|
+
instance_variable_set(:"@#{attr}",val)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.list(*args)
|
11
|
+
list = []
|
12
|
+
commit("product_stock.list", args).each do |inventory|
|
13
|
+
list.push(new(inventory))
|
14
|
+
end
|
15
|
+
list
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.update(id,*args)
|
19
|
+
#commit("product_stock.update", args)
|
20
|
+
connect
|
21
|
+
@connection.call("product_stock.update",id,args)
|
22
|
+
end
|
23
|
+
|
24
|
+
def update(*args)
|
25
|
+
commit("product_stock.update", product_id, args)
|
26
|
+
end
|
27
|
+
|
28
|
+
def in_stock?
|
29
|
+
is_in_stock.to_i == 1
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/invoice.rb
ADDED
data/lib/magento.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'extensions'
|
2
|
+
require 'xmlrpc'
|
3
|
+
require 'xmlrpc/client'
|
4
|
+
require 'configuration'
|
5
|
+
require 'customer'
|
6
|
+
require 'inventory'
|
7
|
+
require 'invoice'
|
8
|
+
require 'order'
|
9
|
+
|
10
|
+
module Magento
|
11
|
+
class Connection
|
12
|
+
attr_accessor :client
|
13
|
+
def initialize(*args)
|
14
|
+
@config = Configuration.new
|
15
|
+
@client = XMLRPC::Client.new(@config.host,@config.path,@config.port)
|
16
|
+
@session = @client.call("login", @config.username, @config.api_key)
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
def call(method = nil, *args)
|
21
|
+
client.call("call",@session, method, args)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/order.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'magento'
|
2
|
+
module Magento
|
3
|
+
class Order < Abstract
|
4
|
+
def self.list(*args)
|
5
|
+
orders = commit("order.list",args)
|
6
|
+
order_list = []
|
7
|
+
orders.each do |order|
|
8
|
+
order_list.push(order.to_struct(self.class.to_s))
|
9
|
+
end
|
10
|
+
order_list
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.find(*args)
|
14
|
+
order_attributes = commit("order.info", args)
|
15
|
+
new(order_attributes)
|
16
|
+
end
|
17
|
+
|
18
|
+
def add_comment(comment = nil, notify = false)
|
19
|
+
return false if comment.nil?
|
20
|
+
commit("order.addComment",self.increment_id,"Pending",comment,notify)
|
21
|
+
end
|
22
|
+
|
23
|
+
def comments
|
24
|
+
status_history
|
25
|
+
end
|
26
|
+
|
27
|
+
def hold
|
28
|
+
commit("order.hold",self.increment_id)
|
29
|
+
end
|
30
|
+
|
31
|
+
def unhold
|
32
|
+
commit("order.unhold",self.increment_id)
|
33
|
+
end
|
34
|
+
|
35
|
+
def cancel
|
36
|
+
commit("order.cancel",self.increment_id)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
#o = Magento::Order.find("100000001")
|
42
|
+
#puts o.attributes
|
43
|
+
|
44
|
+
puts Magento::Order.find("100000001").hold
|
data/lib/product.rb
ADDED
data/lib/region.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'magento'
|
2
|
+
module Magento #:nodoc:
|
3
|
+
class Region < Abstract #:nodoc:
|
4
|
+
def self.list(country = nil)
|
5
|
+
raise RegionException, "Invalid country code" if country.nil?
|
6
|
+
connect
|
7
|
+
regions = []
|
8
|
+
@connection.call("region.list", country)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class RegionException < StandardError #:nodoc:
|
13
|
+
end
|
14
|
+
end
|
data/lib/server.rb
ADDED
data/lib/shipment.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'magento'
|
2
|
+
module Magento #:nodoc:
|
3
|
+
class Shipment < Abstract #:nodoc:
|
4
|
+
CARRIERS = { :usps => "usps", :ups => "ups", :dhl => "dhl", :fedex => "fedex" }
|
5
|
+
|
6
|
+
def self.list(*args)
|
7
|
+
connect
|
8
|
+
shipments = @connection.call("order_shipment.list",args)
|
9
|
+
shipment_list = []
|
10
|
+
shipments.each do |order|
|
11
|
+
shipment_list.push(order.to_struct(self.class.to_s))
|
12
|
+
end
|
13
|
+
shipment_list
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.find(*args)
|
17
|
+
connect
|
18
|
+
shipment_attributes = @connection.call("order_shipment.info", args)
|
19
|
+
new(shipment_attributes)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.create(order_id, items, comment = "", notify = false, include_in_email = false)
|
23
|
+
connect
|
24
|
+
@connection.call("order_shipment.create",order_id, items, comment, notify, include_in_email)
|
25
|
+
end
|
26
|
+
|
27
|
+
def add_comment(comment = nil, notify = false, include_in_email = false)
|
28
|
+
return false if comment.nil?
|
29
|
+
@connection.call("order_shipment.addComment",self.increment_id,comment,notify,include_in_email)
|
30
|
+
end
|
31
|
+
|
32
|
+
def add_tracking_number(carrier_code, number, title = "")
|
33
|
+
raise ShipmentException, "Invalid carrier code" unless CARRIERS.values.include?(carrier_code)
|
34
|
+
@connection.call("order_shipment.addTrack",self.increment_id,carrier_code,title,number)
|
35
|
+
end
|
36
|
+
|
37
|
+
def remove_tracking_number(tracking_number_id)
|
38
|
+
@connection.call("order_shipment.removeTrack",self.increment_id,tracking_number_id)
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.get_carriers(order_id)
|
42
|
+
@connection.call("order_shipment.getCarriers",order_id)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class ShipmentException < StandardError #:nodoc:
|
47
|
+
end
|
48
|
+
end
|
data/magento-api.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{magento-api}
|
5
|
+
s.version = "0.1.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Tim Matheson"]
|
9
|
+
s.date = %q{2009-08-12}
|
10
|
+
s.description = %q{Rubygem for connecting to a Magento store via the Magento Core API}
|
11
|
+
s.email = %q{me@timmatheson.com}
|
12
|
+
s.extra_rdoc_files = ["lib/abstract.rb", "lib/category.rb", "lib/configuration.rb", "lib/country.rb", "lib/customer.rb", "lib/customer_address.rb", "lib/customer_groups.rb", "lib/extensions.rb", "lib/inventory.rb", "lib/invoice.rb", "lib/magento.rb", "lib/order.rb", "lib/product.rb", "lib/product_images.rb", "lib/product_types.rb", "lib/region.rb", "lib/server.rb", "lib/shipment.rb", "README.rdoc"]
|
13
|
+
s.files = ["config/magento.yml", "init.rb", "lib/abstract.rb", "lib/category.rb", "lib/configuration.rb", "lib/country.rb", "lib/customer.rb", "lib/customer_address.rb", "lib/customer_groups.rb", "lib/extensions.rb", "lib/inventory.rb", "lib/invoice.rb", "lib/magento.rb", "lib/order.rb", "lib/product.rb", "lib/product_images.rb", "lib/product_types.rb", "lib/region.rb", "lib/server.rb", "lib/shipment.rb", "Rakefile", "README.rdoc", "test/test_customer.rb", "test/test_helper.rb", "test/test_inventory.rb", "test/test_magento.rb", "test/test_order.rb", "Manifest", "magento-api.gemspec"]
|
14
|
+
s.homepage = %q{}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Magento-api", "--main", "README.rdoc"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{magento-api}
|
18
|
+
s.rubygems_version = %q{1.3.4}
|
19
|
+
s.summary = %q{Rubygem for connecting to a Magento store via the Magento Core API}
|
20
|
+
s.test_files = ["test/test_customer.rb", "test/test_helper.rb", "test/test_inventory.rb", "test/test_magento.rb", "test/test_order.rb"]
|
21
|
+
|
22
|
+
if s.respond_to? :specification_version then
|
23
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
24
|
+
s.specification_version = 3
|
25
|
+
|
26
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
27
|
+
else
|
28
|
+
end
|
29
|
+
else
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class CustomerTest < Test::Unit::TestCase
|
4
|
+
def test_creation
|
5
|
+
customer = Magento::Customer.new
|
6
|
+
assert_not_nil customer
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_firstname
|
10
|
+
customer = Magento::Customer.find("1")
|
11
|
+
assert_equal("Tim",customer["firstname"])
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_lastname
|
15
|
+
customer = Magento::Customer.find("1")
|
16
|
+
assert_equal("Matheson",customer["lastname"])
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_email
|
20
|
+
customer = Magento::Customer.find("1")
|
21
|
+
assert_equal("tim.matheson@ordercup.com",customer["email"])
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_find
|
25
|
+
customer = Magento::Customer.find("1")
|
26
|
+
assert_not_nil customer
|
27
|
+
end
|
28
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
require "test_helper"
|
3
|
+
|
4
|
+
class InventoryTest < Test::Unit::TestCase
|
5
|
+
def test_creation
|
6
|
+
inventory = Magento::Inventory.new
|
7
|
+
assert_not_nil inventory
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_product_id
|
11
|
+
inventory = Magento::Inventory.list("1")[0]
|
12
|
+
assert_equal("1",inventory.product_id)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_qty
|
16
|
+
inventory = Magento::Inventory.list("1")[0]
|
17
|
+
assert_equal(10,inventory.qty.to_i)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_sku
|
21
|
+
inventory = Magento::Inventory.list("1")[0]
|
22
|
+
assert_equal("123456789",inventory.sku)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_first
|
26
|
+
inventory = Magento::Inventory.first
|
27
|
+
assert_not_nil inventory
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
File without changes
|
data/test/test_order.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
class OrderTest < Test::Unit::TestCase
|
3
|
+
def test_creation
|
4
|
+
order = Magento::Order.new
|
5
|
+
assert_not_nil order
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_find
|
9
|
+
order = Magento::Order.find("100000001")
|
10
|
+
assert_not_nil order
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_add_comment
|
14
|
+
order = Magento::Order.find("100000001")
|
15
|
+
comment_text = "This is a test comment #{rand(10)}"
|
16
|
+
order.add_comment(comment_text)
|
17
|
+
assert order.comments.map{|c| c.comment }.include?(comment_text)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_list
|
21
|
+
list = Magento::Order.list
|
22
|
+
assert !list.empty?
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_hold
|
26
|
+
assert Magento::Order.find("100000001").hold
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_unhold
|
30
|
+
assert Magento::Order.find("100000001").unhold
|
31
|
+
end
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: magento-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tim Matheson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-08-12 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Rubygem for connecting to a Magento store via the Magento Core API
|
17
|
+
email: me@timmatheson.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- lib/abstract.rb
|
24
|
+
- lib/category.rb
|
25
|
+
- lib/configuration.rb
|
26
|
+
- lib/country.rb
|
27
|
+
- lib/customer.rb
|
28
|
+
- lib/customer_address.rb
|
29
|
+
- lib/customer_groups.rb
|
30
|
+
- lib/extensions.rb
|
31
|
+
- lib/inventory.rb
|
32
|
+
- lib/invoice.rb
|
33
|
+
- lib/magento.rb
|
34
|
+
- lib/order.rb
|
35
|
+
- lib/product.rb
|
36
|
+
- lib/product_images.rb
|
37
|
+
- lib/product_types.rb
|
38
|
+
- lib/region.rb
|
39
|
+
- lib/server.rb
|
40
|
+
- lib/shipment.rb
|
41
|
+
- README.rdoc
|
42
|
+
files:
|
43
|
+
- config/magento.yml
|
44
|
+
- init.rb
|
45
|
+
- lib/abstract.rb
|
46
|
+
- lib/category.rb
|
47
|
+
- lib/configuration.rb
|
48
|
+
- lib/country.rb
|
49
|
+
- lib/customer.rb
|
50
|
+
- lib/customer_address.rb
|
51
|
+
- lib/customer_groups.rb
|
52
|
+
- lib/extensions.rb
|
53
|
+
- lib/inventory.rb
|
54
|
+
- lib/invoice.rb
|
55
|
+
- lib/magento.rb
|
56
|
+
- lib/order.rb
|
57
|
+
- lib/product.rb
|
58
|
+
- lib/product_images.rb
|
59
|
+
- lib/product_types.rb
|
60
|
+
- lib/region.rb
|
61
|
+
- lib/server.rb
|
62
|
+
- lib/shipment.rb
|
63
|
+
- Rakefile
|
64
|
+
- README.rdoc
|
65
|
+
- test/test_customer.rb
|
66
|
+
- test/test_helper.rb
|
67
|
+
- test/test_inventory.rb
|
68
|
+
- test/test_magento.rb
|
69
|
+
- test/test_order.rb
|
70
|
+
- Manifest
|
71
|
+
- magento-api.gemspec
|
72
|
+
has_rdoc: true
|
73
|
+
homepage: ""
|
74
|
+
licenses: []
|
75
|
+
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options:
|
78
|
+
- --line-numbers
|
79
|
+
- --inline-source
|
80
|
+
- --title
|
81
|
+
- Magento-api
|
82
|
+
- --main
|
83
|
+
- README.rdoc
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: "0"
|
91
|
+
version:
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: "1.2"
|
97
|
+
version:
|
98
|
+
requirements: []
|
99
|
+
|
100
|
+
rubyforge_project: magento-api
|
101
|
+
rubygems_version: 1.3.4
|
102
|
+
signing_key:
|
103
|
+
specification_version: 3
|
104
|
+
summary: Rubygem for connecting to a Magento store via the Magento Core API
|
105
|
+
test_files:
|
106
|
+
- test/test_customer.rb
|
107
|
+
- test/test_helper.rb
|
108
|
+
- test/test_inventory.rb
|
109
|
+
- test/test_magento.rb
|
110
|
+
- test/test_order.rb
|