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 > Likes Api >

Green Thing Labs

Likes API

"Liking" content

A user can "like" objects within the system. This is possible for [wiki:API/Stories Stories] and [wiki:API/Content Content Items]. To like an object:

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

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"?>
      <like>
        <type>Story</type>
        <id>22076</id>
      </user>
    
Tag Description Required?
Id The id of the object Yes

An empty "201 Created" response will be returned.

The following Ruby code demonstrates how to "like" a Story object.

      #!/usr/bin/env ruby

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

      GT_USERNAME = "username_here"
      GT_PASSWORD = "password_here"

      like = {}
      like[:type] = "Story" # Could be "ContentItem"
      like[:id] = 22076

      # Do HTTP POST
      url = URI.parse('http://www.dothegreenthing.com/ratings')
      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 = like.to_xml :root => 'like'
      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: like was created"
        else
          res.error!
      end
    
Latest from the Green Thing Blog:
Super Less So by Hamlet Au Yeung | Super Less So by Hamlet Au Yeung With 'Man of Steel' currently flying high at the top of...