Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Bug 1095466 - Make marketplace api url overrideable. r=kgrandon #26004

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 18 additions & 8 deletions apps/search/js/providers/marketplace.js
Expand Up @@ -5,11 +5,7 @@
'use strict';

const NUM_DISPLAY = 4;
const API = 'https://marketplace.firefox.com/api/v2/apps/search/rocketbar/' +
'?q={q}' +
'&limit=' + NUM_DISPLAY +
'&lang=' + document.documentElement.lang +
'&region=restofworld';
var apiUrl = null;

function Marketplace() {}

Expand All @@ -23,16 +19,30 @@
dedupeStrategy: 'exact',
remote: true,

init: function() {

DataGridProvider.prototype.init.apply(this, arguments);
var urlKey = 'search.marketplace.url';
var req = navigator.mozSettings.createLock().get(urlKey);
req.onsuccess = function () {
if (req.result[urlKey]) {
apiUrl = req.result[urlKey]
.replace('{limit}', NUM_DISPLAY)
.replace('{lang}', document.documentElement.lang);
}
};
},

search: function(input) {
return new Promise((resolve, reject) => {
this.abort();

if (!input) {
return;
if (!input || !apiUrl) {
return reject();
}

var req = new XMLHttpRequest();
req.open('GET', API.replace('{q}', input), true);
req.open('GET', apiUrl.replace('{q}', input), true);
req.onload = (function onload() {
var results = JSON.parse(req.responseText);
if (!results.length) {
Expand Down
12 changes: 10 additions & 2 deletions apps/search/test/unit/providers/marketplace_test.js
@@ -1,6 +1,7 @@
'use strict';
/* global MocksHelper, Search */

/* global MockNavigatorSettings */
require('/shared/test/unit/mocks/mock_navigator_moz_settings.js');
require('/shared/test/unit/mocks/mock_moz_activity.js');
require('/shared/test/unit/mocks/mock_l10n.js');

Expand All @@ -25,9 +26,16 @@ var mocksForMarketplaceProvider = new MocksHelper([
suite('search/providers/marketplace', function() {
mocksForMarketplaceProvider.attachTestHelpers();

var fakeElement, stubById, subject;
var fakeElement, stubById, subject, realMozSettings;

setup(function(done) {
realMozSettings = navigator.mozSettings;
navigator.mozSettings = MockNavigatorSettings;

navigator.mozSettings.createLock().set({
'search.marketplace.url': 'http://localhost'
});

fakeElement = document.createElement('div');
fakeElement.style.cssText = 'height: 100px; display: block;';
stubById = this.sinon.stub(document, 'getElementById')
Expand Down
1 change: 1 addition & 0 deletions build/config/common-settings.json
Expand Up @@ -185,6 +185,7 @@
"ril.data.cp.apns": "",
"ril.callerId": "CLIR_DEFAULT",
"everythingme.api.url": "https://api.everything.me/partners/1.0/{resource}/",
"search.marketplace.url": "https://marketplace.firefox.com/api/v2/apps/search/rocketbar/?q={q}&limit={limit}&lang={lang}&region=restofworld",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I think we've probably messed up on the everything.me api url by sticking the query params in here as well. How do you feel about just having the base URL here, and moving the rest of the path/query params into the code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont know why we would do that, if the marketplace provided a new api it would very possibly use a new different url format, parameterised urls are the normal way to do things and they keep the logic fairly contained, I mean almost all the urls in about:config are similiarly (different format) parameterised

"screen.automatic-brightness": false,
"screen.brightness": 1,
"screen.timeout": 60,
Expand Down
5 changes: 3 additions & 2 deletions shared/test/integration/profile.js
Expand Up @@ -4,10 +4,11 @@
module.exports = {
settings: {
'cdn.url': 'http://localhost',
'everythingme.api.url': null
'everythingme.api.url': null,
'search.marketplace.url': null
},
prefs: {
'geo.wifi.uri': 'http://localhost'
},
}
// apps: {}
};