SEVEN THINGS YOU CAN DO TO LEAD A GREENER LIFE
  • Walk_the_walk_off
  • Stay_grounded_off
  • All_consuming_off
  • Easy_on_the_meat_off
  • Human_heat_off
  • Plug_out_off
  • Stick_with_what_you_got_off
Home > Green Thing Labs > Comments Api >

Green Thing Labs

Comments API

Commenting

A user can comment on various objects within the system. This is possible for Stories and Content Items. To comment on an object:

URL: http://www.dothegreenthing.com/comments

Method: POST

Authentication required

The POST body should be an XML document. Both the Accept and Content-Type headers in the request should be set to "text/xml". An example document follows:

      <?xml version="1.0" encoding="UTF-8"?>
      <comment>
        <type>Story</type>
        <id>22076</id>
        <comment>This comment was posted through the API</comment>
      </comment>
    
Tag Description Required?
Type The type of object to like. This can be a Story or a Content Item Yes
Id The id of the object Yes

An empty "201 Created" response will be returned.

The following Ruby code demonstrates how to add a comment to a [wiki:API/Stories Story] object.

      #!/usr/bin/env ruby

      require 'net/http'
      require 'rubygems'
      require 'activesupport'

      GT_USERNAME = "username_here"
      GT_PASSWORD = "password_here"

      comment = {}
      comment[:type] = "Story" # Could be "ContentItem"
      comment[:id] = 22076
      comment[:comment] = "This comment was posted through the API"

      # Do HTTP POST
      url = URI.parse('http://www.dothegreenthing.com/comments')
      req = Net::HTTP::Post.new(url.path)
      req.basic_auth GT_USERNAME, GT_PASSWORD
      req['Accept'] = "text/xml"
      req['Content-Type'] = "text/xml"
      req.body = comment.to_xml :root => 'comment'
      http = Net::HTTP.new(url.host, url.port)
      http.set_debug_output($stdout)
      res = http.start do |x|
        x.request(req)
      end
      case res
        when Net::HTTPCreated
          puts "OK: comment was posted"
        else
          res.error!
      end
    
Latest from the Green Thing Blog:
Do The Green Thing's guide to Valentine's Day | (Image: favim)  It's almost Valentine's Day and if you haven't got your...