How to use the alfy.fetch function in alfy

To help you get started, we’ve selected a few alfy 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 SamVerschueren / alfred-font-awesome / index.js View on Github external
'use strict';
const alfy = require('alfy');
const Color = require('color');

const url = 'http://m19dxw5x0q-dsn.algolia.net/1/indexes/*/queries?x-algolia-agent=Algolia%20for%20vanilla%20JavaScript%203.13.1&x-algolia-application-id=M19DXW5X0Q&x-algolia-api-key=c79b2e61519372a99fa5890db070064c';

// Determine the iconset depending on the background color
const background = new Color(alfy.alfred.themeBackground);
const iconset = background.light() ? 'black' : 'white';

alfy
	.fetch(url, {
		method: 'POST',
		json: true,
		headers: {
			'Content-Type': 'application/json',
			Accept: 'application/json'
		},
		body: `{"requests":[{"indexName":"font_awesome","params":"query=${alfy.input}&page=0&facets=%5B%5D&tagFilters=&hitsPerPage=50"}]}`
	})
	.then(data => {
		const items = data.results[0].hits.map(x => {
			return {
				title: x.name,
				autocomplete: x.name,
				subtitle: `${x.css_class}`,
				arg: x.css_class,
github klaascuvelier / alfred-mdn / index.js View on Github external
"use strict";

const alfy = require("alfy");
const mdnBase = "https://wiki.developer.mozilla.org/api/v1/search/en-US";

alfy.fetch(`${mdnBase}?q=${alfy.input}`, { transform })
    .then(results => {
        const items = (results || []).map(result => {
            const {title, excerpt, url} = result;
            const subtitle = stripHtml(excerpt);

            return {
                title,
                subtitle,
                autoComplete: title,
                arg: url,
                quicklookurl: url
            }
        });

        // No results
        if (items.length === 0 && false) {
github CoderMageFox / alfredMagic / VariableNameTransLate / MainLogic / FeachDataFromServer.js View on Github external
getJoinedResult: function (Api, Params, Name) {
        alfy.fetch(Api, Params).then(Result => {
            if (Result.errorCode === 0) {
                let ResultValueArr, ResultTranslationArr;
                //默认初始值:
                //ValueArr用于获取
                ResultValueArr = [];
                ResultTranslationArr = Result.translation;
                ResultTranslationArr.map((item) => {
                    ResultValueArr.push({
                        title: Name(item),
                        subtitle: `标准翻译结果: ${item}`,
                        arg: Name(item),
                    });
                });
                // 网络翻译结果
                if (Result.web) {
                    let WebResult = Result.web;
github Rawnly / alfred-iconfinder-search / index.js View on Github external
https.get(url, function(response) {
		 if (callback != undefined) {
			 response.pipe(file).on('finish', () => {
				 callback(file)
			 })
		 }
	});
};



// Checks for available update and updates the `info.plist`
alfredNotifier();

alfy.fetch(url, {
    transform: body => {
        body = body.icons
        return body;
    }
}).then(data => {

	const items = data.map(x => {
		const tags = x.tags.join(', ');
		const id = x.icon_id;
		const argument = `https://www.iconfinder.com/icons/${id}`;
		const icon_path = join(dir, `${inp}_${x.icon_id}.png`);

		return {
			title: `[${tags}]`,
			subtitle: `ID: ${id}`,
			arg: argument,
github xfslove / alfred-mvns / index.js View on Github external
const dateFormat = require('date-format');

let q = alfy.input;
const s = q.split(':');

if (s.length > 1) {
  q = 'g:'+s[0];
  if (s[1]) {
    q = q+' AND '+'a:'+s[1];
  } 
  if (s.length > 2 && s[2]) {
    q = q+' AND '+'v:'+s[2];
  }
}

alfy.fetch('http://search.maven.org/solrsearch/select', {
	query: {
		q,
    start: 0,
		rows: 20
	}
}).then(data => {
  const items = data.response.docs
	  .map(x => {
      const v = x.v?x.v:x.latestVersion;
      const mvn = `\n  ${x.g}\n  ${x.a}\n  ${v}\n`;
      const gradle = `compile '${x.g}:${x.a}:${v}'`;
		  return {
			  title: `${x.g}:${x.a}:${v}`,
			  subtitle: `updated at ${dateFormat('yyyy-dd-MM', new Date(x.timestamp))}`,
        arg: mvn,
        mods: {
github sorrycc / alfred-douban / index.js View on Github external
(async () => {
  const data = await alfy.fetch('https://api.douban.com/v2/movie/search', {
    query: {
      q: encodeURI(alfy.input),
    },
  });

  if (!data.subjects) {
    alfy.error(new Error(`API request failed`));
    return;
  }

  if (data.subjects.length === 0) {
    alfy.output([
      {
        title: `No movie found ${alfy.input}`,
        subtitle: 'Click to see the result for yourself',
        arg: `https://www.douban.com/search?cat=1002&q=${alfy.input}`,
github jonrohan / alfred-figma / lib / utils.js View on Github external
const getResults = async function(url) {
  const cache =  alfy.cache.get(url)
  if (cache) {
    return cache
  }
  return alfy.fetch(`https://api.figma.com/v1${url}`, {
    query: { },
    headers: { 'Content-Type': 'application/json', 'x-figma-token': process.env.FIGMA_TOKEN },
    json: true
  }).then(data => {
    alfy.cache.set(url, data, {maxAge: 1000 * 60 * 60 * 24})
    return data
  })
}
github CoderMageFox / alfredMagic / StackOverFlow / so.js View on Github external
getResultFromSo(ResultValueArr) {
        let transResult, outputResult;
        transResult = ResultValueArr[0].arg;
        outputResult = [];
        //此处是为了在第一项中显示翻译结果,添加了第一项的结果查询
        outputResult.push(ResultValueArr[0]);
        let encodedtransResult = encodeURI(transResult);
        alfy.fetch(`https://api.stackexchange.com/2.2/search?order=desc&sort=votes&intitle=${encodedtransResult}&site=stackoverflow`, transResult).then((Result) => {
            if (Result.items.length === 0) {
                outputResult.push({
                    title: '无可用回答,请尝试重新输入',
                    subtitle: '提示:请不要输入过多的关键字以免影响翻译',
                    arg: null
                })
            } else {
                Result.items.map((question) => {
                    outputResult.push({
                        title: question.title,
                        subtitle: `已有回答${question.answer_count || 0}个,浏览数${question.view_count || 0}个`,
                        arg: question.link
                    });
                })
            }
            alfy.output(outputResult);
github spinscale / alfred-workflow-elastic-docs / src / request.js View on Github external
exports.request = (query, opts = {}, url='https://host-nm1h2z.api.swiftype.com/api/as/v1/engines/elastic-en-us/search') => {
  if (query.query === null || query.query.trim().length == 0) {
    return Promise.resolve([])
  }
  let json = { query: query.query, page:{ size: 10 },"search_fields":{"title":{"weight":3}, "body":{}},"result_fields":{"title":{"raw":{}},"url":{"raw":{}},"product_name":{"raw":{}}},"filters":{"all":[{"website_area":["documentation"]}]}}
  if (query.product !== null && query.product != undefined) {
    json.filters.all[json.filters.all.length] = {"product_name": [query.product] }
  }
  if (query.version !== null && query.version != undefined) {
    json.filters.all[json.filters.all.length] = {"product_version": [query.version] }
  }

  var headers = { "Authorization": "Bearer search-yq8eq2orbgnmq1jjjfw4hocv" }
  var opts = Object.assign(opts, { method: "POST", body: json, json: true, headers: headers })
  return alfy.fetch(url, opts)
  .then(res => {
    if (res.meta.page.total_results == 0) {
      return Promise.resolve([{ title: 'No results found', icon: { path: rootDir + '/icon.png' } }])
    }
    const items = res.results.map(hit => {
      var product = _.find(Object.keys(icons), (name) => { return hit.product_name.raw.toLowerCase().includes(name) })
      let icon = product !== undefined ? icons[product] : icons['elasticsearch']

      return {
        title: striptags(hit.title.raw),
        subtitle: striptags(hit.product_name.raw),
        arg: hit.url.raw,
        icon: { path: icon }
      }
    })
github skibitsky / alfred-timing / projects.js View on Github external
'use strict';
import {env} from 'process';
import {fetch, output, inputMatches} from 'alfy';

const Authorization = 'Bearer ' + env.token;

fetch('https://web.timingapp.com/api/v1/projects', {
	headers: {
		'Content-Type': 'application/json',
		Authorization
	},
	json: true
}).then(result => {
	const data = result.data.map(pr => {
		return {
			uid: pr.self,
			title: pr.title,
			autocomplete: pr.title,
			arg: pr.title
		};
	});

	output(inputMatches(data, 'title'));