1 | # 2Klic.io SDK
|
2 |
|
3 | ## Installing the library from the private repository
|
4 |
|
5 | bower install 2klic_io-sdk --save
|
6 |
|
7 | ## Getting Started
|
8 |
|
9 | Include the library in your index.html
|
10 |
|
11 | <script src="bower_components/dist/sdk.js"></script>
|
12 |
|
13 | Instantiate a new engine:
|
14 |
|
15 | var platform = new Klic();
|
16 |
|
17 | By default, the engine will point to https://api.2klic.io. If you want to work with a local development engine, just use the url option:
|
18 |
|
19 | var platform = new Klic({url: 'http://localhost:5000'});
|
20 |
|
21 | 2Klic.io is using JWT tokens for authentication. In order to use most of the available methods and helpers, you need to retrieve a valid token.
|
22 |
|
23 | ### How to instantiate in Node:
|
24 |
|
25 | var Klic = require('@2klic/2klic_io-sdk');
|
26 | var KlicSDK = new Klic();
|
27 | KlicSDK.devices.list().then(function(devices){
|
28 | console.log(devices);
|
29 | return devices
|
30 | });
|
31 |
|
32 | ### Configuring our SDK to retrieve a token
|
33 |
|
34 | You need to set the following options in order to retrieve a valid token:
|
35 |
|
36 | url: Url of the 2klic.io instance you want to use. default to https://api.2klic.io
|
37 | auth: {
|
38 | token: An existing token (previously retrieved) or nothing
|
39 | },
|
40 | unsafe: true indicates that we're in an unsafe environment (client app, browser, etc)
|
41 | app_key : The key of the app as provided by 2klic.io
|
42 | app_secret: Optional. The secret if you are in a safe environment (do not use for client or browser app)
|
43 |
|
44 | With these options you can instantiate the Klic instance:
|
45 |
|
46 | var platform = new Klic({
|
47 | unsafe: isClient,
|
48 | app_key: "b2423a98430c03213d7ad86033622f5066a44b69"
|
49 | });
|
50 |
|
51 | Note that we haven't provided any token as we don't have one yet.
|
52 |
|
53 | ### Retrieving a valid token
|
54 |
|
55 | You execute the authenticate method to retrieve your token :
|
56 |
|
57 | platform.authenticate({username:username, password:password}).then(function(result) {
|
58 |
|
59 | // Save the token for subsequent calls
|
60 | platform.auth = {
|
61 | token: result.token
|
62 | };
|
63 |
|
64 | });
|
65 |
|