Skip to content
This repository has been archived by the owner on Apr 28, 2023. It is now read-only.

Commit

Permalink
client: end_session() & other device token methods now return void
Browse files Browse the repository at this point in the history
  • Loading branch information
maxrdz committed Jun 2, 2022
1 parent dfbf8a9 commit 6d2b8a1
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 36 deletions.
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,13 @@ Below is the simplest and fastest way to authenticate to Poparazzi using the pac
import * as Poparazzi from 'poparazzi-private-api';

;(async () => {
// Run the built-in quick login console prompt
// Run the built-in terminal login prompt
const client = new Poparazzi.Client({ interactive_login: true });

client.set_event({ login_success: async () => {
console.log(`Logged into Poparazzi!`);

let session = client.get_session();
let device_token = client.get_device_token();

device_token = await client.end_session(); // Logout
await client.end_session(); // Logout from Poparazzi
}});

client.set_event({ logout: async () => {
Expand All @@ -54,7 +51,7 @@ If you would like to implement a new feature or fix a bug, feel free to create a

API and SDK documentation also make very useful contributions, so if you are good at - please do so!

Before starting on your own contribution, please read [the contributor guidelines](CONTRIBUTING.md)!
Before starting on your own contribution, please read the [contributor guidelines](CONTRIBUTING.md)!

<br>

Expand Down
10 changes: 5 additions & 5 deletions docs/sdk-docs/classes/Client.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Class: `Client`

#### This class serves as the Poparazzi client object, which handles all API calls.
#### This class serves as the Poparazzi client object, which handles all Web / Streaming API calls.

## Class Properties

Expand Down Expand Up @@ -51,13 +51,13 @@

## end_session()

- #### `async` end_session(): [Promise]()<[AppleDeviceToken]() | _null_>
- #### `async` end_session(): [Promise]()<_[void]()_>

- This method ends a Poparazzi session by sending its device token without authorization.
- This method ends the session by sending a PATCH to its device token without authorization.

## generate_device_token()

- #### `async` generate_device_token(): [Promise]()<[AppleDeviceToken]() | _null_>
- #### `async` generate_device_token(): [Promise]()<_[void]()_>

- Sends a randomly generated [AppleDeviceToken]() to the **apple_device_tokens** API endpoint.

Expand Down Expand Up @@ -143,7 +143,7 @@

## send_device_token()

- #### `async` send_device_token(arg: _[DEVICE_TOKEN_ACTION]()_): [Promise]()<[AppleDeviceToken]() | _null_>
- #### `async` send_device_token(arg: _[DEVICE_TOKEN_ACTION]()_): [Promise]()<_[void]()_>

- This function is the under the hood implementation of the **apple_device_tokens** API endpoint.

Expand Down
10 changes: 1 addition & 9 deletions examples/interactive-login.example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,13 @@ import * as Poparazzi from '../';
;(async () => {
const client = new Poparazzi.Client({ interactive_login: true });

// Declare variables for objects returned by the client
let session: Poparazzi.Responses.Session | null;
let device_token: Poparazzi.Responses.AppleDeviceToken | null;

// The code below sets callback events.
// The client will call these functions when their event is triggered.

client.set_event({ login_success: async () => {
console.log(`Logged into Poparazzi!`);

session = client.get_session();
device_token = client.get_device_token();

// Logout from poparazzi
device_token = await client.end_session();
await client.end_session(); // Logout from poparazzi
}});

client.set_event({ login_failure: async () => {
Expand Down
6 changes: 2 additions & 4 deletions examples/manual-login.example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import * as readline from "node:readline";

// Declare variables for objects returned by the client
let session: Poparazzi.Responses.Session | null;
let device_token: Poparazzi.Responses.AppleDeviceToken | null;
let login_status: Poparazzi.CREDENTIAL_STATUS;

/*
Expand All @@ -24,8 +23,7 @@ import * as readline from "node:readline";
session = client.get_session(); // Get updated session with user relationship
console.log(`Poparazzi login success!`);

// Logout from poparazzi
device_token = await client.end_session();
await client.end_session(); // Logout from poparazzi
}});

client.set_event({ login_failure: async () => {
Expand All @@ -38,7 +36,7 @@ import * as readline from "node:readline";

// Create a new Poparazzi session & generate a device token
session = await client.create_session();
device_token = await client.generate_device_token();
await client.generate_device_token(); // required to log out

// The first step to link your session to a Poparazzi account is to verify your phone number.
login_status = await client.submit_phone_number();
Expand Down
6 changes: 0 additions & 6 deletions examples/streaming-api.example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ import * as Poparazzi from '../';
;(async () => {
const client = new Poparazzi.Client({ interactive_login: true });

let session: Poparazzi.Responses.Session | null;
let device_token: Poparazzi.Responses.AppleDeviceToken | null;

// Set event callback for when we connect to the streaming API
client.set_event({ websocket_connect: async () => {
console.log("Connected to the Streaming API!");
Expand All @@ -24,9 +21,6 @@ import * as Poparazzi from '../';
client.set_event({ login_success: async () => {
console.log(`Logged into Poparazzi!`);

session = client.get_session();
device_token = client.get_device_token();

// Connect and authenticate to the Poparazzi streaming API
const status = await client.connect_streaming_api({ auth: true });
}});
Expand Down
12 changes: 6 additions & 6 deletions src/poparazzi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export class Client {
});
}

private async send_device_token(arg: DEVICE_TOKEN_ACTION): Promise<Responses.AppleDeviceToken | null> {
private async send_device_token(arg: DEVICE_TOKEN_ACTION): Promise<void> {

return new Promise(async (resolve, reject) => {
let device_token_id = "";
Expand Down Expand Up @@ -200,15 +200,15 @@ export class Client {
this.device_token = null;
await this.trigger_event("logout"); // call logout event
} else {
Object.assign(this.device_token, data.data); // cast new response data to token
Object.assign(this.device_token, data.data); // cast new response data to client token
}
resolve(this.device_token);
resolve();
});
}
public async generate_device_token(): Promise<Responses.AppleDeviceToken | null> {
public async generate_device_token(): Promise<void> {
return this.send_device_token(DEVICE_TOKEN_ACTION.NEW_TOKEN);
}
public async end_session(): Promise<Responses.AppleDeviceToken | null> {
public async end_session(): Promise<void> {
return this.send_device_token(DEVICE_TOKEN_ACTION.END_SESSION);
}

Expand Down Expand Up @@ -281,7 +281,7 @@ export class Client {
const session = await this.create_session();

// Generate an Apple device token
this.device_token = await this.generate_device_token();
await this.generate_device_token();

// Callback function to prompt input for verification code (after phone number)
const verify_prompt = () => {
Expand Down

1 comment on commit 6d2b8a1

@maxrdz
Copy link
Owner Author

@maxrdz maxrdz commented on 6d2b8a1 Jun 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplified logging out, as end_session() doesn't need to return anything (it's useless)
To even things out, I kept this same 'void' return for all device token methods.

If the device token needs to be accessed for whatever reason after it has been generated, access it via Client.get_device_token().

Please sign in to comment.