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', }
- STATUS =
D=Placed, E=Error placing Order, R=Placed-Verifying, W=Open
{ 'D' => :placed, 'E' => :error_placing_order, 'R' => :placed_verifying, 'W' => :open, }
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
- #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.
30 31 32 33 34 |
# File 'lib/sports_south/order.rb', line 30 def initialize( = {}) requires!(, :username, :password, :source, :customer_number) = @order_number = [:order_number] end |
Instance Attribute Details
#order_number ⇒ Object (readonly)
Returns the value of attribute order_number.
23 24 25 |
# File 'lib/sports_south/order.rb', line 23 def order_number @order_number end |
#response_body ⇒ Object (readonly)
Returns the value of attribute response_body.
22 23 24 |
# File 'lib/sports_south/order.rb', line 22 def response_body @response_body end |
Class Method Details
.find(order_number, options = {}) ⇒ Object
25 26 27 28 |
# File 'lib/sports_south/order.rb', line 25 def self.find(order_number, = {}) requires!(, :username, :password, :source, :customer_number) new(.merge({order_number: order_number})) end |
Instance Method Details
#add_detail(detail = {}) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/sports_south/order.rb', line 79 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().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
36 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 |
# File 'lib/sports_south/order.rb', line 36 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] = header[:shipping][:name] unless header.has_key?(:attn) header[:shipping][:via] = SHIP_VIA[:ground] unless header.has_key?(:ship_via) header[:shipping][:address_two] = '' unless header[:shipping].has_key?(:address_two) http, request = get_http_and_request(API_URL, '/AddHeader') request.set_form_data(form_params().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 |
#details ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/sports_south/order.rb', line 158 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().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
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/sports_south/order.rb', line 127 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().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
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/sports_south/order.rb', line 108 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().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 |