socialblade
Advanced tools
Comparing version 0.0.1 to 0.0.2
import { IClient } from './interfaces/client.interface'; | ||
import { IUser } from './interfaces/user.interface'; | ||
import { IDeveloper } from './interfaces/dev.interface'; | ||
export declare class SocialBladeClient { | ||
@@ -12,2 +13,3 @@ private Http; | ||
AuthAsUser(email: IClient['email'], token: IClient['token']): Promise<IUser>; | ||
Auth(key: IClient['key']): Promise<IDeveloper>; | ||
} |
@@ -26,3 +26,3 @@ "use strict"; | ||
} | ||
isAuthed() { return this.Client.user !== undefined || this.Client.token !== undefined; } | ||
isAuthed() { return this.Client.user !== undefined || this.Client.key !== undefined; } | ||
async AuthAsUser(email, token) { | ||
@@ -44,4 +44,17 @@ const response = await this.Http.get({ | ||
} | ||
async Auth(key) { | ||
const response = await this.Http.get({ | ||
uri: endpoints_1.Endpoints.DeveloperAuth, | ||
qs: { key } | ||
}); | ||
const body = response.body; | ||
// If there is an error we can just return the body | ||
if (body.status.error) | ||
return body; | ||
// If there isn't an error then we can set the client as active then return the body | ||
this.Client = { user: false, key }; | ||
return body; | ||
} | ||
} | ||
exports.SocialBladeClient = SocialBladeClient; | ||
//# sourceMappingURL=client.js.map |
export * from './client'; | ||
export * from './interfaces/client.interface'; | ||
export * from './interfaces/user.interface'; | ||
export * from './interfaces/dev.interface'; |
export declare class Endpoints { | ||
static readonly UserAuth: string; | ||
static readonly DeveloperAuth: string; | ||
} |
@@ -6,3 +6,4 @@ "use strict"; | ||
Endpoints.UserAuth = "/bridge"; | ||
Endpoints.DeveloperAuth = "/third-party"; | ||
exports.Endpoints = Endpoints; | ||
//# sourceMappingURL=endpoints.js.map |
{ | ||
"name": "socialblade", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Library for Social Blade in JavaScript", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -1,2 +0,2 @@ | ||
# Social Blade API in JavaScript [<img align="right" src="https://socialblade.com/images/media/red/2.png">](https://github.com/TimothyCole/socialblade-js) | ||
# Social Blade API in JavaScript [<img align="right" src="https://cdn.tcole.me/socialblade-small.png">](https://github.com/TimothyCole/socialblade-js) | ||
@@ -18,6 +18,42 @@ [](https://travis-ci.com/TimothyCole/socialblade-js) | ||
## Install, Usage, Example | ||
Coming Soon | ||
## Install | ||
```bash | ||
npm install --save socialblade | ||
``` | ||
## Usage | ||
Import the library into your project and construct a new client which will be used to access the API. | ||
Use either the third-party `Auth` function or first-party `AuthAsUser` function to set the client as "active". | ||
#### TypeScript | ||
```ts | ||
import { SocialBladeClient } from 'socialblade'; | ||
const socialblade: SocialBladeClient = new SocialBladeClient(); | ||
// Third-Party Auth | ||
socialblade.Auth("Third-Party API Key").then((data: IDeveloper) => { | ||
console.log(data) | ||
}); | ||
// First-Party Auth | ||
socialblade.AuthAsUser("User Email", "User Access Token").then((data: IUser) => { | ||
console.log(data) | ||
}); | ||
``` | ||
#### ES6+ | ||
```js | ||
const SocialBladeClient = require("socialblade").SocialBladeClient; | ||
const socialblade = new SocialBladeClient(); | ||
// Third-Party Auth | ||
socialblade.Auth("Third-Party API Key").then(console.log) | ||
// First-Party Auth | ||
socialblade.AuthAsUser("User Email", "User Access Token").then(console.log) | ||
``` | ||
## Example | ||
_Examples coming soon. Library still early development_ | ||
## Troubleshooting | ||
If you have official access to the Social Blade API via express permission from the company then feel free to contact me via [Twitter](https://twitter.com/messages/compose?recipient_id=1690693537) or [email me](mailto:tim@timcole.me?cc=tim@socialblade.com&subject=Social%20Blade%20JavaScript%20Library%20Inquiry) for any help. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
13082
23
123
59