1.0.25 • Published 8 years ago

kite-js v1.0.25

Weekly downloads
17
License
MIT
Repository
-
Last release
8 years ago

Kite JavaScript Library

The Kite JavaScript library provides convenient access to the Kite REST API from applications written in the JavaScript language. It includes a pre-defined set of classes for API resources that initialize themselves dynamically from API responses.

Documentation

See the JavaScript API docs.

Suggested Installation Approach

via NPM

npm install kite-js

via CDN

<script src="http://sdks.kite.ly/kite-js/v0/latest/kite.min.js"></script>

Suggested Usage / Approach

Client side JavaScript

The library needs to be configured with your account's public key which is available in your Kite Dashboard.

Kite.setPublicKey("4af946b1b9fabae5c03472ff056a429fd189a16d");

Node.js

After installing the library from NPM you will need to require the library in your project.

const Kite = require('kite-js');

The library needs to be configured with your account's public key which is available in your Kite Dashboard. You may also want to set the optional secret key at this point.

Kite.setPublicKey('replaceWithYourPublicKey');

/* Optional */
Kite.setSecretKey('replaceWithSecretKey');

SDK Features

Address Search / Lookup

Search for an address in a certain country.

If a single matching address is found this is returned, otherwise an array of multiple addresses is returned.

Either search_term or address_id is required.

Kite.address.search({
		country_code: "GBR",
		search_term: "10 Downing Street" // Optional,
		address_id: 'GBR|PR|23747771|0|0|0||Retrieve' // Optional
	}, 
	function(uniqueAddress) {...}, 
	function(multipleAddresses) {...}, 
	function(err) {...} // If no address is found
);

/*
	If multiple addresses are found, another call needs to be made
	to get further details. This can be called directly on the returned
	address object
*/
multipleAddresses[0].getDetail(
	function(success) {...}, 
	function(err) {...}
);

/* or via the Kite.address.getDetail function */
Kite.address.getDetail(
	multipleAddresses[0],
	function(address) {...},
	function(err) {...}
);

Product Retrieval

/* 
	Returns a list of products associated with the current Kite account
 */
Kite.product.list({
		limit: 50,
		offset: 0
	},
	function(productsResponse) {...}, 
	function(err) {...} // E.g incorrect parametres
);

/* Retrieve a single product by it's template_id */
Kite.product.get(
	'i6_case',
	function(product) {...},
	function(err) {...} // If no product is found
);

Order Retrieval

/* 
 * Returns a list of orders associated with the Kite account.
 */
Kite.order.list({
		limit: 100
	},
	function(ordersResponse) {...},
	function(err) {...} // E.g incorrect parametres
);

/* Retrieve single order by id */
Kite.order.get(
	'PS123-12341234',
	function(order) {...}, 
	function(err) {...} // If no order is found
);

Placing Product Orders

/* 
 * Create and submit an order for printing
 * 1. Create any print jobs that will be part of the order
 */  
var phonecaseJob = Kite.job.create({
	template_id:"i6_case",
	asset:"http://.../image.jpg",
	options:{
		case_style:"matte"
	}
});
							    
var tshirtJob = Kite.job.create({
	template_id:"aa_mens_tshirt", 
	assets:{
		center_chest:"http://.../image.jpg",
		center_back:"http://.../image.jpg"
	},
	options:{
		garment_size:"M",
		garment_color:"white"
	}
});

/* 2. Create the order to which the jobs will be added */							    
var order = Kite.order.create();
order.jobs.push(phonecaseJob);
order.jobs.push(tshirtJob);
order.shipping_address = ... ; // set it to an Address object
order.promo_code = "XYZ";  // optional

/* optionally view the cost of the order */
var cost = order.calculateCost(function(cost) {...}, function(err) {...});

/* 3. submit the print order to kite for fulfillment */

/*
	Either the proof of payment needs to be set or if using
	the SDK through NodeJS the secret key can be set instead.
*/
order.proof_of_payment = "..."; // Stripe charge token
order.submit(function(orderId) {...}, function(err) {...});
1.0.25

8 years ago

1.0.24

8 years ago

1.0.23

8 years ago

1.0.22

8 years ago

1.0.21

8 years ago

1.0.20

8 years ago

1.0.19

8 years ago

1.0.18

8 years ago

1.0.17

8 years ago

1.0.16

8 years ago

1.0.15

8 years ago

1.0.14

8 years ago

1.0.13

8 years ago

1.0.12

8 years ago

1.0.10

8 years ago