Class: SportsSouth::Order
Constant Summary collapse
- API_URL =
'http://webservices.theshootingwarehouse.com/smart/orders.asmx'
- SHIP_VIA =
{ ground: '', next_day: 'N', two_day: '2', three_day: '3', saturday: 'S', premium_ground: 'G', }
- STATUS =
D=Placed, E=Error placing Order, R=Placed-Verifying, W=Open
{ 'D' => :placed, 'E' => :error_placing_order, 'R' => :placed_verifying, 'W' => :open, }
Constants inherited from Base
Base::CONTENT_TYPE, Base::TIMEOUT, Base::USER_AGENT
Instance Attribute Summary collapse
-
#order_number ⇒ Object
readonly
Returns the value of attribute order_number.
-
#response_body ⇒ Object
readonly
Returns the value of attribute response_body.
Class Method Summary collapse
Instance Method Summary collapse
- #add_detail(detail = {}) ⇒ Object
- #add_header(header = {}) ⇒ Object
- #add_ship_instructions(ship_instructions = {}) ⇒ Object
- #details ⇒ Object
- #header ⇒ Object
-
#initialize(options = {}) ⇒ Order
constructor
A new instance of Order.
- #submit! ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Order
Returns a new instance of Order.
31 32 33 34 35 |
# File 'lib/sports_south/order.rb', line 31 def initialize( = {}) requires!(, :username, :password) @options = .merge(source: SportsSouth.config.source) @order_number = [:order_number] end |
Instance Attribute Details
#order_number ⇒ Object (readonly)
Returns the value of attribute order_number.
24 25 26 |
# File 'lib/sports_south/order.rb', line 24 def order_number @order_number end |
#response_body ⇒ Object (readonly)
Returns the value of attribute response_body.
23 24 25 |
# File 'lib/sports_south/order.rb', line 23 def response_body @response_body end |
Class Method Details
.find(order_number, options = {}) ⇒ Object
26 27 28 29 |
# File 'lib/sports_south/order.rb', line 26 def self.find(order_number, = {}) requires!(, :username, :password) new(.merge(order_number: order_number)) end |
Instance Method Details
#add_detail(detail = {}) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/sports_south/order.rb', line 100 def add_detail(detail = {}) raise StandardError.new("No @order_number present.") if @order_number.nil? requires!(detail, :ss_item_number, :price) detail[:quantity] = 1 unless detail.has_key?(:quantity) detail[:item_number] = '' unless detail.has_key?(:item_number) detail[:item_description] = '' unless detail.has_key?(:item_description) http, request = get_http_and_request(API_URL, '/AddDetail') request.set_form_data(form_params(@options).merge({ OrderNumber: @order_number, SSItemNumber: detail[:ss_item_number], Quantity: detail[:quantity], OrderPrice: detail[:price], CustomerItemNumber: detail[:item_number], CustomerItemDescription: detail[:item_description], })) response = http.request(request) xml_doc = Nokogiri::XML(response.body) raise SportsSouth::NotAuthenticated if not_authenticated?(xml_doc) @response_body = response.body xml_doc.content == 'true' end |
#add_header(header = {}) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/sports_south/order.rb', line 37 def add_header(header = {}) requires!(header, :purchase_order, :sales_message, :shipping) header[:customer_order_number] = header[:purchase_order] unless header.has_key?(:customer_order_number) header[:adult_signature] = false unless header.has_key?(:adult_signature) header[:signature] = false unless header.has_key?(:signature) header[:insurance] = false unless header.has_key?(:insurance) requires!(header[:shipping], :name, :address_one, :city, :state, :zip, :phone) header[:shipping][:attn] = '' unless header[:shipping].has_key?(:attn) header[:shipping][:address_two] = '' unless header[:shipping].has_key?(:address_two) header[:shipping][:via] = (header[:shipping].has_key?(:ship_via) ? SHIP_VIA[header[:shipping][:ship_via]] : SHIP_VIA[:ground]) http, request = get_http_and_request(API_URL, '/AddHeader') request.set_form_data(form_params(@options).merge({ PO: header[:purchase_order], CustomerOrderNumber: header[:customer_order_number], SalesMessage: header[:sales_message], ShipVia: header[:shipping][:via], ShipToName: header[:shipping][:name], ShipToAttn: header[:shipping][:attn], ShipToAddr1: header[:shipping][:address_one], ShipToAddr2: header[:shipping][:address_two], ShipToCity: header[:shipping][:city], ShipToState: header[:shipping][:state], ShipToZip: header[:shipping][:zip], ShipToPhone: header[:shipping][:phone], AdultSignature: header[:adult_signature], Signature: header[:signature], Insurance: header[:insurance], })) response = http.request(request) xml_doc = Nokogiri::XML(response.body) raise SportsSouth::NotAuthenticated if not_authenticated?(xml_doc) @response_body = response.body @order_number = xml_doc.content end |
#add_ship_instructions(ship_instructions = {}) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/sports_south/order.rb', line 80 def add_ship_instructions(ship_instructions = {}) requires!(ship_instructions, :order_number, :ship_inst_1, :ship_inst_2) http, request = get_http_and_request(API_URL, '/AddShipInstructions') request.set_form_data(form_params(@options).merge({ SystemOrderNumber: ship_instructions[:order_number], ShipInst1: ship_instructions[:ship_inst_1], ShipInst2: ship_instructions[:ship_inst_2], })) response = http.request(request) xml_doc = Nokogiri::XML(response.body) raise SportsSouth::NotAuthenticated if not_authenticated?(xml_doc) @response_body = response.body xml_doc.content == 'true' end |
#details ⇒ Object
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/sports_south/order.rb', line 179 def details raise StandardError.new("No @order_number present.") if @order_number.nil? http, request = get_http_and_request(API_URL, '/GetDetail') request.set_form_data(form_params(@options).merge({ CustomerOrderNumber: @order_number, OrderNumber: @order_number, })) response = http.request(request) body = sanitize_response(response) xml_doc = Nokogiri::XML(body) raise SportsSouth::NotAuthenticated if not_authenticated?(xml_doc) @response_body = body @details = [] xml_doc.css('Table').each do |table| @details << { system_order_number: content_for(table, 'ORDNO'), order_line_number: content_for(table, 'ORLINE'), customer_number: content_for(table, 'ORCUST'), order_item_number: content_for(table, 'ORITEM'), order_quantity: content_for(table, 'ORQTY'), order_price: content_for(table, 'ORPRC'), ship_quantity: content_for(table, 'ORQTYF'), ship_price: content_for(table, 'ORPRCF'), customer_item_number: content_for(table, 'ORCUSI'), customer_description: content_for(table, 'ORCUSD'), item_description: content_for(table, 'IDESC'), quantity_on_hand: content_for(table, 'QTYOH'), line_detail_comment: content_for(table, 'ORDCMT'), line_detail_po_number: content_for(table, 'ORPO2'), } end @details end |
#header ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/sports_south/order.rb', line 148 def header raise StandardError.new("No @order_number present.") if @order_number.nil? http, request = get_http_and_request(API_URL, '/GetHeader') request.set_form_data(form_params(@options).merge({ CustomerOrderNumber: @order_number, OrderNumber: @order_number })) response = http.request(request) body = sanitize_response(response) xml_doc = Nokogiri::XML(body) raise SportsSouth::NotAuthenticated if not_authenticated?(xml_doc) @response_body = body @header = { system_order_number: content_for(xml_doc, 'ORDNO'), customer_number: content_for(xml_doc, 'ORCUST'), order_po_number: content_for(xml_doc, 'ORPO'), customer_order_number: content_for(xml_doc, 'ORCONO'), order_date: content_for(xml_doc, 'ORDATE'), message: content_for(xml_doc, 'MSG'), air_code: content_for(xml_doc, 'ORAIR'), order_source: content_for(xml_doc, 'ORSRC'), status: STATUS[content_for(xml_doc, 'STATUS')], } end |
#submit! ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/sports_south/order.rb', line 129 def submit! raise StandardError.new("No @order_number present.") if @order_number.nil? http, request = get_http_and_request(API_URL, '/Submit') request.set_form_data(form_params(@options).merge({ OrderNumber: @order_number, })) response = http.request(request) xml_doc = Nokogiri::XML(response.body) raise SportsSouth::NotAuthenticated if not_authenticated?(xml_doc) @response_body = response.body xml_doc.content == 'true' end |