How to use the electron-fetch.default function in electron-fetch

To help you get started, we’ve selected a few electron-fetch examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Automattic / simplenote-electron / desktop / updater / manual-updater / index.js View on Github external
async ping() {
    const options = {
      headers: {
        'User-Agent': `Simplenote/${app.getVersion()}`,
      },
    };

    try {
      const releaseResp = await fetch(this.apiUrl, options);

      if (releaseResp.status !== 200) {
        this.emit('error');
        console.log(releaseResp); // eslint-disable-line no-console
        return;
      }

      const releaseBody = await releaseResp.json();

      const releaseAsset = releaseBody.assets.find(
        release => release.name === 'latest.yml'
      );
      if (releaseAsset) {
        const configResp = await fetch(
          releaseAsset.browser_download_url,
          options
github actuallymentor / wintertime-mac-background-freezer / modules / app-manager.js View on Github external
checkUpdates( version ) {
    return fetch( this.rawRepo )
    .then(res => res.json() )
    .then( json => {
      if( json.version > version ) {
        this.updateWindow = new BrowserWindow( { width: 400, height: 200 } )
        this.updateWindow.loadFile( `${ __dirname }/../src/update.html` )
        this.window.on( 'closed', f => this.updateWindow = null )
        if( process.env.debug ) this.updateWindow.webContents.openDevTools( )
      }
    } )
  }
github davicorreiajr / spotify-now-playing / src / data-source / spotify-datasource.js View on Github external
exports.getToken = function(body) {
  body.append('client_id', SPOTIFY_CLIENT_ID);
  body.append('client_secret', SPOTIFY_CLIENT_SECRET);

  return fetch('https://accounts.spotify.com/api/token', {
    method: 'POST',
    body: body.toString(),
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
  })
    .then(res => res.json());
};
github davicorreiajr / spotify-now-playing / src / data-source / github-datasource.js View on Github external
exports.getLatestVersion = function() {
  return fetch('https://api.github.com/repos/davicorreiajr/spotify-now-playing/releases/latest', {
    method: 'GET',
    headers: { 'Accept': 'application/vnd.github.v3+json' }
  })
    .then(res => res.json())
    .then(res => ({
      version: res.name,
      dmgDownloadUrl: res.assets[0].browser_download_url
    }));
};
github davicorreiajr / spotify-now-playing / src / data-source / spotify-datasource.js View on Github external
exports.pause = function(accessToken) {
  return fetch('https://api.spotify.com/v1/me/player/pause', {
    method: 'PUT',
    headers: { 'Authorization': `Bearer ${accessToken}` }
  });
};
github davicorreiajr / spotify-now-playing / src / data-source / spotify-datasource.js View on Github external
      return Promise.all(endpoints.map(endpoint => fetch(endpoint, fetchOptions).then(res => res.json())))
        .then(data => data.map(res => res.items).reduce((result, item) => result.concat(item), []))
github davicorreiajr / spotify-now-playing / src / data-source / spotify-datasource.js View on Github external
exports.addTrackToPlaylist = function(accessToken, playlistId, uri) {
  return fetch(`https://api.spotify.com/v1/playlists/${playlistId}/tracks?uris=${encodeURIComponent(uri)}`, {
    method: 'POST',
    headers: { 'Authorization': `Bearer ${accessToken}` }
  })
    .then(res => res.json());
};
github davicorreiajr / spotify-now-playing / src / data-source / spotify-datasource.js View on Github external
exports.getPlaylists = function(accessToken) {
  const limit = 50;
  const fetchOptions = {
    method: 'GET',
    headers: { 'Authorization': `Bearer ${accessToken}` }
  };

  return fetch(`https://api.spotify.com/v1/me/playlists?limit=${limit}`, fetchOptions)
    .then(res => res.json())
    .then(json => {
      const numberOfRequests = Math.ceil(json.total/limit);
      if(numberOfRequests === 1) return json.items;

      const endpoints = [...Array(numberOfRequests)].map((_, request) => `https://api.spotify.com/v1/me/playlists?offset=${limit * request}&limit=${limit}`);
      return Promise.all(endpoints.map(endpoint => fetch(endpoint, fetchOptions).then(res => res.json())))
        .then(data => data.map(res => res.items).reduce((result, item) => result.concat(item), []));
    })
    .then(data => data.filter(playlist => playlist.collaborative || isPlaylistFromCurrentUser(playlist)));
};
github davicorreiajr / spotify-now-playing / src / data-source / spotify-datasource.js View on Github external
exports.nextTrack = function(accessToken) {
  return fetch('https://api.spotify.com/v1/me/player/next', {
    method: 'POST',
    headers: { 'Authorization': `Bearer ${accessToken}` }
  });
};

electron-fetch

A light-weight module that brings window.fetch to electron's background process

MIT
Latest version published 2 years ago

Package Health Score

57 / 100
Full package analysis

Popular electron-fetch functions