Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: migrate 'StreamLabs' to TypeScript #100

Merged
merged 1 commit into from
Apr 18, 2020
Merged
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
29 changes: 0 additions & 29 deletions src/services/StreamLabs.js

This file was deleted.

41 changes: 41 additions & 0 deletions src/services/StreamLabs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import axios from 'axios';

interface StreamLabsConfig {
token: string;
}

interface StreamLabsLogger {
log: (levels: string[], log: any) => void;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is actually

log: (tags: [], log: string|object) => void

We'll update it when we decide how to improve the logging system (see #103)

}

interface StreamLabsAlert {
message: string;
}

export class StreamLabs {
private base: string;
private token: string;
private logger: StreamLabsLogger;

constructor({ token }: StreamLabsConfig, logger: StreamLabsLogger) {
this.base = 'https://streamlabs.com/api/v1.0';
this.token = token;
this.logger = logger;
}

async alert({ message }: StreamLabsAlert) {
try {
await axios.post(`${this.base}/alerts`, {
access_token: this.token,
message,
type: 'follow',
});
} catch (error) {
if (this.logger) {
this.logger.log(['error', 'streamlabs'], { data: error.response.data });
}

throw error;
}
}
}