Forums Mingle API

Ruby NetHTTP post#592

Subscribe to Ruby NetHTTP post 2 post(s), 2 voice(s)

 
Avatar trpdaddy 2 post(s) #1471

Has anyone made a post work with Ruby?

require ‘net/http’

require ‘uri’

url = URI.parse(‘http://localhost:8080/projects/test_project/cards.xml’)

req = Net::HTTP::Post.new(url.path)

req.basic_auth ‘my_user’, ‘password’

req.set_form_data({‘name’=>”My Card #{Time.new.to_s}”, ‘card_type_name’=>‘story’}, ’;’)

res = Net::HTTP.new(url.host, url.port).start {|http| http.request(req) }

puts res

returns #<net::httpclienterror:0x2adde80>
<?xml version=”1.0” encoding=”UTF-8”?>
<errors> <error>Name can’t be blank</error>
</errors>

I tried putting the ‘name’ and ‘card_type_name’ in the url, but that doesn’t work either. Why are all the examples for cUrl? How about Ruby!?

 
Avatar LiXiao Administrator 21 post(s) #1489

Hi trpdaddy,

all card attributes should be specified like this: card[attribute],
For your instance, use ‘card[name]’ should work.

And, if you use ActiveResource instead of Net::HTTP, should be very easy to build API in ruby
You can find some ruby examples here: http://minglemingle.rubyforge.org/

Cheers

Forums Mingle API