@accentor/api-client-js 中文文档教程
Accentor API Client
Install
使用您选择的包管理器进行安装:
yarn add @accentor/api-client-js
npm install @accentor/api-client-js
How to use
要初始化 API 客户端:
import { createApiClient } from "@accentor/api-client-js";
const baseURL = /* Your logic for baseURL, including /api/ */
const api = createApiClient(baseURL);
Overview of functions
所有函数都应提供一个包含 device_id
和 secret
的 auth 对象。 创建身份验证令牌时,您可以省略此对象。
并非所有功能都适用于每个型号。 只能调用该模型可用的路由。
// Index (some indexes can be called with an optional scope, see below)
const generator = api.users.index(auth);
const { results, done } = await generator.next();
// Create
const result = await api.tracks.create(auth, objectToCreate);
// Read
const result = await api.tracks.read(auth, id);
// Update
const result = await api.tracks.update(auth, id, object);
// Destroy
const true = await api.tracks.destroy(auth, id);
// Destroy empty
const true = await api.albums.destroyEmpty(auth, id);
// Merge
const result = await api.tracks.merge(auth, newId, oldID);
// Start rescan
const result = await api.rescan.start(auth);
// Get rescan status
const result = await api.rescan.show(auth);
Adding scopes to indexes
如果你想过滤通过 indexGenerator
获取的项目,你可以传递一个可选的范围。 我们目前有专辑、艺术家和曲目
的范围使用的范围示例:
import { AlbumsScope } from "@accentor/api-client-js";
const scope = new AlbumsScope.label(1);
const generator = api.albums.index(auth, scope)
您可以用不同的方式创建范围:
- created on a single line
new AlbumsScope.label(id)
- chained for more complex queries
new AlbumsScope.label(id).artist(id).filter(string)
- created and then modified:
const scope = new AlbumsScope()
scope.label(id)
scope.artist(id)
scope.finalQuery
Overview of available scopes
// Albums
new AlbumsScope.artist(artist_id)
new AlbumsScope.label(label_id)
new AlbumsScope.labels([label_id, label_id, ...])
new AlbumsScope.filter(string) // Search in album titles
// Artists
new ArtistsScope.filter(string) // Search in artist names
// Tracks
new TracksScope.album(album_id)
new TracksScope.artist(artist_id)
new TracksScope.genre(genre_id)
new TracksScope.filter(string) // Search in track titles
Versioning
这个包的版本控制基于 API。 这样,路由和范围的更改将在与 API 中相同的版本中引入。 可以发布补丁版本来修复这个包本身的问题。
Accentor API Client
Install
Install using your package manger of choice:
yarn add @accentor/api-client-js
npm install @accentor/api-client-js
How to use
To intialize the API client:
import { createApiClient } from "@accentor/api-client-js";
const baseURL = /* Your logic for baseURL, including /api/ */
const api = createApiClient(baseURL);
Overview of functions
All functions should be provided with an auth object containing the device_id
and secret
. When creating an auth token, you can leave out this object.
Not every function is available for every model. Only the routes available to that model can be called.
// Index (some indexes can be called with an optional scope, see below)
const generator = api.users.index(auth);
const { results, done } = await generator.next();
// Create
const result = await api.tracks.create(auth, objectToCreate);
// Read
const result = await api.tracks.read(auth, id);
// Update
const result = await api.tracks.update(auth, id, object);
// Destroy
const true = await api.tracks.destroy(auth, id);
// Destroy empty
const true = await api.albums.destroyEmpty(auth, id);
// Merge
const result = await api.tracks.merge(auth, newId, oldID);
// Start rescan
const result = await api.rescan.start(auth);
// Get rescan status
const result = await api.rescan.show(auth);
Adding scopes to indexes
If you want to filter the items fetched by through indexGenerator
, you can pass an optional scope. We currently have scopes for albums, artists and tracks
An example of a scope used:
import { AlbumsScope } from "@accentor/api-client-js";
const scope = new AlbumsScope.label(1);
const generator = api.albums.index(auth, scope)
You can create scopes in different ways:
- created on a single line
new AlbumsScope.label(id)
- chained for more complex queries
new AlbumsScope.label(id).artist(id).filter(string)
- created and then modified:
const scope = new AlbumsScope()
scope.label(id)
scope.artist(id)
scope.finalQuery
Overview of available scopes
// Albums
new AlbumsScope.artist(artist_id)
new AlbumsScope.label(label_id)
new AlbumsScope.labels([label_id, label_id, ...])
new AlbumsScope.filter(string) // Search in album titles
// Artists
new ArtistsScope.filter(string) // Search in artist names
// Tracks
new TracksScope.album(album_id)
new TracksScope.artist(artist_id)
new TracksScope.genre(genre_id)
new TracksScope.filter(string) // Search in track titles
Versioning
This package bases its versioning on the major and minor versions of the API. This way, changes in routes and scopes are introduced in the same version that they are introduced in the API. Patch releases can be issued to fix issues in this package itself.