Skip to content

Commit

Permalink
Merge pull request #30 from textileio/andrew/update-api-config
Browse files Browse the repository at this point in the history
Update api config
  • Loading branch information
andrewxhill authored Feb 14, 2020
2 parents aff757a + 399e52f commit 0946a94
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ Join us on our [public Slack channel](https://slack.textile.io/) for news, discu

## Usage

`js-textile` provides access to Textile APIs in apps based on an App Token. For details on getting an app token, see [textileio/textile](https://github.com/textileio/textile) or join the [Textile Slack](https://slack.textile.io).
`js-textile` provides access to Textile APIs in apps based on a Project Token. For details on getting an app token, see [textileio/textile](https://github.com/textileio/textile) or join the [Textile Slack](https://slack.textile.io).

### Threads APIs

Textile provides remote threads APIs your app can use.

- token: an app token from your textile project
- token: a project token from your textile project
- deviceId: a unique ID (uuid) for this user in your app

```js
let api = new textile.API({
token: '<app token>',
token: '<project token>',
deviceId: '<user id>'
})

Expand All @@ -51,7 +51,7 @@ Requires you run the Threads daemon (`threadsd`) on localhost. See [instructions

```js
let api = new textile.API({
token: '<app token>',
token: '<project token>',
deviceId: '<user id>',
dev: true
})
Expand Down
2 changes: 1 addition & 1 deletion examples/browser/localThreadsDaemon.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
(async function () {

window.api = new textile.API({
token: '<app token>',
token: '<project token>',
deviceId: '<user id>',
dev: true
})
Expand Down
11 changes: 6 additions & 5 deletions src/ThreadsConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ export class ThreadsConfig extends Config {
public token: string,
public deviceId: string,
public dev: boolean,
public apiScheme: string = 'https',
public api: string = 'cloud.textile.io',
public sessionPort: number = 8006,
public scheme: string = 'https',
public authApi: string = 'cloud.textile.io',
public authPort: number = 443,
public threadsApi: string = 'api.textile.io',
public threadsPort: number = 6007,
public transport: grpc.TransportFactory = grpc.WebsocketTransport(),
) {
super()
this.host = `${this.apiScheme}://${this.api}:${this.threadsPort}`
this.host = `${this.scheme}://${this.threadsApi}:${this.threadsPort}`
}
async start(sessionId?: string) {
if (sessionId !== undefined) {
Expand All @@ -30,7 +31,7 @@ export class ThreadsConfig extends Config {
await this.refreshSession()
}
get sessionAPI(): string {
return `${this.apiScheme}://${this.api}:${this.sessionPort}`
return `${this.scheme}://${this.threadsApi}:${this.authPort}`
}
private async refreshSession() {
if (this.dev) {
Expand Down
21 changes: 12 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ export type APIConfig = {
token: string
deviceId: string
dev?: boolean
apiScheme?: string
api?: string
sessionPort?: number
scheme?: string
authApi?: string
authPort?: number
threadsApi?: string
threadsPort?: number
}
export class API {
Expand All @@ -34,18 +35,20 @@ export class API {
config.token,
config.deviceId,
true,
config.apiScheme !== (null || undefined) ? config.apiScheme : 'http',
config.api !== (null || undefined) ? config.api : '127.0.0.1',
config.sessionPort !== (null || undefined) ? config.sessionPort : 8006,
config.scheme !== (null || undefined) ? config.scheme : 'http',
config.authApi !== (null || undefined) ? config.authApi : '127.0.0.1',
config.authPort !== (null || undefined) ? config.authPort : 8006,
config.threadsApi !== (null || undefined) ? config.threadsApi : '127.0.0.1',
config.threadsPort !== (null || undefined) ? config.threadsPort : 6007,
)
: new ThreadsConfig(
config.token,
config.deviceId,
false,
config.apiScheme !== (null || undefined) ? config.apiScheme : 'https',
config.api !== (null || undefined) ? config.api : 'cloud.textile.io',
config.sessionPort !== (null || undefined) ? config.sessionPort : 8006,
config.scheme !== (null || undefined) ? config.scheme : 'https',
config.authApi !== (null || undefined) ? config.authApi : 'cloud.textile.io',
config.authPort !== (null || undefined) ? config.authPort : 443,
config.threadsApi !== (null || undefined) ? config.threadsApi : 'api.textile.io',
config.threadsPort !== (null || undefined) ? config.threadsPort : 6007,
)
}
Expand Down

0 comments on commit 0946a94

Please sign in to comment.