feat: ref codes

This commit is contained in:
Kieran 2023-11-30 16:37:42 +00:00
parent 9e4a0542ea
commit 6f8e8eca0f
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941

View File

@ -78,6 +78,10 @@ export interface RelayDistance {
description?: string; description?: string;
} }
export interface RefCodeResponse {
code: string
}
export default class SnortApi { export default class SnortApi {
#url: string; #url: string;
#publisher?: EventPublisher; #publisher?: EventPublisher;
@ -99,8 +103,8 @@ export default class SnortApi {
return this.#getJson<Array<string>>(`api/v1/twitter/follows-for-nostr?username=${encodeURIComponent(username)}`); return this.#getJson<Array<string>>(`api/v1/twitter/follows-for-nostr?username=${encodeURIComponent(username)}`);
} }
createSubscription(type: number) { createSubscription(type: number, refCode?: string) {
return this.#getJsonAuthd<InvoiceResponse>(`api/v1/subscription?type=${type}`, "PUT"); return this.#getJsonAuthd<InvoiceResponse>(`api/v1/subscription?type=${type}&refCode=${refCode}`, "PUT");
} }
renewSubscription(id: string, months = 1) { renewSubscription(id: string, months = 1) {
@ -135,6 +139,10 @@ export default class SnortApi {
return this.#getJson<Array<RelayDistance>>(`api/v1/relays?count=${count}`, "POST", { lat, lon }); return this.#getJson<Array<RelayDistance>>(`api/v1/relays?count=${count}`, "POST", { lat, lon });
} }
getRefCode() {
return this.#getJsonAuthd<RefCodeResponse>("api/v1/referral", "GET");
}
async #getJsonAuthd<T>( async #getJsonAuthd<T>(
path: string, path: string,
method?: "GET" | string, method?: "GET" | string,