Skip to content

Commit

Permalink
Return data objects (#14)
Browse files Browse the repository at this point in the history
* initial pass at switching to an axios instance for http

* update tests

* test test test

* remove Error since not using it yet

* remove docs from non-gh-pages and such

* use object.assign instead of manually merging

* add readme and package

* more docs

* 2.0.0-0
  • Loading branch information
mmcc committed Oct 12, 2018
1 parent 5529461 commit 3b9d29a
Show file tree
Hide file tree
Showing 116 changed files with 664 additions and 147,152 deletions.
1 change: 1 addition & 0 deletions .nvmrc
@@ -0,0 +1 @@
9
48 changes: 38 additions & 10 deletions README.md
@@ -1,6 +1,6 @@
# Mux Node SDK

![build status](https://api.travis-ci.org/muxinc/mux-node-sdk.svg?branch=master)
![build status](https://api.travis-ci.org/muxinc/mux-node-sdk.svg?branch=master) ![npm version](https://badge.fury.io/js/%40mux%2Fmux-node.svg)

Official Mux API wrapper for Node projects.

Expand All @@ -22,7 +22,9 @@ yarn add @mux/mux-node
```

## Releases
The latest **stable** release is `1.1.1`
The latest **stable** release is `1.1.1`

Please keep in mind that master contains edge, so at any point it may be out of sync with what's in the latest stable release. Please consult the [releases](https://github.com/muxinc/mux-node-sdk/releases) page for both stable releases and release candidates.

## Usage
To start, you will need a Mux access token and secret for your Mux environment. For more information on where to get
Expand All @@ -39,27 +41,45 @@ const { Video, Data } = muxClient;
As an example, you can create a Mux asset and playback ID by using the below functions on your Video instance.
```javascript
// Create an asset
let assetId;
Video.assets.create({ input: 'https://storage.googleapis.com/muxdemofiles/mux-video-intro.mp4' })
.then((res) => {
const { data } = res.data;
assetId = data.id;
});
const asset = await Video.assets.create({ input: 'https://storage.googleapis.com/muxdemofiles/mux-video-intro.mp4' });
```

```javascript
// Create a playback ID for an asset
Video.playbackIds.create(assetId, { policy: 'public' });
const playbackId = await Video.assets.createPlaybackId(assetId, { policy: 'public' });
```

You can access the Mux Data API in the same way by using your Data instance. For example, you can list all of the
values across every breakdown for the `aggregate_startup_time` metric by using the below function.

```javascript
Data.metrics.breakdown('aggregate_startup_time', { group_by: 'browser' });
const breakdown = await Data.metrics.breakdown('aggregate_startup_time', { group_by: 'browser' });
```

Every function will return a chainable [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).

```javascript
Video.assets.create({
input: 'https://storage.googleapis.com/muxdemofiles/mux-video-intro.mp4'
}).then(asset => {
/* Do things with the asset */
});
```

## `request` and `response` events

The SDK returns the `data` key for every object, because in the Mux API that's always the thing you actually want to see. Sometimes, however, it's useful to see more details about the request being made or the full response object. You can listen for `request` and `response` events to get these raw objects.

```javascript
muxClient.on('request', req => {
// Request will contain everything being sent such as `headers, method, base url, etc
});

muxClient.on('response', res => {
// Response will include everything returned from the API, such as status codes/text, headers, etc
});
```

See the [Mux-Node docs](https://muxinc.github.io/mux-node-sdk/identifiers.html) for a list of all available functions.

## Development
Expand All @@ -77,4 +97,12 @@ To generate the ESDocs, run:
open ./docs/index.html
```

## Contributing

Find a bug or want to add a useful feature? That'd be amazing! If you'd like to submit a [pull request](https://help.github.com/articles/about-pull-requests/) to the project with changes, please do something along these lines:

1. Fork the project wherever you'd like
2. Create a meaningful branch name that relates to your contribution. Consider including an issue number if available. `git co -b add-node-lts-support`
3. Make any changes you'd like in your forked branch.
4. Add any relevant tests for your changes
5. Open the pull request! :tada:
1 change: 0 additions & 1 deletion docs/_config.yml

This file was deleted.

0 comments on commit 3b9d29a

Please sign in to comment.