npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

trakter

v0.1.0

Published

simple node module for trakt.tv V2 api

Downloads

14

Readme

trakter

A simple node module to access Trakt API v2.

#Purpose Trakt.tv keeps track of movies and Television that you want to watch, have watched, have collected, and much else. This module makes it easy. There has been a great deal of good work done on the V1 trakt api, and some good modules, but I wanted to build one for the new version 2 of the API with no dependencies other than standard node, and keep it as simple as possible.

#Installation

Installing Trakter

You can install the stable branch (recommended) into your project using the node package manager:

npm install trakter

Or globally using

npm install -g trakter

If you want the dev branch, you probably already have a good idea of how to proceed.

#Configuration

##1. Register YOUR Application with trakt.tv

  1. Register as a user at Trakt.TV if you haven't already. This is free, unless you choose to go premium. You do not need premium to use the API.
  2. Register your application. At the time of writing, this is the "Create An App" link at the bottom of the page.
  3. Go to your trakt.tv account, and look up your application details. You will be needing:
    • Client ID: (a long string of text)
    • Client Secret: (another long string of text)
    • PIN URL: (a URL)

##2. Configure Trakter with your application details Create an initial configuration with your application registration details from the step above.

// application registration details from trakt.tv 
config = {  pinUrl: <a url> 
              client_id: <client id>,
              client_secret: <client secret>
              };

##3. Authorise your application for the Trakt.tv user Call the setConfig method of Trakter with the config your created, and a function which returns the PIN from a user (see below for an example):

trakter.setConfig(config,getPIN, function (err) {
  if (err) {
    console.log(err);
    console.log('Cannot configure trakt.tv interface');
    process.exit(9);
  }

##4. Save the config (which now includes the user authorisation) for use later Once trakter is initialised and an authorisation is granted, you should use trakter.getConfig() to return the complete config object, which you can save and reuse the next time your application starts.

##5. Make API calls from your application API calls are made with Trakter.request (suppliedOptions,data,next).

  • suppliedOptions are passed to the API, and as a minimum, you need path and method. If you pass other options, they will override the defaults Trakter chooses, but you should not normally need to.
  • data is for those API calls which require it, otherwise just pass null.
  • next is the callback function.
  trakter.request({path:'/shows/game-of-thrones', method:'GET'},null,showResult);

#Quickstart Once trakter is initialised and an authorisation is granted, you should use trakter.getConfig() to return the complete config object, which you can save and reuse the next time you application starts. Here is a fully working example to get you started:

var CONSTANT = {
              configFilename:'./config.json',
              pinUrl: '<your-value-here>',
              client_id: '<your-value-here>',
              client_secret: '<your-value-here>'
}
var nconf = require('nconf');
var trakter = require ('./trakter');
var readlineSync = require('readline-sync');

nconf.argv()
      .env()
      .file({ file: CONSTANT.configFilename });
nconf.load();

var config = nconf.get('trakter')

if (!config) {
  console.log ('Cannot read config - using defaults');
  config = {  pinUrl: CONSTANT.pinUrl,
              client_id: CONSTANT.client_id,
              client_secret: CONSTANT.client_secret
              };
  nconf.set('trakter',config);
}

trakter.setConfig(nconf.get('trakter'),getPIN, function (err) {
  if (err) {
    console.log(err);
    console.log('Cannot configure trakt.tv interface');
    process.exit(9);
  }
  nconf.set('trakter',trakter.getConfig()); // save the configuration
  nconf.save();

  trakter.request({path:'/shows/game-of-thrones', method:'GET'},null,showResult);
  });

function showResult(err,data) {
  console.log(data);
}


function getPIN(PINUrl)
{
  console.log('Go to ' + PINUrl + ' and get PIN');
  return readlineSync.question('Enter Trakt.TV PIN :');
}

#More Detail

Managing configurations

I generally use nconf. See the example below.

Getting the user's PIN

readlineSync is a nice simple way to get the PIN from the command line. See the example below.

Tests

There is a basic set of unit tests included. You will need to add your application registration details to test.js to run them. #How to contribute

To Do

  • implement the "refresh" token
  • add functionality to use the oauth workflow to avoid the PIN where possible
  • browser version using xmlhttlrequest and a require.js wrapper