Module: Whitehouse::Client::Order
- Included in:
- Whitehouse::Client
- Defined in:
- lib/whitehouse/client/order.rb
Overview
Methods for the Order Submit API
Constant Summary collapse
- BOUNDARY =
"-----------RubyMultipartPost"
Instance Method Summary collapse
-
#confirm_order(confirmation_id) ⇒ Boolean
Confirm order.
-
#submit_order(order) ⇒ Integer, false
Submit order.
Instance Method Details
#confirm_order(confirmation_id) ⇒ Boolean
Confirm order
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/whitehouse/client/order.rb', line 32 def confirm_order(confirmation_id) # Couldn't get faraday to build this request correctly # connection.post "OrderImport/Submit/#{confirmation_id}" url = connection.url_prefix + URI.parse("OrderImport/Submit/#{confirmation_id}") header = {"Accept" => "application/json", "Content-Type"=> "multipart/form-data; boundary=#{BOUNDARY}"} post_body = [] post_body << "--#{BOUNDARY}\r\n" post_body << "Content-Disposition: form-data; name=\"access_token\"\r\n\r\n" post_body << access_token post_body << "\r\n--#{BOUNDARY}--\r\n" # Create the HTTP objects request = Net::HTTP::Post.new(url.path, header) request.body = post_body.join http = Net::HTTP.new(url.host, url.port) http.use_ssl = true res = http.request(request) body = JSON.parse(res.body) return res.is_a?(Net::HTTPSuccess) && !body["ErrorNumber"] end |
#submit_order(order) ⇒ Integer, false
Submit order
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/whitehouse/client/order.rb', line 16 def submit_order(order) file = Tempfile.new('entry.json') file.write(order.to_json) file.close response = post 'OrderImport', {entry: Faraday::UploadIO.new(file.path, "application/json")} file.unlink if response.success? && !response.body.ErrorNumber response.body.ConfirmationID else false end end |