API Reference and Developer Documentation

Rackspace Cloud Files Integration

Kraken API allows you to easily store optimized images directly in your Rackspace Cloud Files (presumably CDN-enabled). With just a few additional parameters your optimized images will be pushed to Cloud Files in no time.

Mandatory Parameters:
userYour Rackspace username.
keyYour unique Cloud Files API Key.
containerName of a destination container on your Cloud Files account.
Optional Parameters:
regionName of the region your CloudFiles container is located in. This field is mandatory if the region is different from the default one (iad). The full list of CloudFiles regions can be found here.
pathDestination path in your container (e.g. "images/layout/header.jpg"). Defaults to root "/".
sslA boolean value (true or false) instructing Kraken API to fetch either SSL or non-SSL URL from Rackspace CloudFiles. Defaults to false meaning the non-SSL URL will be returned.

The above parameters must be passed in a cf_store object:

{
    "cf_store": {
        "user": "your-rackspace-username",
        "key": "your-rackspace-api-key",
        "container": "destination-container"
    }
}

Below you can find an example of a complete request that uses cf_store to push optimized image into your Cloud Files container. We will use url option to feed the API with a URL of image to be optimized. The below request uses example (fake) credentials - you will need to replace them with your real ones.

{
  "auth": {
      "api_key": "your-api-key",
      "api_secret": "your-api-secret"
  },
  "cf_store": {
      "user": "Foobar",
      "key": "12dc6c9147c201f96f20c1dcdc112919",
      "container": "assets",
      "path": "images/layout/header.png"
  },
  "url": "http://awesome-website.com/images/header.png",
  "wait": true,
  "lossy": true
}
<?php

require_once("Kraken.php");

$kraken = new Kraken("your-api-key", "your-api-secret");

$params = array(
    "url" => "http://awesome-website.com/images/header.png",
    "wait" => true,
    "lossy" => true,
    "cf_store" => array(
        "user" => "Foobar",
        "key" => "12dc6c9147c201f96f20c1dcdc112919",
        "container" => "assets",
        "path" => "images/layout/header.png"
    )
);

$data = $kraken->url($params);

if ($data["success"]) {
    echo "Success. Optimized image URL: " . $data["kraked_url"];
} else {
    echo "Fail. Error message: " . $data["message"];
}
var Kraken = require("kraken");

var kraken = new Kraken({
    "api_key": "your-api-key",
    "api_secret": "your-api-secret"
});

var params = {
    "url": "http://awesome-website.com/images/header.png",
    "wait": true,
    "lossy": true,
    "cf_store": {
        "user": "Foobar",
        "key": "12dc6c9147c201f96f20c1dcdc112919",
        "container": "assets",
        "path": "images/layout/header.png"
    },
};

kraken.url(params, function (status) {
    if (status.success) {
        console.log("Success. Optimized image URL: %s", status.kraked_url);
    } else {
        console.log("Fail. Error message: %s", status.message);
    }
});
require 'rubygems'
require 'kraken-io'

kraken = Kraken::API.new(
    :api_key => 'your-api-key',
    :api_secret => 'your-api-secret'
)

params = {
    :wait => true,
    :lossy => true,
    :cf_store': {
        'user' => 'Foobar',
        'key' => '12dc6c9147c201f96f20c1dcdc112919',
        'container' => 'assets',
        'path' => 'images/layout/header.png'
    }
}

data = kraken.url('http://awesome-website.com/images/header.png', params)

if data.success
    puts 'Success! Optimized image URL: ' + data.kraked_url
else
    puts 'Fail. Error message: ' + data.message
end
package main

import (
    "log"
    "github.com/kraken-io/kraken-go"
)

func main() {
    kr, err := kraken.New("your-api-key", "your-api-secret")

    if err != nil {
        log.Fatal(err)
    }

    params := map[string]interface {} {
        "wait": true,
        "lossy": true,
        "url": "http://awesome-website.com/images/header.png",
        "cf_store": map[string]interface {} {
            "user": "Foobar",
            "key": "12dc6c9147c201f96f20c1dcdc112919",
            "container": "assets",
            "path": "images/layout/header.png"
        }
    }

    data, err := kr.URL(params)

    if err != nil {
        log.Fatal(err)
    }

    if data["success"] != true {
        log.Println("Failed, error message ", data["message"])
    } else {
        log.Println("Success, Optimized image URL: ", data["kraked_url"])
    }
}
from krakenio import Client

api = Client('your-api-key', 'your-api-secret')

data = {
    'wait': True,
    'lossy': True,
    'cf_store': {
        'user': 'Foobar',
        'key': '12dc6c9147c201f96f20c1dcdc112919',
        'container': 'assets',
        'path': 'images/layout/header.png'
    }
}

result = api.url('http://awesome-website.com/images/header.png', data);

if result.get('success'):
    print result.get('kraked_url')
else:
    print result.get('message')

If your container is CDN-enabled, the optimization results will contain kraked_url which points directly to the optimized file location in your Cloud Files account, for example:

http://e9ffc049726-fdd2d4f11d1005c9e8de.r2.cf1.rackcdn.com/images/layout/header.png

If your container is not CDN-enabled kraked_url will point to the optimized image URL in the Kraken API:

https://dl.kraken.io/api/ec/df/a5/c55d5668b1b5fe9e420554c4ee/header.png