The following documentation explains how to integrate OnSugar with your application over standard HTTP requests.
Current version: 1.0
Fetching content from OnSugar is easy: just append the API call to http://[sitename].onsugar.com/ and you'll get a structured version of your content in either JSON or XML. When using JSON the output will be sent as a Javascript object assigned to a variable named onsugar_api.
To access private methods you will need to authenticate your request by posting two additional arguments - login and password. Additionally, POST methods take an optional parameter callback which will return the response in either XML or JSON.
GET /api/posts/[format]
GET /api/posts/[format]/[id]
GET /api/user/[name]/[format]
GET /api/user/following/[name]/[format]
GET /api/followers/[format]
POST /api/posts/create
text
picture
chat
link
quote
video
User does not exist.
Invalid credentials.
var mysite = "http://sugarcubes.onsugar.com/"
new Ajax.Request(mysite + "api/posts/create", {
method: 'post',
crossSite: true,
parameters: {
type: 'picture',
login: 'mysugar',
password: 'saccharin',
url: 'http://www.craigslist.org/about/best/sdo/566171148.3.jpg',
body: 'cat in a hat',
callback: 'json'
},
onSuccess: function(transport) {
eval(transport.responseText); //this gives us the onsugar_api object
console.log("The URL for your new post is " + mysite + onsugar_api["posts"][0].id);
}
});
@doc = Hpricot(Net::HTTP.get(URI.parse("http://sugarcubes.onsugar.com/api/posts/xml")))
(@doc/:post).each do |post|
@posts << Post.create!(:title => (post/:title).innerHTML,
:body => (post/:body).innerHTML)
end