I am calling on those of you who are bilingual in both Ruby and PHP. I am using an API call to place an order. Most of the parameter are strings. However, the API call also allows a file parameter (called 'FILE' in API docs) to upload a pdf or word document. Can I simply use File.open(...) as a parameter value for the call? I do not see anything about multi-part forms in the API documentation. What is the Ruby equivalent of “@packingslip.doc” in the example below?
From the API docs, here is a description of the file parameter:
Name: packingslip, Description: Packing Slip, Format: FILE – (Only Pdf,docx and doc files are allowed)
From the API example in PHP: (most parameter omitted for clarity)
$postfields["packingslip"] = “@packingslip.doc”;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
$data = curl_exec($ch);
curl_close($ch);
I would like to be able to call the API with Net::HTTP.post (as I have been able to without the file parameter):
@result = Net::HTTP.post_form(uri, {key: key,
hash: hash,
method: 'addorder',
email: 'email@myemail.com',
address: user.address,
city: user.city
file: ??? }).body