Skip to content

Commit

Permalink
Merge pull request #130 from deepgram/readme-methods
Browse files Browse the repository at this point in the history
updated readme to have examples of all methods
  • Loading branch information
briancbarrow authored May 24, 2023
2 parents 3f53bc7 + 971a427 commit e425e95
Show file tree
Hide file tree
Showing 3 changed files with 355 additions and 5 deletions.
353 changes: 351 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ const { Deepgram } = require("@deepgram/sdk");
const deepgram = new Deepgram(DEEPGRAM_API_KEY);
```

## Examples
# Examples

### Transcribe an Existing File
## Transcription

### Pre-recorded

#### Remote Files

Expand Down Expand Up @@ -70,6 +72,353 @@ const response = await deepgram.transcription.preRecorded(streamSource, {

See an example real time project at https://github.com/deepgram-devs/node-live-example, or visit this [Getting Started guide](https://developers.deepgram.com/documentation/getting-started/streaming/)

### Usage

#### listRequests
Retrieves all requests associated with the provided project_id based on the provided options.
```js
deepgram.usage
.listRequests("84b227ad-dfac-4096-82f6-f7397006050b", {
start: "2022-07-01",
end: "2022-07-28",
})
.then((response) => {
console.log("Usage: ", response);
})
.catch((err) => {
console.log("ERROR: ", err);
});
```
#### getRequest
Retrieves a specific request associated with the provided project_id.
```js
deepgram.usage
.getRequest(
// projectId
"84b227ad-dfac-4096-82f6-f7397006050b",
// requestId
"f12cc224-282b-4de4-90f1-651d5fdf04f1"
)
.then((response) => {
fs.writeFileSync(
`usage.json`,
JSON.stringify(response),
() => `Wrote json`
);
})
.catch((err) => {
console.log("ERROR: ", err);
});
```

#### getUsage
Retrieves usage associated with the provided project_id based on the provided options.
```js
deepgram.usage
.getUsage("84b227ad-dfac-4096-82f6-f7397006050b", {
punctuate: true,
diarize: true
})
.then((response) => {
console.log("Usage: ", response);
})
.catch((err) => {
console.log("ERROR: ", err);
});
```

### getFields
Retrieves features used by the provided project_id based on the provided options.
```js
deepgram.usage
.getFields("84b227ad-dfac-4096-82f6-f7397006050b", {
start: "2022-07-01",
end: "2022-07-28",
})
.then((response) => {
console.log("Usage: ", response);
})
.catch((err) => {
console.log("ERROR: ", err);
});
```

### Scopes
#### get
Retrieves scopes of the specified member in the specified project.
```js
deepgram.scopes
.get(
"84b227ad-dfac-4096-82f6-f7397006050b",
"f12cc224-282b-4de4-90f1-651d5fdf04f1"
)
.then((response) => {
fs.writeFileSync(
`scope.json`,
JSON.stringify(response),
() => `Wrote json`
);
})
.catch((err) => {
console.log("ERROR: ", err);
});
```

#### update
Updates the scope for the specified member in the specified project.
```js
deepgram.scopes
.update(
"84b227ad-dfac-4096-82f6-f7397006050b",
"f12cc224-282b-4de4-90f1-651d5fdf04f1",
"member:read"
)
.then((response) => {
console.log({response})
})
.catch((err) => {
console.log("ERROR: ", err);
});
```

### Projects
#### list
Returns all projects accessible by the API key.
```js
deepgram.projects
.list()
.then((response) => {
console.log("list", response);
})
.catch((err) => {
console.log("err", err);
});
```

#### get
Retrieves a specific project based on the provided project_id.
```js
deepgram.projects
.get("84b227ad-dfac-4096-82f6-f7397006050b")
.then((response) => {
console.log("list", response);
})
.catch((err) => {
console.log("err", err);
});
```

#### update
Update a project.
```js
deepgram.projects
.update(
{ project_id: "84b227ad-dfac-4096-82f6-f7397006050b" },
{
name: "A new name",
}
)
.then((response) => {
console.log("list", response);
})
.catch((err) => {
console.log("err", err);
});
```

#### delete
Delete a project.
```js
deepgram.projects
.delete("84b227ad-dfac-4096-82f6-f7397006050b")
.then((response) => {
console.log("delete", response);
})
.catch((err) => {
console.log("err", err);
});
```

### Members

#### listMembers
Retrieves account objects for all of the accounts in the specified project.
```js
deepgram.members
.listMembers("84b227ad-dfac-4096-82f6-f7397006050b")
.then((response) => {
console.log("Members: ", response);
})
.catch((err) => {
console.log("Members ERROR: ", err);
});
```

#### deleteMembers
Removes member account for specified member_id.
```js
deepgram.members
.removeMember(
"84b227ad-dfac-4096-82f6-f7397006050b",
"f12cc224-282b-4de4-90f1-651d5fdf04f1"
)
.then((response) => {
console.log("Member DELETED: ", response);
})
.catch((err) => {
console.log("Member DELETED ERROR: ", err);
});
```

### Keys
#### list
Retrieves all keys associated with the provided project_id.
```js
deepgram.keys
.list("84b227ad-dfac-4096-82f6-f7397006050b")
.then((res) => {
console.log({ res });
})
.catch((err) => {
console.log("ERROR: ", err);
});
```

#### get
Retrieves a specific key associated with the provided project_id.
```js
deepgram.keys
.get(
"84b227ad-dfac-4096-82f6-f7397006050b",
"f12cc224-282b-4de4-90f1-651d5fdf04f1"
)
.then((res) => {
console.log({ res });
})
.catch((err) => {
console.log("ERROR: ", err);
});
```

#### create
Creates an API key with the provided scopes.
```js
deepgram.keys
.create(
"84b227ad-dfac-4096-82f6-f7397006050b",
"Temporary key",
["usage"],
{
timeToLive: 5000,
}
)
.then((res) => {
console.log({ res });
})
.catch((err) => {
console.log("ERROR: ", err);
});
```

#### delete
Deletes a specific key associated with the provided project_id.
```js
deepgram.keys
.delete(
"84b227ad-dfac-4096-82f6-f7397006050b",
"f12cc224-282b-4de4-90f1-651d5fdf04f1"
)
.then((response) => {
console.log("KEY DELTED: ", response);
})
.catch((err) => {
console.log("KEY DELETED ERROR: ", err);
});
```

### Invitations
#### list
Retrieves all invitations associated with the provided project_id.
```js
deepgram.invitations
.list("84b227ad-dfac-4096-82f6-f7397006050b")
.then((res) => {
console.log({ res });
})
.catch((err) => {
console.log("ERROR: ", err);
});
```

#### send
Sends an invitation to the provided email address.
```js
deepgram.invitation
.send("84b227ad-dfac-4096-82f6-f7397006050b", {
email: "[email protected]",
scope: "member",
})
.then((response) => {
console.log("Invitation sent: ", response);
})
.catch((err) => {
console.log("Invitation ERROR: ", err);
});
```

#### leave
Removes the authenticated user from the project.
```js
deepgram.invitation
.leave("84b227ad-dfac-4096-82f6-f7397006050b")
.then((response) => {
console.log({response});
})
.catch((err) => {
console.log("Invitation leave ERROR: ", err);
});
```

#### delete
Removes the specified invitation from the project.
```js
deepgram.invitation
.delete("84b227ad-dfac-4096-82f6-f7397006050b", "[email protected]")
.then((response) => {
console.log({response});
})
.catch((err) => {
console.log("Invitation delete ERROR: ", err);
});
```

### Billing
#### listBalances
Retrieves the list of balance info for the specified project.
```js
deepgram.billing
.listBalances("84b227ad-dfac-4096-82f6-f7397006050b")
.then((response) => {
console.log({response});
})
.catch((err) => {
console.log("Billing listBalances ERROR: ", err);
});
```

#### getBalance
Retrieves the balance info for the specified project and balance_id.
```js
deepgram.billing
.getBalance("84b227ad-dfac-4096-82f6-f7397006050b", "21b98377-657e-471a-b75e-299fb99ec2c3")
.then((response) => {
console.log({response});
})
.catch((err) => {
console.log("Billing getBalance ERROR: ", err);
});
```

## Samples

To run the sample code, first run the following in your terminal:
Expand Down
2 changes: 1 addition & 1 deletion src/members.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class Members {
}

/**
* Retrieves account objects for all of the accounts in the specified project.
* Removes member account for specified member_id.
* @param {string} projectId Unique identifier of the project
* @param {string} memberId Unique identifier of the member
* @param {string} endpoint Custom API endpoint
Expand Down
5 changes: 3 additions & 2 deletions src/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
ProjectResponse,
ProjectPatchRequest,
RequestFunction,
ErrorResponse
ErrorResponse,
Message
} from "./types";

export class Projects {
Expand Down Expand Up @@ -83,7 +84,7 @@ export class Projects {
* @param {string} projectId Unique identifier of the project
* @param {string} endpoint Custom API endpoint
*
* @returns {Promise<void | ErrorResponse>}
* @returns {Promise<Message | ErrorResponse>}
*/
async delete(
projectId: string,
Expand Down

0 comments on commit e425e95

Please sign in to comment.