Commit ff174e12 authored by Aurélien Vermylen's avatar Aurélien Vermylen

Fix stuff for device syncing.

parent 46b74188
...@@ -14459,15 +14459,13 @@ return new Parser; ...@@ -14459,15 +14459,13 @@ return new Parser;
AUTOMATIC_BASE_DOMAIN = 'api.automatic.com', AUTOMATIC_BASE_DOMAIN = 'api.automatic.com',
AUTOMATIC_BASE_URI = AUTOMATIC_BASE_PROTOCOL + '://' AUTOMATIC_BASE_URI = AUTOMATIC_BASE_PROTOCOL + '://'
+ AUTOMATIC_BASE_DOMAIN, + AUTOMATIC_BASE_DOMAIN,
/*AUTOMATIC_VALID_ENDPOINTS = ['/trip/', '/trip/{id}/', '/user/',
'/user/{id}/', '/user/{user_id}/device/',
'/user/{user_id}/device/{device_id}/', '/vehicle/{id}/', '/vehicle/',
'/vehicle/{vehicle_id}/mil/'],*/
AUTOMATIC_VALID_ENDPOINT_REGEXES = [/^\/trip(\/T_\w*|)\/$/, AUTOMATIC_VALID_ENDPOINT_REGEXES = [/^\/trip(\/T_\w*|)\/$/,
/^\/user\/me(\/device(\/\w*|)|)\/$/, /^\/user\/me(\/device(\/\w*|)|)\/$/,
/^\/user\/U_\w*(\/device(\/\w*|)|)\/$/,
/^\/vehicle(\/C_\w*(\/mil|)|)\/$/], /^\/vehicle(\/C_\w*(\/mil|)|)\/$/],
AUTOMATIC_VALID_ENDPOINTID_REGEXES = [/^\/trip\/T_\w*\/$/, AUTOMATIC_VALID_ENDPOINTID_REGEXES = [/^\/trip\/T_\w*\/$/,
/^\/user\/me\/device\/\w*\/$/, /^\/user\/me\/device\/\w*\/$/,
/^\/user\/U_\w*\/device\/\w*\/$/,
/^\/vehicle\/C_\w*\/$/], /^\/vehicle\/C_\w*\/$/],
automatic_template = UriTemplate.parse(AUTOMATIC_BASE_URI + automatic_template = UriTemplate.parse(AUTOMATIC_BASE_URI +
'{/endpoint*}'); '{/endpoint*}');
...@@ -14509,6 +14507,11 @@ return new Parser; ...@@ -14509,6 +14507,11 @@ return new Parser;
throw new jIO.util.jIOError('Wrong Automatic API query. (usually ' + throw new jIO.util.jIOError('Wrong Automatic API query. (usually ' +
'caused by wrong "id" or "type")', 400); 'caused by wrong "id" or "type")', 400);
} }
// Handle /user/me/device/ endpoint, which would be put as user, but
// is actually a device query.
if (endpoint === '/user/me/device/') {
type = 'device';
}
// Promise chain to handle multi-part response ("_metadata"->"next" parts). // Promise chain to handle multi-part response ("_metadata"->"next" parts).
function treatNext(returned) { function treatNext(returned) {
var data, var data,
...@@ -14584,8 +14587,14 @@ return new Parser; ...@@ -14584,8 +14587,14 @@ return new Parser;
//'xhrFields': {withCredentials: true} //'xhrFields': {withCredentials: true}
}); });
}).push(function (respdev) { }).push(function (respdev) {
device_dict[token] = var temp = JSON.parse(respdev.target.responseText);
JSON.parse(respdev.target.responseText).results[0].id; if (temp.results.length === 0) {
return new jIO.util.jIOError(
'No device associated to this account yet.',
200
);
}
device_dict[token] = temp.results[0].id;
if (dev === 'all' || dev === device_dict[token]) { if (dev === 'all' || dev === device_dict[token]) {
return jIO.util.ajax({ return jIO.util.ajax({
'type': 'GET', 'type': 'GET',
...@@ -14795,7 +14804,7 @@ return new Parser; ...@@ -14795,7 +14804,7 @@ return new Parser;
key_list, key_list,
automatic_filters = {}, automatic_filters = {},
simplequery_type_value, simplequery_type_value,
intercept_keys = ['start_date', 'stop_date', 'automatic_device', intercept_keys = ['start_date', 'stop_date', 'device',
'vehicle'], 'vehicle'],
intercept_keys_automatic_name = ['started_at', 'ended_at', 'device', intercept_keys_automatic_name = ['started_at', 'ended_at', 'device',
'vehicle'], 'vehicle'],
...@@ -14882,6 +14891,9 @@ return new Parser; ...@@ -14882,6 +14891,9 @@ return new Parser;
' contain "type" constraint with "=" operator.', 400); ' contain "type" constraint with "=" operator.', 400);
} }
automatic_endpoint = '/' + simplequery_type_value[0][1] + '/'; automatic_endpoint = '/' + simplequery_type_value[0][1] + '/';
if (automatic_endpoint === '/device/') {
automatic_endpoint = '/user/me/device/';
}
return _queryAutomaticAPI(automatic_endpoint, automatic_filters, this) return _queryAutomaticAPI(automatic_endpoint, automatic_filters, this)
.push(function (results) { .push(function (results) {
if (!(results instanceof Array)) { if (!(results instanceof Array)) {
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -17,15 +17,13 @@ ...@@ -17,15 +17,13 @@
AUTOMATIC_BASE_DOMAIN = 'api.automatic.com', AUTOMATIC_BASE_DOMAIN = 'api.automatic.com',
AUTOMATIC_BASE_URI = AUTOMATIC_BASE_PROTOCOL + '://' AUTOMATIC_BASE_URI = AUTOMATIC_BASE_PROTOCOL + '://'
+ AUTOMATIC_BASE_DOMAIN, + AUTOMATIC_BASE_DOMAIN,
/*AUTOMATIC_VALID_ENDPOINTS = ['/trip/', '/trip/{id}/', '/user/',
'/user/{id}/', '/user/{user_id}/device/',
'/user/{user_id}/device/{device_id}/', '/vehicle/{id}/', '/vehicle/',
'/vehicle/{vehicle_id}/mil/'],*/
AUTOMATIC_VALID_ENDPOINT_REGEXES = [/^\/trip(\/T_\w*|)\/$/, AUTOMATIC_VALID_ENDPOINT_REGEXES = [/^\/trip(\/T_\w*|)\/$/,
/^\/user\/me(\/device(\/\w*|)|)\/$/, /^\/user\/me(\/device(\/\w*|)|)\/$/,
/^\/user\/U_\w*(\/device(\/\w*|)|)\/$/,
/^\/vehicle(\/C_\w*(\/mil|)|)\/$/], /^\/vehicle(\/C_\w*(\/mil|)|)\/$/],
AUTOMATIC_VALID_ENDPOINTID_REGEXES = [/^\/trip\/T_\w*\/$/, AUTOMATIC_VALID_ENDPOINTID_REGEXES = [/^\/trip\/T_\w*\/$/,
/^\/user\/me\/device\/\w*\/$/, /^\/user\/me\/device\/\w*\/$/,
/^\/user\/U_\w*\/device\/\w*\/$/,
/^\/vehicle\/C_\w*\/$/], /^\/vehicle\/C_\w*\/$/],
automatic_template = UriTemplate.parse(AUTOMATIC_BASE_URI + automatic_template = UriTemplate.parse(AUTOMATIC_BASE_URI +
'{/endpoint*}'); '{/endpoint*}');
...@@ -67,6 +65,11 @@ ...@@ -67,6 +65,11 @@
throw new jIO.util.jIOError('Wrong Automatic API query. (usually ' + throw new jIO.util.jIOError('Wrong Automatic API query. (usually ' +
'caused by wrong "id" or "type")', 400); 'caused by wrong "id" or "type")', 400);
} }
// Handle /user/me/device/ endpoint, which would be put as user, but
// is actually a device query.
if (endpoint === '/user/me/device/') {
type = 'device';
}
// Promise chain to handle multi-part response ("_metadata"->"next" parts). // Promise chain to handle multi-part response ("_metadata"->"next" parts).
function treatNext(returned) { function treatNext(returned) {
var data, var data,
...@@ -142,8 +145,14 @@ ...@@ -142,8 +145,14 @@
//'xhrFields': {withCredentials: true} //'xhrFields': {withCredentials: true}
}); });
}).push(function (respdev) { }).push(function (respdev) {
device_dict[token] = var temp = JSON.parse(respdev.target.responseText);
JSON.parse(respdev.target.responseText).results[0].id; if (temp.results.length === 0) {
return new jIO.util.jIOError(
'No device associated to this account yet.',
200
);
}
device_dict[token] = temp.results[0].id;
if (dev === 'all' || dev === device_dict[token]) { if (dev === 'all' || dev === device_dict[token]) {
return jIO.util.ajax({ return jIO.util.ajax({
'type': 'GET', 'type': 'GET',
...@@ -353,7 +362,7 @@ ...@@ -353,7 +362,7 @@
key_list, key_list,
automatic_filters = {}, automatic_filters = {},
simplequery_type_value, simplequery_type_value,
intercept_keys = ['start_date', 'stop_date', 'automatic_device', intercept_keys = ['start_date', 'stop_date', 'device',
'vehicle'], 'vehicle'],
intercept_keys_automatic_name = ['started_at', 'ended_at', 'device', intercept_keys_automatic_name = ['started_at', 'ended_at', 'device',
'vehicle'], 'vehicle'],
...@@ -440,6 +449,9 @@ ...@@ -440,6 +449,9 @@
' contain "type" constraint with "=" operator.', 400); ' contain "type" constraint with "=" operator.', 400);
} }
automatic_endpoint = '/' + simplequery_type_value[0][1] + '/'; automatic_endpoint = '/' + simplequery_type_value[0][1] + '/';
if (automatic_endpoint === '/device/') {
automatic_endpoint = '/user/me/device/';
}
return _queryAutomaticAPI(automatic_endpoint, automatic_filters, this) return _queryAutomaticAPI(automatic_endpoint, automatic_filters, this)
.push(function (results) { .push(function (results) {
if (!(results instanceof Array)) { if (!(results instanceof Array)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment