nikolayneykov

Untitled

Jul 29th, 2019
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const apiKey = '&api_key=N8TVb2yjw9q5DG5Us8Zs9bqM33UF3QU5';
  2. const baseUrl = 'http://api.giphy.com/v1/gifs';
  3. const uploadUrl = `http://upload.giphy.com/v1/gifs?${apiKey}`;
  4.  
  5. const getTrendingGifs = async () => {
  6.   const response = await fetch(`${baseUrl}/trending?${apiKey}`);
  7.   const trendingGifs = await response.json();
  8.  
  9.   return trendingGifs;
  10. };
  11.  
  12. const uploadGif = async (data) => {
  13.   const response = await fetch(uploadUrl, {
  14.     method: 'POST',
  15.     mode: 'no-cors',
  16.     header: {
  17.       'Access-Control-Allow-Origin': '*',
  18.       'Content-Type': 'multipart/form-data',
  19.     },
  20.     body: data
  21.   });
  22.  
  23.   return response;
  24. };
  25.  
  26. const getSearchedGifs = async (searchStr) => {
  27.   const response = await fetch(`${baseUrl}/search?${apiKey}&q=${searchStr}`);
  28.   const searchedGifs = await response.json();
  29.  
  30.   return searchedGifs;
  31. };
  32.  
  33. const getUploadedGifs = async () => {
  34.   // TODO
  35. };
  36.  
  37. const getGifById = async () => {
  38.   // TODO
  39. };
  40.  
  41. const getRandomGifId = async () => {
  42.   // TODO
  43. };
  44.  
  45. const getRandomGifs = async () => {
  46.   // TODO
  47. };
  48.  
  49. export {
  50.   getTrendingGifs,
  51.   uploadGif,
  52.   getSearchedGifs,
  53.   getUploadedGifs,
  54.   getGifById,
  55.   getRandomGifId,
  56.   getRandomGifs,
  57. };
Advertisement
Add Comment
Please, Sign In to add comment