Giter Club home page Giter Club logo

freee-gen-csv's Introduction

openapi-generaterを用いたgo sdkの生成

openapi-generator generate -g go -i pkg/freeeclient/api/openapi.yaml -o pkg/freeeclient --git-user-id Yoii-Inc --git-repo-id freee-gen-csv --additional-properties=packageVersion=0.2.0,packageName=freeeclient --type-mappings=integer=int64
  1. Remove go.mod, go.sum in pkg/freeeclient

概要

freeeの取引履歴のうち、売上高のみ取り出しCSV(sales.csv)へ出力する

事前インストール

Go(1.16)のインストール

https://golang.org/doc/install 上記のリンクを参照

GNU Makeのインストール

インストールされていれば、以下のコマンドを実行して確認可能

make --version

ビルド用のバイナリインストール

make devel-deps

ビルド

バイナリのビルド

./bin/gen-sales-csvが生成される

make build

環境変数の設定

.envファイルの作成

プロジェクト直下の.env.templateをコピーし、.envを作成する。

Client ID、Client Secretの取得

https://developer.freee.co.jp/tutorials/starting-api

上記のリンクに従って行う。

ただし、コールバックURLにはurn:ietf:wg:oauth:2.0:oobを入力する。

取得した値を、.envCLIENT_IDCLIENT_SECRETへ入力する

Tokenの取得

https://developer.freee.co.jp/tutorials/getting-access-token

上記のリンクに従って行う。

まずは認可コードを取得する。その後、以下のPostを実行する。

curl -i -X POST \
 -H "Content-Type:application/x-www-form-urlencoded" \
 -d "grant_type=authorization_code" \
 -d "client_id={クライアントId}" \
 -d "client_secret={クライアントSecret}" \
 -d "code={認可コード}" \
 -d "redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob" \
 'https://accounts.secure.freee.co.jp/public_api/token'

以下のようなレスポンスが返ってくる

{"access_token":"{アクセストークン}","token_type":"bearer","expires_in":86399,"refresh_token":"{リフレッシュトークン}","scope":"read write default_read","created_at":1620802518}

Company Idの取得

https://developer.freee.co.jp/docs/accounting/reference#/ 上記のリンクからAPIコールを行って取得する。

/api/1/companiesの鍵マークにアクセストークンを入力して実行する。

取得したら、.envCOMPANY_IDへ入力する

# レスポンス例
{
  "companies": [
    {
      "id": 1234567,
      "name": null,
      "name_kana": null,
      "display_name": "開発用テスト事業所",
      "role": "admin"
    }
  ]
}

実行

初回の実行(Tokenの入力が必要)

./bin/gen-sales-csv --access-token={アクセストークン} --refresh-token={リフレッシュトークン}

./out/sales.csvが生成される。

また、トークンが./token.bへ保存される

2回目以降の実行

./bin/gen-sales-csv

./out/sales.csvが生成される。

また、トークンの有効期限が切れた場合のリフレッシュは自動で行われ、./token.bへ保存される

freee-gen-csv's People

Contributors

banoth-ravinder avatar taskooh 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.