Git Product home page Git Product logo

esa-exporter's Introduction

@suin/esa-exporter

esa.io API から全データをエクスポートするライブラリ。

esa.io のエクスポート機能はマークダウンファイルがダウンロードできるだけで、他の情報が入ってこないためこれを開発しました。

特徴

  • エクスポートに対応しているデータ
    • メンバー
    • 投稿
      • コメント
      • stargazers

インストール

yarn add @suin/esa-exporter
# or
npm install @suin/esa-exporter

使い方

基本的な用法:

import { exportAll, Entity } from "@suin/esa-exporter";

(async () => {
  const team = process.env.ESA_TEAM;
  const token = process.env.ESA_TOKEN;
  const entities: Entity[] = [];

  for await (const entity of exportAll({ team, token })) {
    entities.push(entity);
  }

  console.log(entities);
})();

出力例:

[
  {
    $type: "member",
    myself: true,
    name: "Taro Tanaka",
    screen_name: "tanaka",
    icon:
      "https://img.esa.io/uploads/production/users/1/icon/thumb_m_********.png",
    role: "owner",
    posts_count: 222,
    joined_at: "2014-07-01T08:10:55+09:00",
    last_accessed_at: "2019-12-27T16:23:23+09:00",
    email: "[email protected]",
  },
  {
    $type: "member",
    myself: false,
    name: "Hanako Sato",
    screen_name: "sato",
    icon:
      "https://img.esa.io/uploads/production/users/2/icon/thumb_m_********.jpg",
    role: "owner",
    posts_count: 111,
    joined_at: "2014-07-01T08:19:26+09:00",
    last_accessed_at: "2019-08-13T18:07:24+09:00",
    email: "[email protected]",
  },
  {
    $type: "post",
    number: 1,
    name: "esa APIの使い方",
    full_name: "日報/2015/05/09/esa APIの使い方 #api #dev",
    wip: true,
    body_md: "...",
    body_html: "...",
    created_at: "2015-05-09T11:54:50+09:00",
    message: "初稿です!",
    url: "https://example.esa.io/posts/1",
    updated_at: "2015-05-09T11:54:51+09:00",
    tags: ["api", "dev"],
    category: "日報/2015/05/09",
    revision_number: 1,
    created_by: {
      myself: true,
      name: "Taro Tanaka",
      screen_name: "tanaka",
      icon:
        "https://img.esa.io/uploads/production/users/1/icon/thumb_m_********.png",
    },
    updated_by: {
      myself: true,
      name: "Taro Tanaka",
      screen_name: "tanaka",
      icon:
        "https://img.esa.io/uploads/production/users/1/icon/thumb_m_********.png",
    },
  },
];

exportAllは様々なエンティティをごちゃまぜで返してくるので、 エンティティ種別ごとに何らかの処理をする必要がある場合は、Entity[$type]で分岐処理を書いてください:

import { exportAll, Member, Post } from "@suin/esa-exporter";

(async () => {
  const team = process.env.ESA_TEAM;
  const token = process.env.ESA_TOKEN;

  const members: Member[] = [];
  const posts: Post[] = [];

  for await (const entity of exportAll({ team, token })) {
    switch (entity.$type) {
      case "member":
        members.push(entity);
        break;
      case "post":
        posts.push(posts);
        break;
    }
  }
})();

API リファレンス

https://suin.github.io/esa-exporter/

esa-exporter's People

Contributors

semantic-release-bot avatar suin avatar

Stargazers

 avatar

Watchers

 avatar  avatar  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.