-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
73 lines (66 loc) · 1.84 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"use strict";
/**
* Sony Lifelog API
* Usage:
*
* var lifelog = require('sony-lifelog');
*
* // If you have access token,
* var app = lifelog.app({ token: 'token-bla' })
* app.users()
* .then(function(results){
* // do something with results
* }, function(reason){
* // error reason
* });
*
* // If you don't have access token,
*
* var auth = lifelog.auth({
* client_id: 'bla_key',
* secret: 'bla_key',
* scope: 'lifelog.profile.read+lifelog.activities.read+lifelog.locations.read'
* });
* var url = auth.getRedirectURL();
* // send user to url
*
* // after callback operation...
* auth.getAccessToken(code)
* .then(function(results){
* // do something with results
* var accessToken = results.access_token;
*
* var app = lifelog.app({token: accessToken});
* app.users()
* .then(function(results){
* // got this users result
* }, function(reason){
* // error reason
* });
* }, function(reason){
* // error reason
* });
*
*
*/
/** Application Side **/
var appObj = require('./application');
/** Authentication Side **/
var authObj = require('./auth');
var SonyLifelog = {
app: function(token){
/** Application Object **/
if(token){
return appObj(token);
}
return null;
},
auth: function(obj){
/** Validate Auth Object **/
if(obj.client_id || obj.scope || obj.client_secret){
return authObj(obj);
}
return null;
}
};
module.exports = SonyLifelog;