/SWIX-JS

Official Javascript library(read-only) for the SWIX Rest Api

Primary LanguageJavaScriptBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

#SWIX-JS

A read-only interface to the SWIX REST Api.

SWIX-JS uses jsonp to fetch data with the SWIX api.

#Using the SWIX-JS Library

##Getting the library

You can load the SWIX Javascript library one of 2 ways.

	<script type="text/javascript" src="www.yourwebsite.com/swix.js">

or when the API is publicly available you will be able to load the source Javascript directly from SWIX.

	<script type="text/javascript" src="www.swixapp.com/media/js/swix.1.0.js">

##Authentication

Authentication for the Javascript library uses API Key authentication. You will be assigned an API Key to use in conjunction with your username when you signup for API access.

##Usage

Initialize the Library/Authenticate

	SWIX.init('username', 'apikey')

Fetch a list of brands

	SWIX.getBrands(function(data){
		console.log(data);
	});

	//output
	{
		[
			{
				"brand": "/api/v1/brand/1/",
				"created_at": "2011-04-20T12:31:04",
				"date": "2011-04-14T00:00:00",
				"id": "1",
				"name": "test"
			},
			{
				"brand": "/api/v1/brand/2/",
				"created_at": "2011-04-20T12:31:04",
				"date": "2011-04-14T00:00:00",
				"id": "2",
				"name": "test 2"
			}
		]
	}

Fetch a Brand by its ID

	SWIX.getBrandByID(1, function(data){
		console.log(data);
	});

	//output
	{
		"brand": "/api/v1/brand/1/",
		"created_at": "2011-04-20T12:31:04",
		"date": "2011-04-14T00:00:00",
		"id": "1",
		"name": "test"
	},

Fetch a List of pods in a particular Brand

	SWIX.getBrandPods(1, function(data){
		console.log(data);
	});
	//output
	{
		"meta":
		{
			"limit": 20,
			"next": null,
			"offset": 0,
			"previous": null,
			"total_count": 1
		},
		"objects":
		[
			{
				"active": true,
				"brand": "/api/v1/brand/1/",
				"created_at": "2011-06-15T09:22:28",
				"error_count": 0,
				"id": "2",
				"name": "Mike Grouchy",
				"seriesdata": "/api/v1/brand/1/pod/2/seriesdata/"
			}
		]
	}

Fetch a Pod given a Brand ID and a Pod ID.

	SWIX.getPodById(1, 2, function(data){
		console.log(data);
	});
	//output
	{
		"pod": "/api/v1/brand/1/pod/2",
		"active": true,
		"brand": "/api/v1/brand/1/",
		"created_at": "2011-06-15T09:22:28",
		"error_count": 0,
		"id": "2",
		"name": "Mike Grouchy",
		"seriesdata": "/api/v1/brand/38/pod/1/seriesdata/"
	}

Get the a Pods Series Data given a Brand ID and a Pod ID. Optionally specify an arbitrary metric to retrieve. You may also specify what graph fromat to retrieve the data in. Note: Currently only highcharts format is supported, eventually you will be able to request other

	SWIX.getPodSeriesData(1, 2, , function(data){
		console.log(data);
	});

	//assuming a twitter pod and we want to get the follower data
	SWIX.getPodSeriesData(1, 2, 'followers', 'highcharts', function(data){
		console.log(data);
	});

	//result
	{
		"metric": "followers",
		"series": [[1299823200000, 12], [1299909600000, 13],
			[1299996000000, 13], [1300078800000, 14], [1300165200000, 13],
			[1300251600000, 14], [1300338000000, 13], [1300424400000, 13],
			[1300510800000, 13], [1300597200000, 13], [1300683600000, 13],
			[1300770000000, 12], [1300856400000, 12], [1300942800000, 12],
			[1301029200000, 12], [1301115600000, 11], [1301202000000, 12],
			[1301288400000, 11], [1301374800000, 12], [1301461200000, 12],
			[1301547600000, 12], [1301634000000, 14], [1301720400000, 12],
			[1301806800000, 12], [1301893200000, 13], [1301979600000, 13],
			[1302066000000, 13], [1302152400000, 13], [1302238800000, 13],
			[1302325200000, 12], [1302411600000, 12], [1302498000000, 12],
			[1302584400000, 12], [1302670800000, 14], [1302757200000, 12],
			[1302843600000, 13], [1302930000000, 13], [1303016400000, 13],
			[1303102800000, 13], [1303189200000, 16], [1303275600000, 14]]
	}
	
	SWIX.getPodSeriesData(55,3,'','',function(data){
		console.log(data);
	});
	
	//result
	{
	   "meta":{
	      "limit":20,
	      "next":null,
	      "offset":0,
	      "previous":null,
	      "total_count":18
	   },
	   "objects":[
	      {
	         "friends":55,
	         "id":"1",
	         "measured_at":"2011-06-11T16:00:20",
	         "updated_at":"2011-06-10T16:00:20",
	         "wallposts":100
	      },
	      {
	         "friends":65,
	         "id":"2",
	         "measured_at":"2011-06-12T16:00:20",
	         "updated_at":"2011-06-10T16:00:20",
	         "wallposts":110
	      },
	      {
	         "friends":75,
	         "id":"3",
	         "measured_at":"2011-06-13T16:00:20",
	         "updated_at":"2011-06-10T16:00:20",
	         "wallposts":120
	      }
	   ]
	}

#Questions ?

Contact Mike Grouchy

twitter: @mgrouchy
email: mike@swixhq.com

or Contact SWIX Support