exigo 0.0.1 → 0.0.3

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.3
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{exigo}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["David Moulton"]
12
- s.date = %q{2011-05-12}
12
+ s.date = %q{2011-05-24}
13
13
  s.description = %q{provides access to exigo's API without 'very much' knowledge of soap}
14
14
  s.email = %q{dave@themoultons.net}
15
15
  s.extra_rdoc_files = [
@@ -1,7 +1,7 @@
1
1
  require 'savon'
2
2
 
3
3
  class Exigo
4
- attr_accessor :username,:password,:company,:wsdl,:namespacer
4
+ attr_accessor :username,:password,:company,:wsdl,:namespacer, :transaction_details
5
5
 
6
6
  def initialize(username,password,company)
7
7
  @username = username
@@ -12,19 +12,66 @@ class Exigo
12
12
  end
13
13
 
14
14
  def method_missing(name, *args, &block)
15
+ payload = args[0].each_with_object({}) { |(k,v), h| h["api:#{k}"] = v }
16
+
17
+ make_request(name,payload)
18
+ end
19
+
20
+ # Not yet complete
21
+ def new_order(shipping_info,order_properties,distributor_id,create_customer=true, test=false)
22
+ ship_to = {"api:FirstName" => shipping_info["api:FirstName"],
23
+ "api:LastName" => shipping_info["api:LastName"],
24
+ "api:Email" => shipping_info["api:Email"],
25
+ "api:Phone" => shipping_info["api:Phone"],
26
+ "api:Address1" => shipping_info["api:MainAddress1"],
27
+ "api:City" => shipping_info["api:MainCity"],
28
+ "api:State" => shipping_info["api:MainState"],
29
+ "api:Zip" => shipping_info["api:MainZip"],
30
+ "api:Country" => shipping_info["api:MainCountry"],
31
+
32
+ }
33
+ ret = { :success => true }
34
+ order_id = nil
35
+ begin
36
+ if create_customer
37
+ cc_res = make_request("create_customer", shipping_info)
38
+
39
+ ret[:new_customer_id] = cc_res[:customer_id]
40
+
41
+ order_info = ship_to.merge(order_properties)
42
+
43
+ order_res = make_request("create_order",order_info)
44
+ ret[:order_id] = order_res[:order_id]
45
+ end
46
+ rescue Exception=>e
47
+ ret[:success] = false
48
+ ret[:error] = e.to_s
49
+
50
+ if ret[:order_id]
51
+
52
+ #TODO: cancel order if there is an error after its created
53
+ end
54
+ end
55
+
56
+ ret
57
+ end
58
+
59
+ protected
60
+
61
+ def make_request(name,payload)
15
62
  client = Savon::Client.new @wsdl
16
63
  ns = @namespacer
17
64
  auth = { "api:LoginName"=>@username, "api:Password"=>@password, "api:Company"=>@company }
18
- payload = args[0].each_with_object({}) { |(k,v), h| h["api:#{k}"] = v }
19
65
  action = name.to_s.camelcase
20
-
66
+
21
67
  response = client.request "api:#{action}Request" do
22
- http.headers["SOAPAction"] = "\"#{ns}#{action}\""
68
+ http.headers["SOAPAction"] = "\"#{ns}#{action}\""
23
69
  soap.namespaces["xmlns:env"] = "http://schemas.xmlsoap.org/soap/envelope/"
24
70
  soap.namespaces["xmlns:api"] = ns
25
71
  soap.header = { "api:ApiAuthentication" => auth }
26
72
  soap.body = payload
27
73
  end
74
+
28
75
  response.to_hash["#{name}_result".to_sym]
29
76
  end
30
77
  end
@@ -1,4 +1,4 @@
1
- class Test::Unit::TestCase
1
+
2
2
  # A valid API user for logging into api.exigo.com
3
3
  API_USERNAME = 'username'
4
4
  API_PASSWORD = 'password'
@@ -7,5 +7,16 @@ class Test::Unit::TestCase
7
7
  # A valid user in exigo that the api user has access to
8
8
  EXIGO_USERNAME = 'username'
9
9
  EXIGO_PASSWORD = 'password'
10
- EXIGO_ID = 123
11
- end
10
+ EXIGO_ID = 123
11
+
12
+ # Other implementation specific data
13
+ CURRENCY_CODE = "usd"
14
+ INITIAL_ORDER_STATUS = 0
15
+ SUCCESSFUL_ORDER_STATUS = 0
16
+ FAILED_ORDER_STATUS = 0
17
+ WAREHOUSE_ID = 0
18
+ SHIPPING_METHOD = 0
19
+ PRICE_TYPE = 0
20
+ ITEM_CODE = ""
21
+ ORDER_TYPE = "Default"
22
+ TEST_PRODUCT = ""
@@ -16,4 +16,50 @@ class TestExigo < Test::Unit::TestCase
16
16
  assert res[:result][:status] == "Success"
17
17
  assert_equal EXIGO_ID.to_s, res[:customer_id]
18
18
  end
19
+
20
+ should "create a new customer and a new order in exigo" do
21
+ conn = Exigo.new(API_USERNAME,API_PASSWORD,API_COMPANY)
22
+
23
+ customer = {"api:FirstName" => "Test",
24
+ "api:LastName" => "User",
25
+ "api:CustomerType" => "10",
26
+ "api:Email" => "test3254@example.com",
27
+ "api:Phone" => "8015551212",
28
+ "api:MainAddress1" => "123 Main St",
29
+ "api:MainCity" => "Salt Lake City",
30
+ "api:MainState" => "UT",
31
+ "api:MainZip" => "84001",
32
+ "api:MainCountry" => "US",
33
+ "api:CanLogin" => false,
34
+ "api:EnrollerID" => EXIGO_ID,
35
+ "api:InsertEnrollerTree" => "true",
36
+ "api:SponsorID" => EXIGO_ID,
37
+ "api:InsertUnilevelTree" => "true"
38
+ }
39
+
40
+ order_properties = { "api:CustomerID" => EXIGO_ID,
41
+ "api:OrderStatus" => "CCPending",
42
+ "api:CurrencyCode" => "usd",
43
+ "api:OrderType" => "APIOrder",
44
+ "api:OrderDate" => Time.now,
45
+ "api:WarehouseID" => 5,
46
+ "api:ShipMethodID" => 6,
47
+ "api:PriceType" => 1,
48
+ "api:Details" => { "api:OrderDetailRequest" => { "api:ItemCode" => TEST_PRODUCT,"api:Quantity" => 1 } } }
49
+
50
+ res = conn.new_order(customer,order_properties, EXIGO_ID, true, true)
51
+ assert_equal true,res[:success]
52
+ puts res.inspect
53
+
54
+ c = conn.get_customers(:CustomerID => res[:new_customer_id])
55
+ assert_equal("test3254@example.com",c[:customers][:customer_response][:email], "New customer not correct")
56
+
57
+ # delete user
58
+ if (res[:new_customer_id])
59
+ d = conn.update_customer(:CustomerID => res[:new_customer_id], :CustomerStatus => 0)
60
+ assert_equal "Success", d[:result][:status]
61
+ end
62
+
63
+
64
+ end
19
65
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: exigo
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - David Moulton
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-12 00:00:00 -06:00
13
+ date: 2011-05-24 00:00:00 -06:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -116,7 +116,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
116
  requirements:
117
117
  - - ">="
118
118
  - !ruby/object:Gem::Version
119
- hash: -4349311301346426398
119
+ hash: -2741708506165734724
120
120
  segments:
121
121
  - 0
122
122
  version: "0"