diff --git a/src/media/js/routes_api_args.js.dist b/src/media/js/routes_api_args.js.dist new file mode 100644 index 0000000..c11bdd8 --- /dev/null +++ b/src/media/js/routes_api_args.js.dist @@ -0,0 +1,10 @@ +define('routes_api_args', [], function() { + return function() { + // This function should return an object containing the data to be + // added to each API URL. + return { + lang: (navigator.l10n && navigator.l10n.language) || navigator.language || navigator.userLanguage + }; + }; + +}); diff --git a/src/media/js/urls.js b/src/media/js/urls.js index 5066313..e61acae 100644 --- a/src/media/js/urls.js +++ b/src/media/js/urls.js @@ -1,6 +1,7 @@ define('urls', - ['capabilities', 'format', 'routes_api', 'settings', 'underscore', 'user', 'utils'], - function(caps, format, api_endpoints, settings, _, user) { + ['buckets', 'format', 'routes_api', 'routes_api_args', 'settings', + 'user', 'utils'], + function(buckets, format, api_endpoints, api_args, settings, user) { var group_pattern = /\(.+\)/; var optional_pattern = /(\(.*\)|\[.*\]|.)\?/g; @@ -36,37 +37,19 @@ define('urls', console.error('Could not find the view "' + view_name + '".'); }; - function _dev() { - if (caps.firefoxOS) { - return 'firefoxos'; - } else if (caps.firefoxAndroid) { - return 'android'; - } - } - function _userArgs(func) { return function() { var out = func.apply(this, arguments); - var lang = navigator.language; - if (navigator.l10n && navigator.l10n.language) { - lang = navigator.l10n.language; - } - var args = { - lang: lang, - region: user.get_setting('region') || '', - carrier: user.get_setting('carrier') || '', - dev: _dev() - }; + var args = api_args(); if (user.logged_in()) { args._user = user.get_token(); } - Object.keys(args).forEach(function(k) { - if (!args[k] || - settings.api_param_blacklist && - settings.api_param_blacklist.indexOf(k) !== -1) { - delete args[k]; + var blacklist = settings.api_param_blacklist || []; + for (var key in args) { + if (!args[key] || blacklist.indexOf(key) !== -1) { + delete args[key]; } - }); + } return require('utils').urlparams(out, args); }; } @@ -103,7 +86,7 @@ define('urls', api: { url: _userArgs(api), params: _userArgs(apiParams), - sign: _userArgs(_.identity), + sign: _userArgs(function(url) {return url;}), unsigned: { url: api, params: apiParams