Coder Social home page Coder Social logo

vanilevsky / zenmoney-api Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sleepwalker/zenmoney-api

0.0 0.0 0.0 220 KB

A nodejs implementation of zenmoney api: https://github.com/zenmoney/ZenPlugins/wiki/ZenMoney-API

JavaScript 9.80% TypeScript 90.20%

zenmoney-api's Introduction

A nodejs implementation of zenmoney api: https://github.com/zenmoney/ZenPlugins/wiki/ZenMoney-API

Установка

npm install zenmoney-api

или

yarn add zenmoney-api

Примеры использования

Авторизация по токену

import { zenmoneyApi } from 'zenmoney-api';

const token = '...';

(async () => {
  try {
    await zenmoneyApi.authorizeByToken(token);

    const diff = await zenmoneyApi.diff({
      // fetch prev two months
      serverTimestamp: Math.round(
        (Date.now() - 60 * 24 * 60 * 60 * 1000) / 1000,
      ),
    });

    // strip arrays to only 3 items
    Object.values(diff).forEach((item) => {
      if (Array.isArray(item)) {
        item.splice(0, item.length - 3);
      }
    });

    console.dir(diff, { depth: null });

    const suggestion = await zenmoneyApi.suggest({
      payee: 'McDonalds',
    });

    console.log('Suggestion for McDonalds');
    console.dir(suggestion, { depth: null });
  } catch (error) {
    console.log('Error requesting diff', {
      error,
      request: error.request,
      response: error.response,
    });

    process.exit(1);
  }

  process.exit(0);
})();

Авторизация по логину и паролю

import { zenmoneyApi } from 'zenmoney-api';

const username = '...';
const password = '...';
const apiKey = '...';
const apiSecret = '...';

(async () => {
  try {
    await zenmoneyApi.authorize({
      username,
      password,
      apiKey,
      apiSecret,
    });

    const diff = await zenmoneyApi.diff({
      // fetch prev two months
      serverTimestamp: Math.round(
        (Date.now() - 60 * 24 * 60 * 60 * 1000) / 1000,
      ),
    });

    // strip arrays to only 3 items
    Object.values(diff).forEach((item) => {
      if (Array.isArray(item)) {
        item.splice(0, item.length - 3);
      }
    });

    console.dir(diff, { depth: null });

    const suggestion = await zenmoneyApi.suggest({
      payee: 'McDonalds',
    });

    console.log('Suggestion for McDonalds');
    console.dir(suggestion, { depth: null });
  } catch (error) {
    console.log('Error requesting diff', {
      error,
      request: error.request,
      response: error.response,
    });

    process.exit(1);
  }

  process.exit(0);
})();

Forked from https://github.com/SleepWalker/zenmoney-api

zenmoney-api's People

Contributors

vanilevsky avatar sleepwalker avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.