0

Given I have this, using Ruby 1.9.3p194

Authentication is digestauth

require 'json'
require 'httpclient'

API_URL= "https://api.somewhere.com/upload"
API_KEY='blahblah'
API_SECRET ='blahlbah'
IMAGE ='someimage.png'

h=HTTPClient.new
h.set_auth(API_URL, API_KEY, API_SECRET)

File.open(IMAGE) do |file|
  body = { 'image' => file}
  res = h.post(API_URL, body)
  p res.inspect
end

I get errors

Ive tried Typheous, Patron, Mechanize, Curl but want to find a way that is simple and works e.g.

curl --digest -u myusrname:password  -F "image=@image.png" "https://api.somewhere.com/upload"

Curl posts nothing and doesnt work as expected. Ive been assured that the API accepts posts, I have a simple web page that does what I need to do via a simple form and it works fine

Any one know what the easiest way ahead is?

Thanks

user1320651
  • 808
  • 2
  • 15
  • 42
  • What kind of API is it? If it is a REST API, you'd be better off with HTTParty or RestClient. If it is just a simple Web interface where you post a form, Mechanize is probably the easiest. – Mark Thomas Sep 03 '12 at 00:15

1 Answers1

0

Solved it, went back to Curb. It is a RESTful API, RestClient was doing something funky with the digest. HttpClient too was posting blank files. Curb did it.

user1320651
  • 808
  • 2
  • 15
  • 42