0.169.0 • Published 6 years ago

mercury-sdk-js v0.169.0

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

Mercury Javascript SDK

This is an SDK that wraps calls to the Discovery APIs. The SDK exposes an object with classes that represent API groups. Each class will have a number of name-spaced methods that return promises with data from APIs in that group. Each class will also expose some common methods for hateoas support, using the auth tools against additional endpoints, and affiliate login/logut functionality. See the documentation below for a complete list of methods.

SDK Development

Requirements:

  • node and npm

Getting started:

  • clone the repo
  • run $ npm install
  • see package.json for a list of npm scripts

Adding SDK to your project

Requirements:

  • node and npm

Getting started:

  • install with npm - npm install @discodigital/mercury-sdk-js --save

Developing Locally:

If you'd like to use this package locally to make changes and use in your project, you can create a link through npm from the root of your project:

  • npm link ../path/to/mercury-sdk-js @discodigital/mercury-sdk-js@0.<version>.0

Note: If you are linking the mercury-sdk-js package into a react project and that react project is using react-hot loader, then you will need to explicitly tell it to ignore the mercury-sdk-js package when it does its transformation. You can do this in the webpack.config.js where you have defined the loader for react-hot. You'll need to add mercury-sdk-js to the exclude:

{
    test: /\.jsx?$/,
    loaders: ['react-hot', 'babel?cacheDirectory'], // support HMR
    exclude: [/node_modules/, /mercury-sdk-js/],
},

Base Class functionality

All of the API group classes are built on top of a base class that provides the shared functionality. The primary differences between API group classes are defined by their config sections, thus most of the functionality resides in the base class.

Constructor

new SDKBase(options, child)

Parameters:

Properties:

Methods

destroy()

Used by client apps to remove any listeners or maps that may prevent the instance from being garbage collected
Example

classInstance.destroy();

fetchWithAuth(url, options) → {Promise}

This exposes the internal fetchWithAuth method for client apps using the SDKBase it allows for add hoc calls to apis with auth support and could be useful for APIs that aren't included in the SDK yet
Parameters:

Returns:
a Promise resolving with the json data from the api called, parsed to add HATEOS link functions
Example

classInstance.fetchWithAuth('https://my-dev-apis/v1/someendpoint', { method: 'GET' })
    .then(resp => {
        //your data is in resp.headers and resp.body
    });

getAffiliates() → {Promise}

Used by client apps to get a list of affiliates to choose from in affilate auth
Returns:
a Promise resolving with an array of affiliate objects
Example

classInstance.getAffiliates()
    .then(resp => {
        // affiliates list is in resp.body
    });

hateoas.fetch(linksArray, targetRel, parameters) → {Promise}

The hateoas.fetch function allows the client app to pass in a group of hateoas links and make a call to one of them by it's rel name
Parameters:

Returns:
a call to the fetchWithAuth function provided
Example

const linksArray = [
    {
        rel: 'next',
        href: 'https://myapi.com/v1/something?offset=10&platform={platform}',
    },
];

classInstance.hateoas.fetchLink(linksArray, 'next', { platform: 'desktop' })
    .then(resp => {
        //your hateoas link data is in resp.body, there maybe be hateoas links in resp.headers
    });

hateoas.namedResource(configurationsParams, resourceName, resourceParams) → {Promise}

The hateoas.namedResource function will get the configuration for the app defined in the first argument and call one of it's links
Parameters:

Returns:
a call to hateoas.fetch()
Example

classInstance.hateoas.namedResource({ id: 'dgo', key: 'test' }, 'featured', { platform: 'desktop' })
    .then(resp => {
        // your named resource data is in resp.body, there maybe be hateoas links in resp.headers
    });

logOff()

Used by client apps to log out of affiliate auth
Example

classInstance.logOff()
    .then(() => {
        // logoff is now complete
    });

setAffiliate(affiliateObject)

Used by client apps to initialize affiliate auth once an affiliate is chosen by the user
Parameters:

Example

classInstance.setAffiliate({ authClientId:"thr030", links:[], etc });

setAuth(authObj, affiliateLink)

Used by the classes or client applications
Parameters:

Example

classInstance.setAuth({ access_token: '154345234523452345453425.452345243523.2345234' });

API Group: Discovery REST APIs

Constructor

new SDK.Drapi(options)

Parameters:

Example

const classInstance = new SDK.Drapi({
  apiBase: ' https://api.discovery.com.qa-bsidelinger.i.dsc.tv',
  clientId: '12345234tsdfg43256',
});

Methods

Affiliates.find(parameters) → {Promise}

Find all Affiliates

Parameters:

Example

classInstance.Affiliates.find()
    .then(resp => {
        // your data is in resp.headers and resp.body
    })
    .catch(err => {
        // error handling
    });

Affiliates.find(parameters) → {Promise}

Find one Affiliate

Parameters:

Example

classInstance.Affiliates.find({id: 'string'})
    .then(resp => {
        // your data is in resp.headers and resp.body
    })
    .catch(err => {
        // error handling
    });

Bios.find(parameters) → {Promise}

Find all Bios

Parameters:

Example

classInstance.Bios.find()
    .then(resp => {
        // your data is in resp.headers and resp.body
    })
    .catch(err => {
        // error handling
    });

Bios.find(parameters) → {Promise}

Find one Bio

Parameters:

Example

classInstance.Bios.find({id: 'string'})
    .then(resp => {
        // your data is in resp.headers and resp.body
    })
    .catch(err => {
        // error handling
    });

Collections.find(parameters) → {Promise}

Find all Collections

Parameters:

Example

classInstance.Collections.find({platform: 'string', type: 'string'})
    .then(resp => {
        // your data is in resp.headers and resp.body
    })
    .catch(err => {
        // error handling
    });

Collections.find(parameters) → {Promise}

Find one Collection

Parameters:

Example

classInstance.Collections.find({id: 'string'})
    .then(resp => {
        // your data is in resp.headers and resp.body
    })
    .catch(err => {
        // error handling
    });

Configurations.find(parameters) → {Promise}

Find all Configurations

Parameters:

Example

classInstance.Configurations.find({ id: 'dgo', key: 'test' })
    .then(resp => {
        // use your data
    })
    .catch(err => {
        // error handling
    });

Curatedlists.find(parameters) → {Promise}

Find all Curatedlists

Parameters:

Example

classInstance.Curatedlists.find()
    .then(resp => {
        // your data is in resp.headers and resp.body
    })
    .catch(err => {
        // error handling
    });

Curatedlists.find(parameters) → {Promise}

Find one Curatedlist

Parameters:

Example

classInstance.Curatedlists.find({id: 'string'})
    .then(resp => {
        // your data is in resp.headers and resp.body
    })
    .catch(err => {
        // error handling
    });

Featured.find(parameters) → {Promise}

Find all Featured

Parameters:

Example

classInstance.Featured.find({platform: 'string', type: 'string'})
    .then(resp => {
        // your data is in resp.headers and resp.body
    })
    .catch(err => {
        // error handling
    });

FeaturedPage.find(parameters) → {Promise}

Find all FeaturedPage

Parameters:

Example

classInstance.FeaturedPage.find({platform: 'string', type: 'string'})
    .then(resp => {
        // your data is in resp.headers and resp.body
    })
    .catch(err => {
        // error handling
    });

Genres.find(parameters) → {Promise}

Find all Genres

Parameters:

Example

classInstance.Genres.find()
    .then(resp => {
        // your data is in resp.headers and resp.body
    })
    .catch(err => {
        // error handling
    });

Genres.find(parameters) → {Promise}

Find one Genre

Parameters:

Example

classInstance.Genres.find({id: 'string'})
    .then(resp => {
        // your data is in resp.headers and resp.body
    })
    .catch(err => {
        // error handling
    });

Layouts.find(parameters) → {Promise}

Find all Layouts

Parameters:

Example

classInstance.Layouts.find({platform: 'string'})
    .then(resp => {
        // your data is in resp.headers and resp.body
    })
    .catch(err => {
        // error handling
    });

Layouts.find(parameters) → {Promise}

Find one Layout

Parameters:

Example

classInstance.Layouts.find({id: 'string', platform: 'string'})
    .then(resp => {
        // your data is in resp.headers and resp.body
    })
    .catch(err => {
        // error handling
    });

Livestreams.find(parameters) → {Promise}

Find one Livestream

Parameters:

Example

classInstance.Livestreams.find({id: 'string'})
    .then(resp => {
        // your data is in resp.headers and resp.body
    })
    .catch(err => {
        // error handling
    });

Livestreams.find(parameters) → {Promise}

Find all Livestreams

Parameters:

Example

classInstance.Livestreams.find()
    .then(resp => {
        // your data is in resp.headers and resp.body
    })
    .catch(err => {
        // error handling
    });

Menus.find(parameters) → {Promise}

Find all Menus

Parameters:

Example

classInstance.Menus.find()
    .then(resp => {
        // your data is in resp.headers and resp.body
    })
    .catch(err => {
        // error handling
    });

Menus.find(parameters) → {Promise}

Find one Menu

Parameters:

Example

classInstance.Menus.find({id: 'string'})
    .then(resp => {
        // your data is in resp.headers and resp.body
    })
    .catch(err => {
        // error handling
    });

Moreepisodes.find(parameters) → {Promise}

Find all Moreepisodes

Parameters:

0.169.0

6 years ago

0.168.0

6 years ago

0.167.0

6 years ago

0.166.0

6 years ago

0.165.0

6 years ago

0.164.0

6 years ago

0.163.0

6 years ago

0.162.0

6 years ago

0.161.0

6 years ago

0.160.0

6 years ago

0.159.0

6 years ago

0.158.0

6 years ago

0.157.0

6 years ago

0.156.0

6 years ago

0.155.0

6 years ago

0.154.0

7 years ago

0.153.0

7 years ago

0.152.0

7 years ago

0.151.0

7 years ago

0.150.0

7 years ago

0.149.0

7 years ago

0.148.0

7 years ago

0.147.0

7 years ago

0.146.0

7 years ago

0.145.0

7 years ago

0.144.0

7 years ago

0.143.0

7 years ago

0.142.0

7 years ago

0.141.0

7 years ago

0.140.0

7 years ago

0.139.0

7 years ago

0.138.0

7 years ago

0.137.0

7 years ago

0.136.0

7 years ago

0.135.0

7 years ago

0.134.0

7 years ago

0.133.0

7 years ago

0.132.0

7 years ago

0.131.0

7 years ago

0.130.0

7 years ago

0.129.0

7 years ago

0.128.0

7 years ago

0.127.0

7 years ago

0.126.0

7 years ago

0.125.0

7 years ago

0.124.0

7 years ago

0.123.0

7 years ago

0.122.0

7 years ago

0.121.0

7 years ago

0.120.0

7 years ago