Git Product home page Git Product logo

esa-api's Introduction

@suin/esa-api

esa.io API のクライアントライブラリ。

特徴

  • すべてのエンドポイントに対応しています。
  • esa API の OpenAPI 仕様書から生成したクライアントライブラリをベースに一部拡張を加えたライブラリです。

インストール

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

使い方

基本的な用法:

import { createClient } from "@suin/esa-api";

const teamName = "your_team_name";

const client = createClient({
  token: process.env.ESA_TOKEN, // アクセストーン
});

{
  // 記事一覧を取得する
  const {
    data: { posts },
  } = await client.getPosts({ teamName });
}

{
  // 指定した記事を取得する
  const { data: post } = await client.getPost({ teamName, postNumber: 1 });
}

{
  // 記事を新規投稿する
  const { data: createdPost } = await client.createPost({
    teamName,
    post: {
      name: "hi!",
      body_md: "# Getting Started\n",
      tags: ["api", "dev"],
      category: "dev/2015/05/10",
      wip: false,
      message: "Add Getting Started section",
    },
  });
}

{
  // 指定した記事を編集する
  const { data: updatedPost } = await client.updatePost({
    teamName,
    postNumber: 1,
    updatePostBody: {
      post: {
        wip: false,
        message: "Ship it!",
      },
    },
  });
}

複雑なクエリの例:

import { createClient } from "@suin/esa-api";

const teamName = "your_team_name";

const client = createClient({
  token: process.env.ESA_TOKEN,
});

// 細かい条件を設定して記事一覧を取得する
const response = await client.getPosts({
  teamName,
  q: "wip:false",
  include: ["comments", "comments.stargazers", "stargazers"],
  sort: "updated",
  order: "desc",
  per_page: 100,
  page: 1,
});

// 結果からは様々な付随情報が得られます:
// 1. 記事一覧
const { posts } = response.data;
// 2. 利用制限
const { limit, remaining, reset } = response.ratelimit;
// 3. ページネーション
const { prev_page, next_page, page, per_page, max_per_page, total_count } =
  response.data;

API リファレンス

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

esa-api's People

Contributors

semantic-release-bot avatar suin avatar

Stargazers

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