particle-api-js 10.2.0 → 10.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/Client.js CHANGED
@@ -2,168 +2,168 @@ const Library = require('./Library');
2
2
  let Particle;
3
3
 
4
4
  class Client {
5
- constructor({ auth, api = new Particle() }){
6
- this.auth = auth;
7
- this.api = api;
8
- }
9
-
10
- ready(){
11
- return Boolean(this.auth);
12
- }
13
-
14
- /**
15
- * Get firmware library objects
16
- * @param {Object} query The query parameters for libraries. See Particle.listLibraries
17
- * @returns {Promise} A promise
18
- */
19
- libraries(query = {}){
20
- return this.api.listLibraries(Object.assign({}, query, { auth: this.auth }))
21
- .then(payload => {
22
- const libraries = payload.body.data || [];
23
- return libraries.map(l => new Library(this, l));
24
- });
25
- }
26
-
27
- /**
28
- * Get one firmware library object
29
- * @param {String} name Name of the library to fetch
30
- * @param {Object} query The query parameters for libraries. See Particle.getLibrary
31
- * @returns {Promise} A promise
32
- */
33
- library(name, query = {}){
34
- return this.api.getLibrary(Object.assign({}, query, { name, auth: this.auth }))
35
- .then(payload => {
36
- const library = payload.body.data || {};
37
- return new Library(this, library);
38
- });
39
- }
40
-
41
- /**
42
- * Get list of library versions
43
- * @param {String} name Name of the library to fetch
44
- * @param {Object} query The query parameters for versions. See Particle.getLibraryVersions
45
- * @returns {Promise} A promise
46
- */
47
- libraryVersions(name, query = {}){
48
- return this.api.getLibraryVersions(Object.assign({}, query, { name, auth: this.auth }))
49
- .then(payload => {
50
- const libraries = payload.body.data || [];
51
- return libraries.map(l => new Library(this, l));
52
- });
53
- }
54
-
55
- /**
56
- * Contribute a new library version
57
- * @param {Buffer} archive The compressed archive with the library source
58
- * @returns {Promise} A promise
59
- */
60
- contributeLibrary(archive){
61
- return this.api.contributeLibrary({ archive, auth: this.auth })
62
- .then(payload => {
63
- const library = payload.body.data || {};
64
- return new Library(this, library);
65
- }, error => {
66
- this._throwError(error);
67
- });
68
- }
69
-
70
- /**
71
- * Make the the most recent private library version public
72
- * @param {string} name The name of the library to publish
73
- * @return {Promise} To publish the library
74
- */
75
- publishLibrary(name){
76
- return this.api.publishLibrary({ name, auth: this.auth })
77
- .then(payload => {
78
- const library = payload.body.data || {};
79
- return new Library(this, library);
80
- }, error => {
81
- this._throwError(error);
82
- });
83
- }
84
-
85
- /**
86
- * Delete an entire published library
87
- * @param {object} params Specific params of the library to delete
88
- * @param {string} params.name Name of the library to delete
89
- * @param {string} params.force Key to force deleting a public library
90
- * @returns {Promise} A promise
91
- */
92
- deleteLibrary({ name, force }){
93
- return this.api.deleteLibrary({ name, force, auth: this.auth })
94
- .then(() => true, error => this._throwError(error));
95
- }
96
-
97
- _throwError(error){
98
- if (error.body && error.body.errors){
99
- const errorMessages = error.body.errors.map((e) => e.message).join('\n');
100
- throw new Error(errorMessages);
101
- }
102
- throw error;
103
- }
104
-
105
- downloadFile(uri){
106
- return this.api.downloadFile({ uri });
107
- }
108
-
109
- /**
110
- * @param {Object} files Object containing files to be compiled
111
- * @param {Number} platformId Platform id number of the device you are compiling for
112
- * @param {String} targetVersion System firmware version to compile against
113
- * @returns {Promise} A promise
114
- * @deprecated Will be removed in 6.5
115
- */
116
- compileCode(files, platformId, targetVersion){
117
- return this.api.compileCode({ files, platformId, targetVersion, auth: this.auth });
118
- }
119
-
120
- /**
121
- * @param {object} params
122
- * @param {string} params.deviceId Device ID or Name
123
- * @param {boolean} params.signal Signal on or off
124
- * @returns {Promise} A promise
125
- * @deprecated Will be removed in 6.5
126
- */
127
- signalDevice({ signal, deviceId }){
128
- return this.api.signalDevice({ signal, deviceId, auth: this.auth });
129
- }
130
-
131
- /**
132
- * @returns {Promise} A promise
133
- * @deprecated Will be removed in 6.5
134
- */
135
- listDevices(){
136
- return this.api.listDevices({ auth: this.auth });
137
- }
138
-
139
- /**
140
- * @returns {Promise} A promise
141
- * @deprecated Will be removed in 6.5
142
- */
143
- listBuildTargets(){
144
- return this.api.listBuildTargets({ onlyFeatured: true, auth: this.auth })
145
- .then(payload => {
146
- let targets = [];
147
- for (let target of payload.body.targets){
148
- for (let platform of target.platforms){
149
- targets.push({
150
- version: target.version,
151
- platform: platform,
152
- prerelease: target.prereleases.indexOf(platform) > -1,
153
- firmware_vendor: target.firmware_vendor
154
- });
155
- }
156
- }
157
- return targets;
158
- }, () => {});
159
- }
160
-
161
- trackingIdentity({ full = false, context = undefined }={}){
162
- return this.api.trackingIdentity({ full, context, auth: this.auth })
163
- .then(payload => {
164
- return payload.body;
165
- });
166
- }
5
+ constructor({ auth, api = new Particle() }){
6
+ this.auth = auth;
7
+ this.api = api;
8
+ }
9
+
10
+ ready(){
11
+ return Boolean(this.auth);
12
+ }
13
+
14
+ /**
15
+ * Get firmware library objects
16
+ * @param {Object} query The query parameters for libraries. See Particle.listLibraries
17
+ * @returns {Promise} A promise
18
+ */
19
+ libraries(query = {}){
20
+ return this.api.listLibraries(Object.assign({}, query, { auth: this.auth }))
21
+ .then(payload => {
22
+ const libraries = payload.body.data || [];
23
+ return libraries.map(l => new Library(this, l));
24
+ });
25
+ }
26
+
27
+ /**
28
+ * Get one firmware library object
29
+ * @param {String} name Name of the library to fetch
30
+ * @param {Object} query The query parameters for libraries. See Particle.getLibrary
31
+ * @returns {Promise} A promise
32
+ */
33
+ library(name, query = {}){
34
+ return this.api.getLibrary(Object.assign({}, query, { name, auth: this.auth }))
35
+ .then(payload => {
36
+ const library = payload.body.data || {};
37
+ return new Library(this, library);
38
+ });
39
+ }
40
+
41
+ /**
42
+ * Get list of library versions
43
+ * @param {String} name Name of the library to fetch
44
+ * @param {Object} query The query parameters for versions. See Particle.getLibraryVersions
45
+ * @returns {Promise} A promise
46
+ */
47
+ libraryVersions(name, query = {}){
48
+ return this.api.getLibraryVersions(Object.assign({}, query, { name, auth: this.auth }))
49
+ .then(payload => {
50
+ const libraries = payload.body.data || [];
51
+ return libraries.map(l => new Library(this, l));
52
+ });
53
+ }
54
+
55
+ /**
56
+ * Contribute a new library version
57
+ * @param {Buffer} archive The compressed archive with the library source
58
+ * @returns {Promise} A promise
59
+ */
60
+ contributeLibrary(archive){
61
+ return this.api.contributeLibrary({ archive, auth: this.auth })
62
+ .then(payload => {
63
+ const library = payload.body.data || {};
64
+ return new Library(this, library);
65
+ }, error => {
66
+ this._throwError(error);
67
+ });
68
+ }
69
+
70
+ /**
71
+ * Make the the most recent private library version public
72
+ * @param {string} name The name of the library to publish
73
+ * @return {Promise} To publish the library
74
+ */
75
+ publishLibrary(name){
76
+ return this.api.publishLibrary({ name, auth: this.auth })
77
+ .then(payload => {
78
+ const library = payload.body.data || {};
79
+ return new Library(this, library);
80
+ }, error => {
81
+ this._throwError(error);
82
+ });
83
+ }
84
+
85
+ /**
86
+ * Delete an entire published library
87
+ * @param {object} params Specific params of the library to delete
88
+ * @param {string} params.name Name of the library to delete
89
+ * @param {string} params.force Key to force deleting a public library
90
+ * @returns {Promise} A promise
91
+ */
92
+ deleteLibrary({ name, force }){
93
+ return this.api.deleteLibrary({ name, force, auth: this.auth })
94
+ .then(() => true, error => this._throwError(error));
95
+ }
96
+
97
+ _throwError(error){
98
+ if (error.body && error.body.errors){
99
+ const errorMessages = error.body.errors.map((e) => e.message).join('\n');
100
+ throw new Error(errorMessages);
101
+ }
102
+ throw error;
103
+ }
104
+
105
+ downloadFile(uri){
106
+ return this.api.downloadFile({ uri });
107
+ }
108
+
109
+ /**
110
+ * @param {Object} files Object containing files to be compiled
111
+ * @param {Number} platformId Platform id number of the device you are compiling for
112
+ * @param {String} targetVersion System firmware version to compile against
113
+ * @returns {Promise} A promise
114
+ * @deprecated Will be removed in 6.5
115
+ */
116
+ compileCode(files, platformId, targetVersion){
117
+ return this.api.compileCode({ files, platformId, targetVersion, auth: this.auth });
118
+ }
119
+
120
+ /**
121
+ * @param {object} params
122
+ * @param {string} params.deviceId Device ID or Name
123
+ * @param {boolean} params.signal Signal on or off
124
+ * @returns {Promise} A promise
125
+ * @deprecated Will be removed in 6.5
126
+ */
127
+ signalDevice({ signal, deviceId }){
128
+ return this.api.signalDevice({ signal, deviceId, auth: this.auth });
129
+ }
130
+
131
+ /**
132
+ * @returns {Promise} A promise
133
+ * @deprecated Will be removed in 6.5
134
+ */
135
+ listDevices(){
136
+ return this.api.listDevices({ auth: this.auth });
137
+ }
138
+
139
+ /**
140
+ * @returns {Promise} A promise
141
+ * @deprecated Will be removed in 6.5
142
+ */
143
+ listBuildTargets(){
144
+ return this.api.listBuildTargets({ onlyFeatured: true, auth: this.auth })
145
+ .then(payload => {
146
+ let targets = [];
147
+ for (let target of payload.body.targets){
148
+ for (let platform of target.platforms){
149
+ targets.push({
150
+ version: target.version,
151
+ platform: platform,
152
+ prerelease: target.prereleases.indexOf(platform) > -1,
153
+ firmware_vendor: target.firmware_vendor
154
+ });
155
+ }
156
+ }
157
+ return targets;
158
+ }, () => {});
159
+ }
160
+
161
+ trackingIdentity({ full = false, context = undefined }={}){
162
+ return this.api.trackingIdentity({ full, context, auth: this.auth })
163
+ .then(payload => {
164
+ return payload.body;
165
+ });
166
+ }
167
167
  }
168
168
 
169
169
  module.exports = Client;
package/src/Defaults.js CHANGED
@@ -1,7 +1,7 @@
1
1
  module.exports = {
2
- baseUrl: 'https://api.particle.io',
3
- clientSecret: 'particle-api',
4
- clientId: 'particle-api',
5
- tokenDuration: 7776000, // 90 days
6
- auth: undefined
2
+ baseUrl: 'https://api.particle.io',
3
+ clientSecret: 'particle-api',
4
+ clientId: 'particle-api',
5
+ tokenDuration: 7776000, // 90 days
6
+ auth: undefined
7
7
  };