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
<errorName 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!?
Comments
4 comments
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
I always use net/https. Every time I've tried ActiveResource, it makes things more difficult. However, that could be due to my inexperience with ActiveResource.
https://github.com/ThoughtWorksStudios/mingle_events uses net/https.
I use this snippet whenever I write API code to handle GET and POST. Here is an example of using that snippet:
Hi LiXiao, I'm very keen to see these Mingle API with ruby examples. Your link unfortunately redirects to rubforge.org with no examples to be seen. Could you perhaps provide another link please, or directions on how to get to the examples? Thank-you in advance, Michelle
Jay, thanks *very* much. I went from having no clue to being able to post a murmur. To add on to what you have posted, I'm not sure if it is what I'm suppose to be doing but in the least I get relevant xml back:
def get_card(number)
get 'cards', 'card[number]' => number
end
private
def get(resource, args)
rest_connection.request_get("api/v2/projects/#{@project}/#{resource}.xml", args)
end
...now i just have to work out what to next. =) thanks.
Please sign in to leave a comment.