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

Green Thing Labs

Stories API

Story details

Each story publishes its content in an XML format. An example is shown below:

URL: http://v2.dothegreenthing.com/stories/{story_stub}.xml

Method: GET

Example: http://www.dothegreenthing.com/stories/13397_mmmmm_snuggie.xml

      <story href="http://www.dothegreenthing.com/stories/13397_mmmmm_snuggie">
        <title>Critical Mass London</title>
        <content>31st August 2007</content>
        <created_at>2008-10-24T14:42:11Z</created_at>
        <updated_at>2008-10-24T14:42:11Z</updated_at>
        <author href="http://dothegreenthing.com/users/tomtaylor">tomtaylor</author>
        <action href="http://dothegreenthing.com/actions/walk_the_walk">Walk The Walk</action>
        <num_views>18</num_views>
        <num_likes>1</num_likes>
        <comments count="2">
          <comment>
            <author href="http://dothegreenthing.com/users/Floppy">Floppy</author>
            <comment>example comment 1</comment>
            <created_at>2008-10-24T14:42:11Z</created_at>
          </comment>
          <comment>
            <author href="http://dothegreenthing.com/users/Floppy">Floppy</author>
            <comment>example comment 2</comment>
            <created_at>2008-10-24T14:42:11Z</created_at>
          </comment>
        </comments>
        <media href="http://s3.amazonaws.com/panda-test/96.flv">
          <embed src="http://s3.amazonaws.com/panda-test/player.swf" width="515" height="300" 
             allowfullscreen="true" allowscriptaccess="always" 
            flashvars="&displayheight=300&file=http://s3.amazonaws.com/panda-test/96.flv&width=400&height=300" />
        </media>
      </story>
    

If the story includes embedded media (video, photo, audio, flash, etc), the canonical location of that media is included in the href attribute of the media tag, and the code required to embed it in an HTML document is included inside the tag.

If the story media content includes video which is available in different formats, those formats and file locations are listed in the video_files tag. This will be the case for videos which are not hosted on external sites, but are instead hosted by Green Thing.

Creating stories

To create a story, you should send an [wiki:APIDetails#Authentication authenticated] POST request to the stories URL:

URL: http://v2.dothegreenthing.com/stories

Method: POST

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 and a description of each tag follows:

      <?xml version="1.0" encoding="UTF-8"?>
      <story>
        <title>My fantastic story</title>
        <content>This story was created through the Green Thing API. It's teh awesome.</content>
        <url>http://www.youtube.com/watch?v=muLIPWjks_M</url>
        <file>
          <original_filename>logo.png</original_filename>
          <content-type>image/png</content-type>
          <data>--FILE DATA BASE64 ENCODED--</data>
        </file>
        <hero-action-stub>walk_the_walk</hero-action-stub>
        <tag-list>api, omg, ponies</tag-list>
      </story>
    

You can upload JPGS, PNG and GIFS, with a max file size of 3mb. Please keep the file extension in the tag.

Tag Description Required?
Title The title of the story Yes
Content The content of the story No
Url The URL for any embedded content. This can be a URL from any of the services supported by embedit No
File The file you want to be embbeded. At the moment images are only allowed to be uploaded (max 3mb) No
Hero Action Stub The stub for the hero action that this story should be associated with. For instance, for the "Walk the Walk" action, the stub would be "walk_the_walk" No
Tag List A comma-separated list of tags to add to the story No

If story creation is successful, the server will return "201 Created", and will include a Location header containing the canonical URL of the new story. If there is an error in the submitted data, the server will return a 422 error, with error details returned in XML format in the body.

The following Ruby code creates a story through the API:

      #!/usr/bin/env ruby

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

      GT_USERNAME = "username_here"
      GT_PASSWORD = "password_here"

      # Create story
      story = {}
      story[:title] = "My fantastic story"
      story[:content] = "This story was created through the Green Thing API. It's teh awesome."
      story[:url] = "http://www.youtube.com/watch?v=muLIPWjks_M"
      story[:hero_action_stub] = "walk_the_walk"
      story[:tag_list] = "api, omg, ponies"

      # Do HTTP POST

      url = URI.parse('http://localhost:3001/stories')
      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 = story.to_xml :root => "story"
      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::HTTPSuccess, Net::HTTPRedirection
          puts "Created story OK at #{res['Location']}"
        else
          res.error!
      end
    

All stories

There is a feed for all the latest stories posted to the site:

URL: http://v2.dothegreenthing.com/stories.atom

Method: GET

There are various parameters that can be applied to change the ordering and filtering of this feed:

Parameter Description Example
a Show only stories tagged to a particular action. The value should be the stub for the requested action.r http://v2.dothegreenthing.com/stories.atom?a=walk_the_walk

This feed includes [http://georss.org geoRSS] information for each story, and includes RFC 5005 pagination links.

Stories for a particular user

Each user has an atom feed of the stories that they have written:

URL: http://v2.dothegreenthing.com/users/{username}.atom

Method: GET

Example: http://v2.dothegreenthing.com/users/Floppy.atom

This feed includes [http://georss.org geoRSS] information for each story, and includes RFC 5005 pagination links.

Following

If a user is following other users, a feed of the stories written by followed users is available.

URL: http://v2.dothegreenthing.com/users/{username}/following.atom

Method: GET

Example: http://v2.dothegreenthing.com/users/Floppy/following.atom

This feed includes [http://georss.org geoRSS] information for each story, and includes RFC 5005 pagination links.

Individual Stories

For each individual story, an Atom feed is available containing the comments posted on that story.

URL: http://v2.dothegreenthing.com/stories/{story_id}.atom

Method: GET

Example: http://v2.dothegreenthing.com/stories/6.atom

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...