UNPKG

6.32 kBMarkdownView Raw
1# Appcelerator Platform SDK
2
3> This is a Node module that will allow you to make API requests to the Appcelerator Platform.
4
5[![Build Status](https://travis-ci.org/appcelerator/appc-platform-sdk.svg)](https://travis-ci.org/appcelerator/appc-platform-sdk) [![npm version](https://badge.fury.io/js/appc-platform-sdk.svg)](http://badge.fury.io/js/appc-platform-sdk) [![Coverage Status](https://coverage.appcelerator.com/appcelerator/appc-platform-sdk/label_master.svg)](https://coverage.appcelerator.com/appcelerator#appc-platform-sdk)
6
7## Installation
8
9 $ npm install appc-platform-sdk
10
11## Usage
12
13```javascript
14var AppC = require('appc-platform-sdk');
15
16// login
17AppC.login(username,password,function(err,session){
18 // we got an error, oops
19 if (err) return console.error(err);
20
21 // print out some information about our logged in user
22 console.log(session.user.username);
23
24 // when you're done, logout
25 AppC.logout(session);
26});
27```
28
29## Auth
30
31Authentication API used for gaining access to the platform.
32
33### Login
34
35Login to the Platform. Will validate the user and create a user session which will allow you to make subsequent API calls to the platform while the session is valid.
36
37```javascript
38AppC.login(username,password,function(err,session){
39 // logged in, check err
40});
41```
42
43### Logout
44
45Logout of the Platform session. Will invalidate the session object.
46
47```javascript
48AppC.logout(session,function(){
49 // logged out
50});
51```
52
53## Session
54
55A new Session instance is created on a succesful login. The following properties / functions are available:
56
57| Property | Type | Description |
58|--------------|----------|-----------------------------------------|
59| isValid | function | returns true if session is valid |
60| invalidate | function | invalid (and logout) session |
61| user | property | user instance |
62| orgs | property | user member orgs |
63
64You cannot create a session and a session is immutable. Once you invalidate a session, it is no longer valid and must not be used again.
65
66## User
67
68User API for interacting with users of the platform.
69
70### find
71
72Find a specific user details.
73
74```javascript
75AppC.User.find(session, '1234', function(err, user){
76
77});
78```
79
80### switchLoggedInOrg
81
82Switch the active session user's logged in / active organization.
83
84```javascript
85AppC.User.switchLoggedInOrg(session, '4567', function(err){
86
87});
88```
89
90## Org
91
92Organization API for interacting with organizations that a user is a member.
93
94### find
95
96Find all the organizations that the current user has visibility.
97
98```javascript
99AppC.Org.find(session, function(err,orgs){
100
101});
102```
103
104### getCurrent
105
106Return the current organization object for user session.
107
108```javascript
109AppC.Org.getCurrent(session);
110```
111
112### getById
113
114Return a specific organization by the org_id.
115
116```javascript
117AppC.Org.getById(session, org_id);
118```
119
120### getByName
121
122Return a specific organization by the name.
123
124```javascript
125AppC.Org.getByName(session, 'Org Name');
126```
127
128## App
129
130App API for interacting with applications registered with the platform.
131
132### findAll
133
134Find all the apps that the current user has access to
135
136```javascript
137// find all apps for current active organization
138AppC.App.findAll(session, function(err,apps){
139
140});
141
142// find all apps for the org_id
143AppC.App.findAll(session, 'org_id', function(err,apps){
144
145});
146```
147
148### find
149
150Find a specific app by app_guid
151
152```javascript
153// find a specific app
154AppC.App.find(session, 'app_guid', function(err,app){
155
156});
157```
158
159### update
160
161Update an app details.
162
163```javascript
164// update an app
165app.app_name = 'my new app name';
166AppC.App.update(session, app, function(err,result){
167 console.log(err,result);
168})
169```
170
171> this API is dangerous. please be cautious in using this API as changes are irreversible.
172
173## Notification
174
175Notification API for handling platform notification events.
176
177### findAll
178
179Find all notifications for the logged in user:
180
181```javascript
182// get all notifications
183AppC.Notification.findAll(session, function(err,results){
184
185});
186```
187
188## Feed
189
190Feed API for handling platform feed events.
191
192### findAll
193
194Find all feed events for the logged in user:
195
196```javascript
197// get all feeds
198AppC.Feed.findAll(session, function(err,results){
199
200});
201
202// get all feeds for app_guid
203AppC.Feed.findAll(session, {app_guid:'123'}, function(err,results){
204
205});
206
207// get feeds by limit
208AppC.Feed.findAll(session, {limit:10}, function(err,results){
209
210});
211```
212
213The following are options that can be passed to the second parameter of findAll:
214
215- org_id: The ID of the org that the messages were sent to
216- app_guid: The guid of the app that the messages were sent to
217- limit: A number of records to limit the result to
218- since: A unix timestamp to get new messages from
219- before: A unix timestamp to get old messages from before
220
221## Cloud
222
223API for accessing Appcelerator Cloud Services (ACS).
224
225### createApp
226
227Create a new pre-built ACS application (mBaaS).
228
229```javascript
230// create a new app
231AppC.Cloud.createApp(session, "foo", function(err,app){
232
233});
234```
235
236Required parameters:
237
238- session: logged in session object
239- name: specify the name of the application to create
240- callback: function to invoke when completed
241
242Returns a JSON object with the application details such as:
243
244```javascript
245{ id: '987w498908098asdfasdfasdf',
246 name: 'foo',
247 status: 0,
248 created_at: '2014-09-29T19:11:40+0000',
249 updated_at: '2014-09-29T19:11:40+0000',
250 key: 'sdfasdfasdf0989890889asdf89asdf',
251 oauth_key: 'asdfasdf08s09d8f09as8df098asdf098',
252 oauth_secret: 'sfhjasdhfausdhf8878as87fdasd78f',
253 group_id: '9890s8df908as09d8f08asdf88188',
254 type: 1 }
255```
256
257
258# Licensing
259
260This code is Confidential and Proprietary to Appcelerator, Inc. All Rights Reserved. This code MUST not be modified, copied or otherwise redistributed without express written permission of Appcelerator. This file is licensed as part of the Appcelerator Platform and governed under the terms of the Appcelerator license agreement. Your right to use this software terminates when you terminate your Appcelerator subscription.
261
262Distribution through the NPM package system located at http://npmjs.org is expressly granted if the package you are downloading is from the official Appcelerator account at http://npmjs.org/package/appc-platform-sdk.