ruby_omx 0.0.10 → 0.0.11

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.
@@ -22,6 +22,10 @@ module RubyOmx
22
22
 
23
23
  class MissingOrderOptions < RubyOmxException
24
24
  end
25
+
26
+ class MissingPurchaseOrderOptions < RubyOmxException
27
+ end
28
+
25
29
 
26
30
  class MissingItemOptions < RubyOmxException
27
31
  end
@@ -0,0 +1,19 @@
1
+ module RubyOmx
2
+ module PurchaseOrders
3
+
4
+ # Universal Direct Order Appending (UDOA)
5
+
6
+ def build_purchase_order_update_request(params={})
7
+ PurchaseOrderUpdateRequest.new(params.merge({:udi_auth_token=>@udi_auth_token, :http_biz_id=>@http_biz_id}))
8
+ end
9
+
10
+ def send_purchase_order_update_request(params={})
11
+ request = build_purchase_order_update_request(params)
12
+ response = post(request.to_xml.to_s)
13
+ return response if request.raw_xml==true || request.raw_xml==1
14
+ PurchaseOrderUpdateResponse.format(response)
15
+ end
16
+ alias_method :append_po, :send_purchase_order_update_request
17
+
18
+ end
19
+ end
@@ -0,0 +1,43 @@
1
+ module RubyOmx
2
+
3
+ class PurchaseOrderLineItem < Response
4
+ xml_name 'LineItem'
5
+ xml_accessor :line_number, :from=>'@lineNumber'
6
+ xml_accessor :item_code #
7
+ xml_accessor :quantity # required for new line, optional for update (if omitted, existing value is not changed)
8
+ xml_accessor :price # required for new line, optional for update (if omitted, existing value is not changed)
9
+ end
10
+
11
+ class PurchaseOrder < Response
12
+ xml_name 'PurchaseOrder'
13
+ xml_accessor :po_number, :from=>'@PONumber' #<PurchaseOrder PONumber="16651" supplierID="76">
14
+ xml_accessor :supplier_id, :from=>'@supplierID'
15
+ xml_accessor :line_items, :as=>[PurchaseOrderLineItem], :in => 'LineDetail'
16
+ end
17
+
18
+ class PurchaseOrderUpdateRequest < Response
19
+ def initialize(a=nil)
20
+ return super unless a.present? # bail if no array of options has been given
21
+ http_biz_id = a.delete(:http_biz_id)
22
+ udi_auth_token = a.delete(:udi_auth_token)
23
+ #udi_auth_token = a.delete(:udi_auth_token)
24
+
25
+ required_fields = [:purchase_order]
26
+ raise MissingPurchaseOrderOptions if required_fields.any? { |option| a[option].nil? }
27
+ raise MissingPurchaseOrderOptions if a[:purchase_order][:po_number].nil? && a[:purchase_order][:supplier_id].nil?
28
+ raise MissingPurchaseOrderOptions if a[:purchase_order][:line_items].nil?
29
+ super
30
+ self.version = a[:version] ||= '1.00'
31
+ self.udi_parameters = []
32
+ self.udi_parameters << UDIParameter.new({:key=>'UDIAuthToken', :value=>udi_auth_token})
33
+ self.udi_parameters << UDIParameter.new({:key=>'HTTPBizID', :value=>http_biz_id})
34
+ end
35
+
36
+ attr_accessor :raw_xml
37
+
38
+ xml_name "PurchaseOrderUpdateRequest"
39
+ xml_accessor :version, :from => '@version'
40
+ xml_accessor :udi_parameters, :as => [RubyOmx::UDIParameter], :in => 'UDIParameter'
41
+ xml_accessor :purchase_order, :as => PurchaseOrder
42
+ end
43
+ end
@@ -0,0 +1,28 @@
1
+ #<PurchaseOrderUpdateResponse>
2
+ # <Success>1</Success>
3
+ # <PurchaseOrder PONumber="16651" SupplierID="76"/>
4
+ # <PODate>2008-09-21 12:32:27</PODate>
5
+ # <TotalAmount>26.50</TotalAmount>
6
+ # <Action>New</Action> <!-- "New" if a new PO number was just assigned, "Update" if a PO number was supplied and the PO's header properties were changed, and/or a PO line was added or updated. -->
7
+ #</PurchaseOrderUpdateResponse>
8
+
9
+ #OrderInformationRequest (OIR200) This request type provides the ShippingInformationRequest (SIR) result for the order as a whole.
10
+
11
+ module RubyOmx
12
+
13
+ class PurchaseOrderResponse < Response
14
+ xml_name 'PurchaseOrder'
15
+ xml_accessor :po_number, :from=>'@PONumber' #<PurchaseOrder PONumber="16651" SupplierID="76">
16
+ xml_accessor :supplier_id, :from=>'@SupplierID'
17
+ end
18
+
19
+ class PurchaseOrderUpdateResponse < Response
20
+ xml_name "PurchaseOrderUpdateResponse"
21
+ xml_reader :success
22
+ xml_accessor :purchase_order, :as => RubyOmx::PurchaseOrderResponse
23
+ xml_accessor :po_date, :from=>'PODate', :as=>DateTime
24
+ xml_accessor :total_amount, :as=>Float
25
+ xml_accessor :action
26
+ end
27
+
28
+ end
@@ -1,13 +1,25 @@
1
1
  module RubyOmx
2
2
 
3
+ class ErrorMessage < Response
4
+ xml_name "Error"
5
+ xml_reader :message, :in => "Error", :from => :content
6
+ end
7
+
3
8
  class ResponseError < Response
4
9
  xml_name "ErrorResponse"
5
10
 
6
- xml_reader :type, :in => "Error"
7
- xml_reader :code, :in => "Error"
8
- xml_reader :message, :in => "Error"
9
- xml_reader :detail, :in => "Error"
10
- xml_reader :request_id
11
+ #xml_reader :type, :in => "Error"
12
+ #xml_reader :code, :in => "Error"
13
+ #xml_reader :message, :in => "Error"
14
+ #xml_reader :detail, :in => "Error"
15
+ #xml_reader :request_id
16
+ xml_reader :success
17
+ xml_reader :errors, :as=>[ErrorMessage]
18
+
19
+ def to_s
20
+ self.errors.join(',')
21
+ end
22
+
11
23
  end
12
24
 
13
25
  end
@@ -44,6 +44,8 @@ module RubyOmx
44
44
 
45
45
  end
46
46
 
47
+ # Shared classes
48
+
47
49
  class UDIParameter < Response
48
50
  xml_name "Parameter"
49
51
  xml_accessor :key, :from => '@key'
@@ -1,3 +1,3 @@
1
1
  module RubyOmx
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.11"
3
3
  end
data/lib/ruby_omx.rb CHANGED
@@ -32,6 +32,7 @@ end
32
32
  require 'ruby_omx/response'
33
33
  require 'ruby_omx/orders'
34
34
  require 'ruby_omx/items'
35
+ require 'ruby_omx/purchase_orders'
35
36
  Dir.glob(File.join(File.dirname(__FILE__), 'ruby_omx/response/*.rb')).each {|f| require f }
36
37
 
37
38
  require 'ruby_omx/base'
@@ -42,4 +43,5 @@ require 'ruby_omx/connection'
42
43
  RubyOmx::Base.class_eval do
43
44
  include RubyOmx::Orders
44
45
  include RubyOmx::Items
46
+ include RubyOmx::PurchaseOrders
45
47
  end
@@ -0,0 +1,57 @@
1
+ require 'test_helper'
2
+
3
+ class PurchaseOrdersTest < MiniTest::Unit::TestCase
4
+ def setup
5
+ @config = YAML.load_file( File.join(File.dirname(__FILE__), 'test_config.yml') )['test']
6
+ @connection = RubyOmx::Base.new(@config)
7
+
8
+ @line1 = { :item_code=>'WATCH-1', :quantity => 1, :price => 122.50 }
9
+ @line2 = { :item_code=>'APPLE-12', :quantity => 31, :price => 1.50 }
10
+ end
11
+
12
+ def test_request_from_xml
13
+ request = RubyOmx::PurchaseOrderUpdateRequest.format(xml_for('PurchaseOrderUpdateRequest(1.00)',200))
14
+ assert_equal '1.00', request.version
15
+ assert_equal '16651', request.purchase_order.po_number
16
+ assert_equal '76', request.purchase_order.supplier_id
17
+ assert_equal 2, request.purchase_order.line_items.length
18
+ assert_equal @line1[:item_code], request.purchase_order.line_items[0].item_code
19
+ assert_equal @line2[:item_code], request.purchase_order.line_items[1].item_code
20
+
21
+ assert_equal 'UDIAuthToken', request.udi_parameters[0].key
22
+ assert_equal @config['udi_auth_token'], request.udi_parameters[0].value
23
+ end
24
+
25
+ def test_send_purchase_order_update_request
26
+ @connection.stubs(:post).returns(xml_for('PurchaseOrderUpdateResponse(1.00)',200))
27
+ request = PurchaseOrderUpdateRequest.new
28
+ po_data = { :purchase_order => {
29
+ :po_number => '16651',
30
+ :supplier_id => '76',
31
+ :line_items => [@line1, @line2]
32
+ }
33
+ }
34
+
35
+ # Missing Order Options
36
+ begin
37
+ response = @connection.send_purchase_order_update_request({})
38
+ rescue MissingPurchaseOrderOptions
39
+ end
40
+
41
+ response = @connection.send_purchase_order_update_request(po_data)
42
+ assert_kind_of PurchaseOrderUpdateResponse, response
43
+ assert_equal '1', response.success
44
+ assert_equal DateTime.parse('2008-09-21 12:32:27'), response.po_date
45
+ assert_equal '16651', response.purchase_order.po_number
46
+ assert_equal '76', response.purchase_order.supplier_id
47
+ assert_kind_of Hash, response.as_hash
48
+
49
+ response = @connection.send_purchase_order_update_request(po_data.merge({:raw_xml => true}))
50
+ assert_kind_of Net::HTTPOK, response
51
+
52
+ # old alias should still work
53
+ response = @connection.append_po(po_data)
54
+ assert_kind_of PurchaseOrderUpdateResponse, response
55
+ assert_equal '16651', response.purchase_order.po_number
56
+ end
57
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_omx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-06 00:00:00.000000000 Z
12
+ date: 2012-08-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: roxml
@@ -71,10 +71,13 @@ files:
71
71
  - lib/ruby_omx/exceptions.rb
72
72
  - lib/ruby_omx/items.rb
73
73
  - lib/ruby_omx/orders.rb
74
+ - lib/ruby_omx/purchase_orders.rb
74
75
  - lib/ruby_omx/response/custom_item_attr_info_response.rb
75
76
  - lib/ruby_omx/response/item_info_response.rb
76
77
  - lib/ruby_omx/response/order_info_request.rb
77
78
  - lib/ruby_omx/response/order_info_response.rb
79
+ - lib/ruby_omx/response/purchase_order_update_request.rb
80
+ - lib/ruby_omx/response/purchase_order_update_response.rb
78
81
  - lib/ruby_omx/response/response_error.rb
79
82
  - lib/ruby_omx/response/smart_report_response.rb
80
83
  - lib/ruby_omx/response/udoa_request.rb
@@ -88,6 +91,7 @@ files:
88
91
  - test/base_test.rb
89
92
  - test/items_test.rb
90
93
  - test/orders_test.rb
94
+ - test/purchase_orders_test.rb
91
95
  - test/test_config.yml
92
96
  - test/test_helper.rb
93
97
  homepage: http://github.com/aew/ruby_omx
@@ -118,5 +122,6 @@ test_files:
118
122
  - test/base_test.rb
119
123
  - test/items_test.rb
120
124
  - test/orders_test.rb
125
+ - test/purchase_orders_test.rb
121
126
  - test/test_config.yml
122
127
  - test/test_helper.rb