How to use electron-fetch - 10 common examples

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 horizon-games / remix-app / src / helpers / app_cache.js View on Github external
const registerAppCache = (browserWindow, userDataPath) => {

  // Attempt to fetch the list.json to determine if we're online
  // and the contents are available, in this case, we will always
  // fetch the latest list of available compilers, but fallback
  // to a local version if available.
  let getList = false
  const listURL = 'https://solc-bin.ethereum.org/bin/list.json'
  const resp = fetch(listURL)
  resp.then((resp) => {
    if (resp.status === 200) {
      getList = true
    }
  }).catch((err) => {
    getList = false
  })

  const filter = {
    urls: ['https://solc-bin.ethereum.org/bin/*']
  }

  const session = browserWindow.webContents.session

  session.webRequest.onBeforeRequest(filter, (details, callback) => {
    const resourceURL = details.url
github zeit / hyper / app / notifications.js View on Github external
export default function fetchNotifications(win) {
  const {rpc} = win;
  const retry = err => {
    setTimeout(() => fetchNotifications(win), ms('30m'));
    if (err) {
      //eslint-disable-next-line no-console
      console.error('Notification messages fetch error', err.stack);
    }
  };
  //eslint-disable-next-line no-console
  console.log('Checking for notification messages');
  fetch(NEWS_URL, {
    headers: {
      'X-Hyper-Version': version,
      'X-Hyper-Platform': process.platform
    }
  })
    .then(res => res.json())
    .then(data => {
      const {message} = data || {};
      if (typeof message !== 'object' && message !== '') {
        throw new Error('Bad response');
      }
      if (message === '') {
        //eslint-disable-next-line no-console
        console.log('No matching notification messages');
      } else {
        rpc.emit('add notification', message);
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)));
};

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