Ruby NetHTTP post

Follow

Comments

4 comments

  • Avatar
    Xiao Li

    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

  • Avatar
    Jay Mitchell

    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:


      def post_murmur(text)

        post 'murmurs', 'murmur[murmur]' => text

      end

      private

      def post(resource, args)

        rest_connection.request_post("api/v2/projects/#{@project}/#{resource}.xml", args)

      end

       def rest_connection

        REST::Connection.new(@base_url, :username => @username, :password => @password)

      end

    -Jay
  • Avatar
    Michelle Pace

    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

  • Avatar
    Michelle Pace

    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.