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