ruby_omx 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,75 +1,48 @@
1
1
  module RubyOmx
2
2
  module Orders
3
3
 
4
- def build_udoa_request(params)
4
+ # Universal Direct Order Appending (UDOA)
5
+
6
+ def build_udoa_request(params={})
5
7
  UDOARequest.new(params.merge({:http_biz_id=>@http_biz_id, :udi_auth_token=>@udi_auth_token}))
6
8
  end
7
9
 
8
- def send_udoa_request(params)
10
+ def send_udoa_request(params={})
9
11
  request = build_udoa_request(params)
10
12
  response = post(request.to_xml.to_s)
11
- if request.raw_xml==true || request.raw_xml==1
12
- return response
13
- end
13
+ return response if request.raw_xml==true || request.raw_xml==1
14
14
  UDOAResponse.format(response)
15
15
  end
16
+ alias_method :append_order, :send_udoa_request
17
+
18
+
19
+ # Order Information
16
20
 
17
- def append_order(params={})
18
- send_udoa_request(params)
21
+ def build_info_request(params={})
22
+ OrderInformationRequest.new(params.merge({:http_biz_id=>@http_biz_id}))
19
23
  end
20
24
 
21
- =begin
22
- #UniversalDirectOrderAppending (UDOA200) This request type is used to create orders in the application.
23
- def append_order(params ={})
24
-
25
- required_fields = [
26
- params[:keycode],
27
- params[:queue_flag],
28
- params[:verify_flag],
29
- params[:order_date],
30
- params[:order_id],
31
- params[:last_name],
32
- params[:line_items],
33
- params[:method_code],
34
- params[:total_amount]
35
- ]
36
- raise MissingOrderOptions if required_fields.any? {|option| option.nil?}
37
-
38
- raw_xml = params[:raw_xml] ||= false
25
+ def send_info_request(params={})
26
+ request = build_info_request(params)
27
+ response = post(request.to_xml.to_s)
28
+ return response if request.raw_xml==true || request.raw_xml==1
29
+ OrderInformationResponse.format(response)
30
+ end
31
+
32
+
33
+ # Smart Report Information
34
+
35
+ def send_smart_report_request(params={})
36
+ schedule_id = params[:schedule_id] ||= 1
37
+ response = get("https://omx.ordermotion.com/en/net/SmartReports.aspx?HTTPBizID=#{@http_biz_id}&ScheduleID=#{schedule_id}")
38
+ SmartReportResponse.format(response)
39
+ end
40
+
41
+ end
42
+ end
39
43
 
40
- doc = Nokogiri::XML::Document.new
41
- root_tag = RubyOmx.add_child_helper(doc,'UDOARequest','version','2.00',nil)
42
-
43
- udi_parameter = RubyOmx.add_child_helper(root_tag,'UDIParameter',nil,nil,nil)
44
- RubyOmx.add_child_helper(udi_parameter,'Parameter','key','HTTPBizID',@http_biz_id)
45
- RubyOmx.add_child_helper(udi_parameter,'Parameter','key','UDIAuthToken',@udi_auth_token)
46
- RubyOmx.add_child_helper(udi_parameter,'Parameter','key','QueueFlag',params[:queue_flag] ||= 'False') # Determines whether any orders with errors will be stored in the OrderMotion "Outside Order Queue", to be corrected by an OrderMotion user before resubmission. If set to "True", almost all orders will be accepted by OrderMotion, but additional order information will only be returned in the response if the order is successfully placed. Otherwise, any order with any error (eg invalid ZIP code) will be rejected.
47
- RubyOmx.add_child_helper(udi_parameter,'Parameter','key','Keycode',params[:keycode])
48
- RubyOmx.add_child_helper(udi_parameter,'Parameter','key','VerifyFlag',params[:verify_flag] ||= 'True') # Determines whether a successful order should be saved, or only verified/calculated. When set to "True", OrderMotion will behave as if the order was placed, but not return an Order Number in the response.
49
- RubyOmx.add_child_helper(udi_parameter,'Parameter','key','Vendor',params[:vendor] ||= nil)
50
-
51
- header = RubyOmx.add_child_helper(root_tag,'Header',nil,nil,nil)
52
- RubyOmx.add_child_helper(header,'StoreCode',nil,nil,params[:store_code] ||= '')
53
- RubyOmx.add_child_helper(header,'OrderID',nil,nil,params[:order_id])
54
- RubyOmx.add_child_helper(header,'OrderDate',nil,nil,params[:order_date]) # Dates are almost the same as the W3C Schema "date" type, but with a space instead of the "T" separating the date from the time.
55
- RubyOmx.add_child_helper(header,'OriginType',nil,nil,params[:origin_type] ||= '2') # 2 = phone order, 3 = internet order
56
-
57
- customer = RubyOmx.add_child_helper(root_tag,'Customer',nil,nil,nil)
58
- address = RubyOmx.add_child_helper(customer,'Address','type','BillTo',nil)
59
- RubyOmx.add_child_helper(address,'TitleCode',nil,nil,params[:title_code] ||= '0')
60
- RubyOmx.add_child_helper(address,'Firstname',nil,nil,params[:first_name] ||= 'Test')
61
- RubyOmx.add_child_helper(address,'Lastname',nil,nil,params[:last_name] ||= 'Test')
62
- RubyOmx.add_child_helper(address,'Address1',nil,nil,params[:address1] ||= nil)
63
- RubyOmx.add_child_helper(address,'Address2',nil,nil,params[:address2] ||= nil)
64
- RubyOmx.add_child_helper(address,'City',nil,nil,params[:city] ||=nil)
65
- RubyOmx.add_child_helper(address,'State',nil,nil,params[:state] ||= nil)
66
- RubyOmx.add_child_helper(address,'ZIP',nil,nil,params[:zip] ||=nil)
67
- RubyOmx.add_child_helper(address,'TLD',nil,nil,params[:tld] ||=nil)
68
- RubyOmx.add_child_helper(address,'PhoneNumber',nil,nil,params[:phone] ||= nil)
69
- RubyOmx.add_child_helper(address,'Email',nil,nil,params[:email] ||= nil)
70
-
71
- shipping_info = RubyOmx.add_child_helper(root_tag,'ShippingInformation',nil,nil,nil)
72
-
44
+
45
+ =begin
73
46
  # Shipping Methods (numeric inputs to MethodCode)
74
47
  # 0 UPS Ground (1-4 Days Transit Time) 0.00
75
48
  # 2 Drop-Ship Montague 1 40.00
@@ -93,72 +66,12 @@ module RubyOmx
93
66
  # 19 Next Day Air (USA Only) 0.00
94
67
  # 20 2nd Day Air (USA Only) 0.00
95
68
  # 21 Priority Mail (Free $74.99 and above), 3-6 days 0.00
96
- RubyOmx.add_child_helper(shipping_info,'MethodCode',nil,nil,params[:method_code])
97
-
98
- # address = RubyOmx.add_child_helper(shipping_info,'Address','type','ShipTo',nil)
99
- # RubyOmx.add_child_helper(address,'TitleCode',nil,nil,'0')
100
- # RubyOmx.add_child_helper(address,'Firstname',nil,nil,'Test') #TODO capture the first and last name for billing, not just shipping
101
- # RubyOmx.add_child_helper(address,'Lastname',nil,nil,'Test')
102
- # RubyOmx.add_child_helper(address,'Address1',nil,nil,'251 West 30th St')
103
- # RubyOmx.add_child_helper(address,'Address2',nil,nil,'Apt 12E')
104
- # RubyOmx.add_child_helper(address,'City',nil,nil,'New York')
105
- # RubyOmx.add_child_helper(address,'State',nil,nil,'NY')
106
- # RubyOmx.add_child_helper(address,'ZIP',nil,nil,'10001')
107
- # RubyOmx.add_child_helper(address,'TLD',nil,nil,'US')
108
- # RubyOmx.add_child_helper(address,'PhoneNumber',nil,nil,nil)
109
- # RubyOmx.add_child_helper(address,'Email',nil,nil,nil)
110
- RubyOmx.add_child_helper(shipping_info,'ShippingAmount',nil,nil,params[:shipping_amount] ||= '0.00')
111
- #RubyOmx.add_child_helper(shipping_info,'HandlingAmount',nil,nil,'0')
112
- #RubyOmx.add_child_helper(shipping_info,'SpecialInstructions',nil,nil,'0')
113
- RubyOmx.add_child_helper(shipping_info,'GiftWrapping',nil,nil,params[:gift_wrapping] ||= 'False')
114
- RubyOmx.add_child_helper(shipping_info,'GiftMessage',nil,nil,params[:gift_message] ||= nil)
115
-
116
- payment_type = RubyOmx.add_child_helper(root_tag,'Payment','type',params[:payment_type] ||= '6',nil) #6 for open invoice
117
- # RubyOmx.add_child_helper(payment_type,'CardNumber',nil,nil,'4111111111111111')
118
- # RubyOmx.add_child_helper(payment_type,'CardVerification',nil,nil,'222')
119
- # RubyOmx.add_child_helper(payment_type,'CardExpDateMonth',nil,nil,'09')
120
- # RubyOmx.add_child_helper(payment_type,'CardExpDateYear',nil,nil,'2011')
121
- # RubyOmx.add_child_helper(payment_type,'CardStatus',nil,nil,'11')
122
- # RubyOmx.add_child_helper(payment_type,'CardAuthCode',nil,nil,'11')
123
- # RubyOmx.add_child_helper(payment_type,'CardTransactionID',nil,nil,'123456789')
124
-
125
- order_detail = RubyOmx.add_child_helper(root_tag,'OrderDetail',nil,nil,nil)
126
-
127
- i=1
128
- params[:line_items].each do |item|
129
- raise MissingItemOptions if item[:item_code].nil?
130
- line_item = RubyOmx.add_child_helper(order_detail,'LineItem','lineNumber',i.to_s,nil)
131
- RubyOmx.add_child_helper(line_item,'ItemCode',nil,nil,item[:item_code])
132
- RubyOmx.add_child_helper(line_item,'Quantity',nil,nil,item[:quantity] ||= '1')
133
- if !item[:unit_price].nil?
134
- RubyOmx.add_child_helper(line_item,'UnitPrice',nil,nil,item[:unit_price])
135
- end
136
- #RubyOmx.add_child_helper(line_item,'StandingOrder','configurationID','5',nil)
137
- #customization = RubyOmx.add_child_helper(line_item,'ItemCustomizationData',nil,nil,nil)
138
- #field = RubyOmx.add_child_helper(customization,'CustomizationField','fieldID','127',nil)
139
- #RubyOmx.add_child_helper(field,'Value',nil,nil,'demoText')
140
- i+=1
141
- end
142
-
143
- check = RubyOmx.add_child_helper(root_tag,'Check',nil,nil,nil)
144
- RubyOmx.add_child_helper(check,'TotalAmount',nil,nil,params[:total_amount])
145
-
146
- response = post(doc.to_xml)
147
- if raw_xml==true || raw_xml==1
148
- return response
149
- else
150
- UDOAResponse.format(response)
151
- end
152
- end
153
69
 
154
70
  #OrderDetailUpdateRequest (ODUR100) This request type enables you to update certain data for orders.
155
71
  #CancellationHistoryRequest (CHR100) This request type lists all the cancellations that have occurred between two dates.
156
72
  #InvoiceProcessRequest (IPR100) This command takes an order number, and runs the invoicing and credit memo processes against the order if there are any order lines that can be subject to an invoice or credit memo, or if there are returns on the order.
157
73
  #OrderCancellationRequest (OCR100) This request type enables you to cancel some or all the line items in an order.
158
- #OrderInformationRequest (OIR200) This request type provides the ShippingInformationRequest (SIR) result for the order as a whole.
159
74
  #OrderSecondaryStatusUpdateRequest (OSSUR100) This request type enables you to set the secondary status of the OrderLines.
160
75
  #OrderUpdateRequest (OUR200) This request type enables you to change the Payment Plan of an order, as well as the basis date for payment plan calculation, and also update the "Alt ID 2" (a.k.a "Reference") field of the order.
161
76
  #OrderWaitDateUpdateRequest (OWDUR100) This request type enables you to change the Wait Date of an existing order.
162
- =end
163
- end
164
- end
77
+ =end
@@ -0,0 +1,31 @@
1
+ #$wtf = "https://api.omx.ordermotion.com/hdde/xml/udi.asp?Wrapper=1&RequestType=OrderInformationRequest&RequestVersion=1.00&HTTPBizID=".BIZ_ID."&OrderNumber=".$OMorderid."&level=$level";
2
+ module RubyOmx
3
+
4
+ class UDIParameter < Response
5
+ xml_name "Parameter"
6
+ xml_accessor :key, :from => '@key'
7
+ xml_accessor :value, :from => :content
8
+ end
9
+
10
+ class OrderInformationRequest < Response
11
+ def initialize(a=nil)
12
+ return super unless a.present? # bail if no array of options has been given
13
+ http_biz_id = a.delete(:http_biz_id)
14
+ #udi_auth_token = a.delete(:udi_auth_token)
15
+
16
+ required_fields = [:order_number]
17
+ raise MissingOrderOptions if required_fields.any? { |option| a[option].nil? }
18
+ super
19
+ self.version = a[:version] ||= '1.00'
20
+ self.udi_parameters = [ RubyOmx::UDIParameter.new({:key=>'HTTPBizID', :value=>http_biz_id}),
21
+ RubyOmx::UDIParameter.new({:key=>'OrderNumber', :value=>a[:order_number]}),
22
+ RubyOmx::UDIParameter.new({:key=>'level', :value=>a[:level] ||=0 })]
23
+ end
24
+
25
+ attr_accessor :order_number, :raw_xml
26
+
27
+ xml_name "OrderInformationRequest"
28
+ xml_accessor :version, :from => '@version'
29
+ xml_accessor :udi_parameters, :as => [RubyOmx::UDIParameter], :in => 'UDIParameter'
30
+ end
31
+ end
@@ -0,0 +1,55 @@
1
+ #OrderInformationRequest (OIR200) This request type provides the ShippingInformationRequest (SIR) result for the order as a whole.
2
+
3
+ module RubyOmx
4
+
5
+ class OrderInfoLineStatus < Response
6
+ xml_name "LineStatus"
7
+ #<LineStatus date="2/9/2006 2:47:00 PM" text="OK">40</LineStatus>
8
+ xml_reader :text, :from => '@text' # C/L means cancelled, OK with a date means processing
9
+ xml_reader :date, :from => '@date', :as=>DateTime # cancellation date if cancelled, processing date if processing
10
+ xml_reader :value, :from => :content, :as=>Integer
11
+ end
12
+
13
+ class OrderInfoOrderHeader < Response
14
+ xml_name "OrderHeader"
15
+ xml_reader :order_id
16
+ xml_reader :order_number
17
+ xml_reader :order_date, :as=>DateTime
18
+ end
19
+
20
+ class OrderInfoLineItem < Response
21
+ xml_name "LineItem"
22
+ xml_reader :item_code
23
+ xml_reader :product_name
24
+ xml_reader :quantity
25
+ xml_reader :price
26
+ xml_reader :line_status, :as=>OrderInfoLineStatus
27
+ xml_reader :warehouse_reference
28
+ xml_reader :tracking_number
29
+ xml_reader :line_cogs, :from=>'LineCOGS', :as=>Float
30
+ xml_reader :unit_cogs, :from=>'UnitCOGS', :as=>Float
31
+ xml_reader :supplier_item_code
32
+
33
+
34
+ # OMX Status Codes
35
+ # 0 complete?, Order cancelled at
36
+ # 1 cancelled?
37
+ # 2
38
+ # 3
39
+ # 4 Order entered processing at
40
+ # 5
41
+ # 6 complete?, All items shipped
42
+ # 7 shipped?
43
+ end
44
+
45
+ class OrderInformationResponse < Response
46
+ xml_name "OrderInformationResponse"
47
+ xml_reader :order_header, :as=>OrderInfoOrderHeader
48
+ #xml_reader :shipping_information, :as=>OrderInfoShippingInfo
49
+ xml_reader :line_items, :as => [OrderInfoLineItem], :in=>'OrderDetail'
50
+
51
+ xml_reader :tracking_number, :in=>'ShippingInformation/Shipment'
52
+ xml_reader :ship_date, :in=>'ShippingInformation/Shipment',:as=>DateTime # if populated, it means all items have shipped
53
+ end
54
+
55
+ end
@@ -0,0 +1,30 @@
1
+ module RubyOmx
2
+
3
+ class SmartReportField < Response
4
+ xml_name "Field"
5
+ xml_reader :id, :from=>'@fieldID'
6
+ xml_reader :value, :from=>:content
7
+ end
8
+
9
+ class SmartReportRow < Response
10
+ xml_name "Row"
11
+ xml_reader :fields, :as=>[SmartReportField]
12
+ #1 Order Number
13
+ #2 Alt ID
14
+ #3 Product SKU
15
+ #4 Product Name
16
+ #5 Quantity
17
+ #6 Price
18
+ #7 Customer Number
19
+ #8 Customer Name
20
+ #10 Shipping Type
21
+ #11 Supplier Id
22
+ #12 Supplier Name
23
+ end
24
+
25
+ class SmartReportResponse < Response
26
+ xml_name "SmartReportResultXml"
27
+ xml_reader :rows, :as=>[SmartReportRow], :in=>'Detail'
28
+ end
29
+
30
+ end
@@ -1,10 +1,4 @@
1
1
  module RubyOmx
2
-
3
- class UDIParameter < Response
4
- xml_name "Parameter"
5
- xml_accessor :key, :from => '@key'
6
- xml_accessor :value, :from => :content
7
- end
8
2
 
9
3
  class Address < Response
10
4
  xml_name "Address"
@@ -75,7 +69,7 @@ module RubyOmx
75
69
 
76
70
  xml_name "UDOARequest"
77
71
  xml_accessor :version, :from => '@version'
78
- xml_accessor :udi_parameters, :as => [UDIParameter], :in => 'UDIParameter'
72
+ xml_accessor :udi_parameters, :as => [RubyOmx::UDIParameter], :in => 'UDIParameter'
79
73
  xml_accessor :order_date, :in => 'Header', :as => DateTime # Dates are almost the same as the W3C Schema "date" type, but with a space instead of the "T" separating the date from the time.
80
74
  xml_accessor :order_id, :in => 'Header', :from => 'OrderID'
81
75
  xml_accessor :origin_type, :in => 'Header'
@@ -5,10 +5,8 @@ module RubyOmx
5
5
  xml_convention :camelcase
6
6
 
7
7
  def initialize(object_attribute_hash=nil)
8
- if !object_attribute_hash.nil?
9
- object_attribute_hash.map { |(k, v)| send("#{k}=", v) }
10
- end
11
- end
8
+ object_attribute_hash.map { |(k, v)| send("#{k}=", v) } if object_attribute_hash.present?
9
+ end
12
10
 
13
11
  # This is the factoryish method that is called!, not new
14
12
  def self.format(response)
@@ -1,3 +1,3 @@
1
1
  module RubyOmx
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
data/test/orders_test.rb CHANGED
@@ -164,7 +164,6 @@ class OrdersTest < MiniTest::Unit::TestCase
164
164
  rescue MissingOrderOptions
165
165
  end
166
166
 
167
- # Should work
168
167
  order_data[:line_items][0].merge!({ :item_code => 'SKU' })
169
168
  response = @connection.send_udoa_request(order_data)
170
169
 
@@ -183,4 +182,38 @@ class OrdersTest < MiniTest::Unit::TestCase
183
182
  assert_kind_of UDOAResponse, response
184
183
  assert_equal 'OMX-ofyccytnacrtnedlldmyed', response.OMX
185
184
  end
185
+
186
+ def test_send_info_request
187
+ @connection.stubs(:post).returns(xml_for('OrderInformationResponse(1.00)',200))
188
+ response = @connection.send_info_request({ :order_number => '16651' })
189
+ assert_kind_of OrderInformationResponse, response
190
+ assert !response.accessors.include?("code")
191
+
192
+ assert_equal DateTime.parse('2006-02-09 14:47:00'), response.ship_date
193
+ assert_equal "", response.tracking_number
194
+ assert_equal '16651', response.order_header.order_number
195
+ assert_equal DateTime.parse('2005-06-20 14:25:00'), response.order_header.order_date
196
+ assert_equal 1, response.line_items.length
197
+ assert_equal 6.52, response.line_items[0].line_cogs
198
+ assert_equal 6.52, response.line_items[0].unit_cogs
199
+ assert_equal '01-113', response.line_items[0].supplier_item_code
200
+ assert_equal '01-113', response.line_items[0].item_code
201
+ assert_instance_of OrderInfoLineStatus, response.line_items[0].line_status
202
+ assert_equal "OK", response.line_items[0].line_status.text
203
+ assert_equal 40, response.line_items[0].line_status.value
204
+ assert_equal DateTime.parse('2/9/2006 2:47:00 PM'), response.line_items[0].line_status.date
205
+ assert_kind_of Hash, response.as_hash
206
+ end
207
+
208
+ def test_send_smart_report_request
209
+ @connection.stubs(:get).returns(xml_for('SmartReports',200))
210
+ response = @connection.send_smart_report_request
211
+ assert_kind_of SmartReportResponse, response
212
+ assert_equal 2, response.rows.length
213
+ assert_equal 12, response.rows[0].fields.length
214
+ assert_equal '1', response.rows[0].fields[0].id
215
+ assert_equal '12432343', response.rows[0].fields[0].value
216
+ assert_kind_of Hash, response.as_hash
217
+ end
218
+
186
219
  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.7
4
+ version: 0.0.8
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-04-30 00:00:00.000000000 Z
12
+ date: 2012-08-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: roxml
@@ -73,7 +73,10 @@ files:
73
73
  - lib/ruby_omx/orders.rb
74
74
  - lib/ruby_omx/response/custom_item_attr_info_response.rb
75
75
  - lib/ruby_omx/response/item_info_response.rb
76
+ - lib/ruby_omx/response/order_info_request.rb
77
+ - lib/ruby_omx/response/order_info_response.rb
76
78
  - lib/ruby_omx/response/response_error.rb
79
+ - lib/ruby_omx/response/smart_result_response.rb
77
80
  - lib/ruby_omx/response/udoa_request.rb
78
81
  - lib/ruby_omx/response/udoa_response.rb
79
82
  - lib/ruby_omx/response.rb
@@ -107,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
110
  version: '0'
108
111
  requirements: []
109
112
  rubyforge_project:
110
- rubygems_version: 1.8.22
113
+ rubygems_version: 1.8.24
111
114
  signing_key:
112
115
  specification_version: 3
113
116
  summary: Ruby wrapper for OrderMotion (OMX)