File tree Expand file tree Collapse file tree 2 files changed +40
-5
lines changed Expand file tree Collapse file tree 2 files changed +40
-5
lines changed Original file line number Diff line number Diff line change @@ -168,7 +168,8 @@ class Auth {
168
168
cache : false ,
169
169
response : 60000 ,
170
170
deadline : 90000 ,
171
- error : { }
171
+ error : { } ,
172
+ stream : false
172
173
} ,
173
174
opts
174
175
) ;
@@ -204,15 +205,20 @@ class Auth {
204
205
opts . headers . authorization = `Bearer ${ clientToken } ` ;
205
206
}
206
207
207
- begin = new Date ( ) . getTime ( ) ;
208
- ( { status, body } = await superagent ( method , url )
208
+ const req = superagent ( method , url )
209
209
. set ( opts . headers )
210
210
. timeout ( {
211
211
response : opts . response ,
212
212
deadline : opts . deadline
213
213
} )
214
- . query ( opts . query )
215
- . send ( opts . payload ) ) ;
214
+ . query ( opts . query ) ;
215
+
216
+ if ( opts . stream ) {
217
+ return req . send ( opts . payload ) . pipe ( opts . stream ) ;
218
+ }
219
+
220
+ begin = new Date ( ) . getTime ( ) ;
221
+ ( { status, body } = await req . send ( opts . payload ) ) ;
216
222
217
223
if (
218
224
this . isCacheEnabled &&
Original file line number Diff line number Diff line change @@ -106,6 +106,35 @@ class DeloreanES {
106
106
return this . auth . send ( this . service , 'GET' , url , { query } ) ;
107
107
}
108
108
109
+ /**
110
+ * @param {String } userId
111
+ * @param {String } deviceId
112
+ * @param {Object } query
113
+ */
114
+ getUnits ( userId , deviceId , query ) {
115
+ const url = `${ this . url } /devices/${ deviceId } /readings/units` ;
116
+ query = { ...query , user_id : userId } ;
117
+ return this . auth . send ( this . service , 'GET' , url , { query } ) ;
118
+ }
119
+
120
+ /**
121
+ * @param {String } userId
122
+ * @param {String } deviceId
123
+ * @param {Object } query
124
+ * @param {Object } stream
125
+ */
126
+ getDeviceReportStream ( userId , deviceId , query , stream ) {
127
+ const url = `${ this . url } /devices/${ deviceId } /stream/report` ;
128
+ query = { ...query , user_id : userId } ;
129
+
130
+ return this . auth . send ( this . service , 'GET' , url , {
131
+ query,
132
+ stream,
133
+ response : 90000 * 3 ,
134
+ timeout : 90000 * 3
135
+ } ) ;
136
+ }
137
+
109
138
/**
110
139
* @param {String } userId
111
140
* @param {String } deviceId
You can’t perform that action at this time.
0 commit comments