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

Release v3.0.0 #2

Merged
merged 27 commits into from Aug 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 12 additions & 2 deletions CHANGELOG.md
Expand Up @@ -4,10 +4,20 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [3.0.0] - 2019-08-19
### Added
- Loyalty functionality

- Alerts functionality
- Credits functionality
- Jar functionality
- Wheel functionality
- Docs

### Changed
- **BREAKING**: All contracts changed
- Test integrations
- README

## [2.0.0] - 2019-08-11
### Added
- Params types in code
Expand Down
107 changes: 17 additions & 90 deletions README.md
Expand Up @@ -5,7 +5,7 @@

#### This module is a implementation of Streamlabs API https://dev.streamlabs.com/

You need nodejs version > 6x because this module was made with ES6.
You need nodejs version > 8x because this module was made with ES6.
```
node --version
```
Expand Down Expand Up @@ -33,116 +33,43 @@ Give the credentials of the StreamLabs to the constructor
| **accessToken** | *The access token if you have one* | **true** | string |

```js
const streamLabs = new StreamlabsApi({
const streamlabs = new StreamlabsApi({
clientId: 'clientId',
clientSecret: 'clientSecret',
redirectUrl: 'http://yourdomain/youraction',
scopes: 'donations.read donations.create alerts.create socket.token',
redirectUrl: 'http://yourdomain/yourrequest',
scopes: 'donations.read donations.create alerts.create socket.token alerts.write points.write points.read credits.write jar.write wheel.write',
});
```

### Authorization
To authenticate with OAuth you will call `authorizationUrl` and will return an URL, you will make a request with a browser and authorizate in OAuth. After that you will be redirect to `RedirectUrl` and you will get a `code` on QueryString `?code='hjqweassxzass'`

```js
const urlAuthorization = streamLabs.authorizationUrl();
```

### Get Access Token
For generate an access token and refresh token you have to call `connect` with the `code` you got on QueryString
------------

| Params | Description | Optional | Type |
| -------- |:---------------| :-----:| :-----:|
| **Code** | *The code you got in the querystring* | **false** | string |

```js
streamLabs.connect(code);
```

### Refresh Access Token
If you need refresh the access token, you have to call `reconnect` and send the `refreshToken`

| Params | Description | Optional | Type |
| -------- |:---------------| :-----:| :-----:|
| **RefreshToken** | *The refresh token you got in credentials* | **false** | string |

```js
streamLabs.reconnect(refreshToken);
```
------------

### Get Donations:
For get donations you have to call `getDonations` and stablish how much donations you want of the collection

| Params | Description | Optional | Type |
| -------- |:---------------| :-----:| :-----:|
| **Limit** | *Stablish how much donations you want of the collection* | **false** | integer |

```js
streamLabs.getDonations(10);
```
- #### [Authorization](https://github.com/tnovas/streamlabs/blob/master/docs/AUTHORIZATION.md)

### Add Donation:
For add donations you have to call `addDonations` and send an object params
- #### [Alerts](https://github.com/tnovas/streamlabs/blob/master/docs/ALERTS.md)

| Params | Description | Optional |
| -------- |:---------------| :-----:|
| **Donation** | *Object with <ul> <li>Name (string)</li> <li>Identifier (string)</li> <li>Amount (double)</li> <li>Currency: (string) - See [Currency Codes](https://dev.streamlabs.com/docs/currency-codes/)</li> <li>Message (string)</li></ul>* | **false** |
- #### [Donations](https://github.com/tnovas/streamlabs/blob/master/docs/DONATIONS.md)

```js
{
name: 'Name_of_user_donation',
identifier: 'Identifyuser@user.com',
amount: 10.20,
currency: 'USD',
message: 'A message'
}
```
- #### [Loyalty](https://github.com/tnovas/streamlabs/blob/master/docs/LOYALTY.md)

### Get alerts real time:
For get alerts on real time you have to call `connectWebSocket` and you will get a token, it should be used on WebSocket in the client
- #### [Wheel](https://github.com/tnovas/streamlabs/blob/master/docs/WHEEL.md)

```js
Server Side
streamLabs.connectWebSocket();
const { socketToken } = streamLabs.getCredentials();
- #### [Jar](https://github.com/tnovas/streamlabs/blob/master/docs/JAR.md)

Client Side
let socket = io(`https://sockets.streamlabs.com?token=${socketToken}`);
socket.on('event', eventData => console.log(eventData));
```
- #### [Credits](https://github.com/tnovas/streamlabs/blob/master/docs/CREDITS.md)

### Get Credentials:
If you need to save credentials, you have to call `getCredentials` and you will get an object
------------

```js
{
accessToken,
refreshToken,
expiresIn,
socketToken
}
```

### Promises
You can use Async Await
```js
async function getDonations() {
const donations = await streamLabs.getDonations(10);
console.log(donations);
}
------------

getDonations();
```

## Test Integration:
You can test the module with your productive credentials.
First change the `clientId` and `clientSecret` in `tests/integration.js` with yours credentials, open a console and run `npm start`, open browser and type `http://localhost:8080/`

### Urls:
- `http://localhost:8080/` return the url of [authorization](#authorization), copy and paste into the url of the browser
- `http://localhost:8080/getDonations?limit=10` return ten [donations](#get-donations)
- `http://localhost:8080/addDonation` [add donations](#add-donation) and return de id
- `http://localhost:8080/credentials` [get credentials](#get-credentials)
- `http://localhost:8080/connectSocket` return the [socket token](#get-alerts-real-time)
- `http://localhost:8080/reconnect` [refresh access token](#refresh-access-token)
First change the `clientId` and `clientSecret` in `tests/integration/streamlabs.js` with yours credentials, open a console and run `npm start`, open browser and type `http://localhost:8080/`

**WARNING** Always when you run npm start, the first link you click should be Authorization
70 changes: 70 additions & 0 deletions docs/ALERTS.md
@@ -0,0 +1,70 @@
## ALERTS

### Create
For create an alert you must call `alerts.create` and send an object param

| Params | Description | Optional |
| -------- |:---------------| :-----:|
| **alert** | *Object with <ul> <li>type (type)</li> <li>message (string)</li> <li>user_message (string)</li></ul>* | **false** |

```js
const { follow, subscription, donation, host } = streamlabs.alerts.types;

streamlabs.alerts.create({
type: donation, // follow, subscription, donation or host.
message: 'simple geometry',
user_message: 'I am second heading',
});
```

### Volume
For mute or unmute volume on alerts you must call `alerts.volume` and send the action

| Params | Description | Optional | Type |
| -------- |:---------------| :-----:| :-----:|
| **action** | *The action will trigger* | **false** | type |

```js
const { mute, unmute } = streamlabs.alerts.actions.volume;

streamlabs.alerts.volume(mute);

streamlabs.alerts.volume(unmute);
```

### Queue
For pause or unpause queue of alerts you must call `alerts.queue` and send the action

| Params | Description | Optional | Type |
| -------- |:---------------| :-----:| :-----:|
| **action** | *The action will trigger* | **false** | type |

```js
const { pause, unpause } = streamlabs.alerts.actions.queue;

streamlabs.alerts.queue(pause);

streamlabs.alerts.queue(unpause);
```

### Video
For show or hide video of alerts you must call `alerts.video` and send the action

| Params | Description | Optional | Type |
| -------- |:---------------| :-----:| :-----:|
| **action** | *The action will trigger* | **false** | type |

```js
const { show, hide } = streamlabs.alerts.actions.video;

streamlabs.alerts.video(show);

streamlabs.alerts.video(hide);
```

### Skip
For skip all alerts you must call `alerts.skip`

```js
streamlabs.alerts.skip();
```
62 changes: 62 additions & 0 deletions docs/AUTHORIZATION.md
@@ -0,0 +1,62 @@

## Authorization
To authenticate with OAuth you will call `authorizationUrl`. This method return a URL, you will make a request with browser and authorizate, then you will be redirect automatically to the URL passed on `redirectUrl` with a param `code` on QueryString `?code='hjqweassxzass'`

```js
const urlAuthorization = streamlabs.authorizationUrl();
```

### Get Access Token
For generate an access token and refresh token you call `connect` with the `code` you get on QueryString

| Params | Description | Optional | Type |
| -------- |:---------------| :-----:| :-----:|
| **Code** | *The code you got in the querystring* | **false** | string |

```js
streamlabs.connect(code);
```

### Get Credentials:
For get credentials you must call `credentials` and you will get an object

```js
console.log(streamlabs.credentials());

// output
{
accessToken: 'access_token',
refreshToken: 'refresh_token',
expiresIn: 3600,
socketToken: 'socket_token',
user: {
streamlabs: {
id:123,
display_name:"YourName"
},
twitch: {
id:123,
display_name:"YourName",
name: "your_name"
},
youtube: {
id:123,
title: 'YourName'
},
...
}
}
```

### Get token for alerts on real time:
For get token for alerts on real time you have to call `connectWebSocket` and you will get a token, it should be used on WebSocket in the client

```js
Server Side
streamlabs.connectWebSocket();
const { socketToken } = streamlabs.credentials();

Client Side
let socket = io(`https://sockets.streamlabs.com?token=${socketToken}`);
socket.on('event', eventData => console.log(eventData));
```
8 changes: 8 additions & 0 deletions docs/CREDITS.md
@@ -0,0 +1,8 @@
## CREDITS

### Roll:
For roll credits you must call `credits.roll`.

```js
streamlabs.credits.roll();
```
29 changes: 29 additions & 0 deletions docs/DONATIONS.md
@@ -0,0 +1,29 @@
## DONATIONS

### Get:
For get donations you must call `donations.get` and stablish how much donations you want.

| Params | Description | Optional | Type |
| -------- |:---------------| :-----:| :-----:|
| **limit** | *Stablish how much donations you want* | **false** | integer |

```js
streamlabs.donations.get(10);
```

### Add:
For add donations you must call `donations.add` and send an object params.

| Params | Description | Optional |
| -------- |:---------------| :-----:|
| **Donation** | *Object with <ul> <li>Name (string)</li> <li>Identifier (string)</li> <li>Amount (double)</li> <li>Currency: (string) - See [Currency Codes](https://dev.streamlabs.com/docs/currency-codes/)</li> <li>Message (string)</li></ul>* | **false** |

```js
streamlabs.donations.add({
name: 'Name_of_user_donation',
identifier: 'Identifyuser@user.com',
amount: 10.20,
currency: 'USD',
message: 'A message'
});
```
8 changes: 8 additions & 0 deletions docs/JAR.md
@@ -0,0 +1,8 @@
## JAR

### Empty:
For empty JAR you must call `jar.empty`.

```js
streamlabs.jar.empty();
```