Add new methods in api.js #2

This commit is contained in:
catalinmiron 2015-06-30 23:30:30 +03:00
parent af1f17bfc5
commit c022e8bb3c
1 changed files with 22 additions and 5 deletions

View File

@ -1,9 +1,26 @@
var API_URL = 'https://api.dribbble.com/shots/';
"use strict";
var API_URL = "https://api.dribbble.com/v1/",
ACCESS_TOKEN = "7a22f910dcdff63bd3ebbe48d022f05e8268c67249709b5489d923f97bcf96ec";
function fetchData(URL) {
return fetch(URL, {
headers: {
"Authorization": "Bearer " + ACCESS_TOKEN
}
}).then((response) => response.json())
}
module.exports = {
getShotsByType: function(query: string, pageNumber: ?number): string {
return (
API_URL + query + '/' + '?per_page=20&page=' + pageNumber
);
getShotsByType: function(type: string, pageNumber: ?number): ?Object {
var URL = API_URL + "shots/?list=" + type;
if (pageNumber) {
URL += "&per_page=10&page=" + pageNumber;
}
return fetchData(URL);
},
getResources: function(url: ?string): ?Object {
return fetchData(url);
}
};