Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ client.getPeople().then((people) => {
- [ ] recorded start time
- [ ] get the current timer if you want
- [ ] full item length
- [ ] end item on time
- [ ] to end item on time
- [ ] live control
- [ ] take/release control
- [ ] restart / jump to end of plan
Expand Down
4 changes: 2 additions & 2 deletions example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ let services = new ServicesClient({
secret: process.env["PCO_SECRET"] || "",
});

const folders = await services.getFolders({ per_page: 100 });
const songs = await services.getSongs({ per_page: 100 });

console.log(folders.join("\n"));
console.log(songs.join("\n"));
2 changes: 1 addition & 1 deletion jsr.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://jsr.io/schema/config-file.v1.json",
"name": "@svecs132/pco-api",
"version": "0.0.2",
"version": "0.0.3",
"license": "MIT",
"exports": "./mod.ts",
"publish": {
Expand Down
3 changes: 2 additions & 1 deletion mod.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { ServicesClient } from "./src/services";
export { default as ServicesClient } from "./src/services";
export * as services from "./src/services";
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export type Options = { appId: string; secret: string; debug?: boolean };
export abstract class Client {
private readonly appId: string;
private readonly secret: string;
private debug: boolean = false;
private debug: boolean;
abstract readonly baseUrl: string;

constructor(options: Options) {
Expand Down
12 changes: 12 additions & 0 deletions src/services/arrangement.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Resource, Client } from "./..";
import * as types from "../types";

export default class Arrangement extends Resource<types.Arrangement> {
constructor(client: Client, data: types.Arrangement) {
super(client, data);
}

toString(): string {
return `(\x1b[33mArrangement\x1b[0m \x1b[2m:id\x1b[0m ${this.id} \x1b[2m:name\x1b[0m ${this.attributes.name})`;
}
}
4 changes: 2 additions & 2 deletions src/services/folder.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Resource, Client, type RequestPagination, paginate } from "./..";
import * as types from "../types";

import { ServiceType } from "./service_type";
import ServiceType from "./service_type";

export class Folder extends Resource<types.Folder> {
export default class Folder extends Resource<types.Folder> {
constructor(client: Client, data: types.Folder) {
super(client, data);
}
Expand Down
43 changes: 38 additions & 5 deletions src/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ import {
} from "./..";
import * as types from "../types";

import { Folder } from "./folder";
import { Organization } from "./organization";
import { Person } from "./person";
import { ServiceType } from "./service_type";
import Arrangement from "./arrangement";
import Folder from "./folder";
import Item from "./item";
import Organization from "./organization";
import Person from "./person";
import Plan from "./plan";
import ServiceType from "./service_type";
import Song from "./song";

export class ServicesClient extends Client {
export default class ServicesClient extends Client {
readonly baseUrl: string = `${BASE_URL}/services/v2`;

constructor(options: Options) {
Expand Down Expand Up @@ -78,4 +82,33 @@ export class ServicesClient extends Client {
}
return new ServiceType(this, res.data);
}

public async getSongs(pagination: RequestPagination = {}): Promise<Song[]> {
const path = `songs?${paginate(pagination)}`;
const res = await this.fetch<types.Song[]>(path);
if ("errors" in res) {
throw new Error(`Error fetching songs: ${res.errors}`);
}
return res.data.map((data) => new Song(this, data));
}

public async getSong(id: string): Promise<Song> {
const path = `songs/${id}`;
const res = await this.fetch<types.Song>(path);
if ("errors" in res) {
throw new Error(`Error fetching song: ${res.errors}`);
}
return new Song(this, res.data);
}
}

export {
Arrangement,
Folder,
Item,
Organization,
Person,
Plan,
ServiceType,
Song,
};
2 changes: 1 addition & 1 deletion src/services/item.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Resource, Client } from "./..";
import * as types from "../types";

export class Item extends Resource<types.Item> {
export default class Item extends Resource<types.Item> {
constructor(client: Client, data: types.Item) {
super(client, data);
}
Expand Down
2 changes: 1 addition & 1 deletion src/services/organization.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Resource, Client } from "./..";
import * as types from "../types";

export class Organization extends Resource<types.Organization> {
export default class Organization extends Resource<types.Organization> {
constructor(client: Client, data: types.Organization) {
super(client, data);
}
Expand Down
2 changes: 1 addition & 1 deletion src/services/person.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Resource, Client } from "./..";
import * as types from "../types";

export class Person extends Resource<types.Person> {
export default class Person extends Resource<types.Person> {
constructor(client: Client, data: types.Person) {
super(client, data);
}
Expand Down
4 changes: 2 additions & 2 deletions src/services/plan.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Resource, Client, type RequestPagination, paginate } from "./..";
import * as types from "../types";

import { Item } from "./item";
import Item from "./item";

export class Plan extends Resource<types.Plan> {
export default class Plan extends Resource<types.Plan> {
private serviceTypeId: string;

constructor(client: Client, data: types.Plan) {
Expand Down
4 changes: 2 additions & 2 deletions src/services/service_type.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Resource, Client, type RequestPagination, paginate } from "./..";
import * as types from "../types";

import { Plan } from "./plan";
import Plan from "./plan";

export class ServiceType extends Resource<types.ServiceType> {
export default class ServiceType extends Resource<types.ServiceType> {
constructor(client: Client, data: types.ServiceType) {
super(client, data);
}
Expand Down
34 changes: 34 additions & 0 deletions src/services/song.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Resource, Client, type RequestPagination, paginate } from "./..";
import * as types from "../types";

import Arrangement from "./arrangement";

export default class Song extends Resource<types.Song> {
constructor(client: Client, data: types.Song) {
super(client, data);
}

toString(): string {
return `(\x1b[33mSong\x1b[0m \x1b[2m:id\x1b[0m ${this.id} \x1b[2m:title\x1b[0m ${this.attributes.title})`;
}

public async getArrangements(
pagination: RequestPagination = {}
): Promise<Arrangement[]> {
const path = `songs/${this.id}/arrangements?${paginate(pagination)}`;
const res = await this.client.fetch<types.Arrangement[]>(path);
if ("errors" in res) {
throw new Error(`Error fetching arrangements: ${res.errors}`);
}
return res.data.map((data) => new Arrangement(this.client, data));
}

public async getArrangement(id: string): Promise<Arrangement> {
const path = `songs/${this.id}/arrangements/${id}`;
const res = await this.client.fetch<types.Arrangement>(path);
if ("errors" in res) {
throw new Error(`Error fetching arrangement: ${res.errors}`);
}
return new Arrangement(this.client, res.data);
}
}