Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search API - grupo 4 -seguimos agregando valor- #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 45 additions & 3 deletions components/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,60 @@
// }
// the values for the 'next' keys should be the same as the ones received
// from the API except for the 'offset' key. the returned 'offset' key
// should be equal to 'paging.offset' key
// should be equal to 'paging.offset' key
// plus 'paging.limit' key (from the API response)
// hint 1: use the 'URL' object to create an object representation of a url and
// append the querystring (https://gist.github.com/a0viedo/13241ba70489d6e16805)
// hint 2: use the fetch API to send a request (https://developers.google.com/web/updates/2015/03/introduction-to-fetch)
// hint 3: use the utils method to get a string from a querystring object
exports.search = function(options) {

var qs = {
limit: options.limit || '',
offset: options.offset || '',
price: options.price || '',
data: options.data || '',
official_store_id: 'all'
//// add other keys here
};
},
url = new URL(ML_SEARCH_URL),
response,
promise;

url.search = utils.getQueryStr(qs);

promise = new Promise(function(resolve, reject){

fetch(url.toString())
.then(
function(response) {
if (response.status !== 200) {
reject(Error('the response status was:' + response.status));
return;
}

// Examine the text in the response
response.json().then(function(data) {
var result = {
results: data.results,
next: {
data: qs.data,
limit: data.paging.limit,
offset: data.paging.offset + data.paging.limit,
price: qs.price
}
}

resolve(result);
});
}
)
.catch(function(err) {
reject(err);
});

});

///// add code here /////
return promise;
};
});