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

Commit

Permalink
Merge pull request #17184 from KevinGrandon/bug_983568_search_marketa…
Browse files Browse the repository at this point in the history
…plce_api_endpoint

Bug 983568 - [Search] Implement new lightweight Marketplace API r=eperelman
  • Loading branch information
KevinGrandon committed Mar 14, 2014
2 parents 5b32f4d + 25f82c2 commit 7a49ca7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 36 deletions.
29 changes: 13 additions & 16 deletions apps/search/js/providers/marketplace.js
Expand Up @@ -5,8 +5,10 @@
'use strict';

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

function Marketplace() {}

Expand Down Expand Up @@ -37,32 +39,27 @@
this.clear();
this.abort();

if (!input) {
return;
}

var req = new XMLHttpRequest();
req.open('GET', API.replace('{q}', input), true);
req.onload = (function onload() {
var results = JSON.parse(req.responseText);
if (!results.meta.total_count) {
if (!results.length) {
return;
}

var length = Math.min(NUM_DISPLAY, results.meta.total_count);
var length = Math.min(NUM_DISPLAY, results.length);
var formatted = [];
for (var i = 0; i < length; i++) {
var app = results.objects[i];
var nameL10n = '';
for (var locale in app.name) {
// Default the app name if we haven't found a matching locale
nameL10n = nameL10n || app.name[locale];
// Overwrite if the locale matches
if (locale === document.documentElement.lang) {
nameL10n = app.name[locale];
}
}
var app = results[i];

formatted.push({
title: navigator.mozL10n.get('install-marketplace-title',
{title: nameL10n}),
icon: app.icons['64'],
{title: app.name}),
icon: app.icon,
dedupeId: app.manifest_url,
dataset: {
slug: app.slug
Expand Down
31 changes: 11 additions & 20 deletions apps/search/test/unit/providers/marketplace_test.js
Expand Up @@ -66,27 +66,18 @@ suite('search/providers/marketplace', function() {

suite('mock response', function() {

var marketplaceContent = {
meta: {
total_count: 2
var marketplaceContent = [
{
'manifest_url': 'http://fakeapp1.mozilla.org/manifest.webapp',
'name': 'FIRST Marketplace App',
'icon': ''
},
objects: [
{
'manifest_url': 'http://fakeapp1.mozilla.org/manifest.webapp',
'name': {
'en-us': 'FIRST Marketplace App'
},
'icons': {}
},
{
'manifest_url': 'http://fakeapp2.mozilla.org/manifest.webapp',
'name': {
'en-us': 'SECOND Marketplace App'
},
'icons': {}
}
]
};
{
'manifest_url': 'http://fakeapp2.mozilla.org/manifest.webapp',
'name': 'SECOND Marketplace App',
'icon': ''
}
];

var requests = [];
var xhr;
Expand Down

0 comments on commit 7a49ca7

Please sign in to comment.