Skip to content

paksu/yleapijs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple promise based API client for YLE API http://developer.yle.fi/

by @joonapaak

Install

$ npm install yleapi

Initialize

var YleAPI = require('yleapi');

var api = new YleAPI({
    APP_ID: 'appid',
    APP_KEY: 'appkey',
    MEDIA_DECRYPT_KEY: 'secret' // not required to use HTTP API but needed if you want to decrypt media urls
});

API

// get and filter stuff from a single endpoint
// returns a promise
api.get('resource/path', {params})

// decrypt media urls with your secret key
// returns the encrypted url
api.decryptMediaUrl(encryptedUrl)

Examples

// get most popular programs
api.get('programs/items', {
    order: 'playcount.24h:desc',
    offset: 150
}).then(function(response) {
    // do stuff with the result
    console.log(response.meta);
    console.log(response.data);
})
.catch(function(error) {
    console.log("got error", error.statusCode, error.responseBody);
})


// get a program and decrypt media url
api.get('media/playouts', {
  program_id: '1-820561',
  media_id: '6-8e9d45c1221544f3be76394fa1a6a102',
  protocol: 'HLS'
}).then(function(response) {
  var mediaUrl = api.decryptMediaUrl(response.data[0].url);
});

Logging

YleAPI uses util.debuglog. To requests run your script with NODE_DEBUG:

$ env NODE_DEBUG=yleapi node myscript.js

Develop

Run tests: $ npm test

Tests currently need file called test_config.js at the root of the project. This file should export the API keys like this:

module.exports = {
    APP_ID: 'a',
    APP_KEY: 'b',
    MEDIA_DECRYPT_KEY: 'c'
};

About

Promise based Yle API client for nodejs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published