-
Notifications
You must be signed in to change notification settings - Fork 548
/
windows.js
186 lines (154 loc) · 3.83 KB
/
windows.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
(function(hello) {
hello.init({
windows: {
name: 'Windows live',
// REF: http://msdn.microsoft.com/en-us/library/hh243641.aspx
oauth: {
version: 2,
auth: 'https://login.live.com/oauth20_authorize.srf',
grant: 'https://login.live.com/oauth20_token.srf'
},
// Refresh the access_token once expired
refresh: true,
logout: function() {
return 'http://login.live.com/oauth20_logout.srf?ts=' + (new Date()).getTime();
},
// Authorization scopes
scope: {
basic: 'wl.signin,wl.basic',
email: 'wl.emails',
birthday: 'wl.birthday',
events: 'wl.calendars',
photos: 'wl.photos',
videos: 'wl.photos',
friends: 'wl.contacts_emails',
files: 'wl.skydrive',
publish: 'wl.share',
publish_files: 'wl.skydrive_update',
share: 'wl.share',
create_event: 'wl.calendars_update,wl.events_create',
offline_access: 'wl.offline_access'
},
// API base URL
base: 'https://apis.live.net/v5.0/',
// Map GET requests
get: {
// Friends
me: 'me',
'me/friends': 'me/friends',
'me/following': 'me/contacts',
'me/followers': 'me/friends',
'me/contacts': 'me/contacts',
'me/albums': 'me/albums',
// Include the data[id] in the path
'me/album': '@{id}/files',
'me/photo': '@{id}',
// Files
'me/files': '@{parent|me/skydrive}/files',
'me/folders': '@{id|me/skydrive}/files',
'me/folder': '@{id|me/skydrive}/files'
},
// Map POST requests
post: {
'me/albums': 'me/albums',
'me/album': '@{id}/files/',
'me/folders': '@{id|me/skydrive/}',
'me/files': '@{parent|me/skydrive}/files'
},
// Map DELETE requests
del: {
// Include the data[id] in the path
'me/album': '@{id}',
'me/photo': '@{id}',
'me/folder': '@{id}',
'me/files': '@{id}'
},
wrap: {
me: formatUser,
'me/friends': formatFriends,
'me/contacts': formatFriends,
'me/followers': formatFriends,
'me/following': formatFriends,
'me/albums': formatAlbums,
'me/photos': formatDefault,
'default': formatDefault
},
xhr: function(p) {
if (p.method !== 'get' && p.method !== 'delete' && !hello.utils.hasBinary(p.data)) {
// Does this have a data-uri to upload as a file?
if (typeof (p.data.file) === 'string') {
p.data.file = hello.utils.toBlob(p.data.file);
}
else {
p.data = JSON.stringify(p.data);
p.headers = {
'Content-Type': 'application/json'
};
}
}
return true;
},
jsonp: function(p) {
if (p.method !== 'get' && !hello.utils.hasBinary(p.data)) {
p.data.method = p.method;
p.method = 'get';
}
}
}
});
function formatDefault(o) {
if ('data' in o) {
o.data.forEach(function(d) {
if (d.picture) {
d.thumbnail = d.picture;
}
if (d.images) {
d.pictures = d.images
.map(formatImage)
.sort(function(a, b) {
return a.width - b.width;
});
}
});
}
return o;
}
function formatImage(image) {
return {
width: image.width,
height: image.height,
source: image.source
};
}
function formatAlbums(o) {
if ('data' in o) {
o.data.forEach(function(d) {
d.photos = d.files = 'https://apis.live.net/v5.0/' + d.id + '/photos';
});
}
return o;
}
function formatUser(o, headers, req) {
if (o.id) {
var token = req.query.access_token;
if (o.emails) {
o.email = o.emails.preferred;
}
// If this is not an non-network friend
if (o.is_friend !== false) {
// Use the id of the user_id if available
var id = (o.user_id || o.id);
o.thumbnail = o.picture = 'https://apis.live.net/v5.0/' + id + '/picture?access_token=' + token;
}
}
return o;
}
function formatFriends(o, headers, req) {
if ('data' in o) {
o.data.forEach(function(d) {
formatUser(d, headers, req);
});
}
return o;
}
})(hello);