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

comicvine-client

v0.1.2

Published

ComicVine Client for remote API, based on Backbone

Downloads

13

Readme

comicvine-client

ComicVine Client for remote API, based on Backbone

Features

  • Exports ComicVine API resources as Backbone collections, ready to be consumed.
  • Uses Redis for caching API responses.
  • Modeled resources:
    • Characters
    • Concepts
    • Issues
    • Locations
    • Movies
    • Objects
    • Origins
    • Persons
    • Powers
    • Publishers
    • StoryArcs
    • Teams
    • Volumes

Dependencies

  • Backbone, used to map API Resources into objects
  • request, used to make http requests to the API
  • caching, used to provide a redis caching layer

Tests

The module provides a set of tests (althougt some methods doesn't have tests yet). The tests has been created using mocha. To run the tests:

  1. Install mocha globally
$ npm install -g mocha
$ cd comicvine-client
$ mocha
  1. If you have mocha installed as a dependency
$ cd comicvine-client
$ npm install mocha
$ node_modules/mocha/bin/mocha

Usage

Initialization

var ComicVineClient = require('comicvine');

var client = new ComicVineClient({
    //Example API key, insert your API key here. More info http://api.comicvine.com/
    apikey: "40ffdec6b2f84ffa415b5f24d289175ae907a6a1",

    //Base URL for all the API requets. Don't change it unless you are using your own proxy or something like that.
    apiUrl: "http://api.comicvine.com",

    //Use redis cache for http requests
    cache: 'redis',

    //Redis host
    host: "192.168.56.2",

    //Redis port
    port: 6379,
});

or

var ComicVineClient = require('comicvine');

var client = new ComicVineClient({
    //Example API key, insert your API key here. More info http://api.comicvine.com/
    apikey: "40ffdec6b2f84ffa415b5f24d289175ae907a6a1",

    //Don't use cache
    //It is *highly recommended* to not disable the cache. ComicVine API is not very fast and very verbose, so
    //not using cache will definetly kill your performance.
    cache: false
});

Get a paginated list of characters

client.collections.pageSize = 20; //100 by default
client.collections.Characters.fetch( {
    //Regular Backbone.Collection.fetch options here...
});

//...later...

client.collections.Characters.fetchNextPage({
    //Regular Backbone.Collection.fetch options here...
})

Get all the list of characters

//Don't even try this without a populated cache, will take ages
client.collections.Characters.fetchAll({
    success: function(collection) {
        //Run this callback after all the collection has been retrieved
    },
    each: function(collection) {
        //Run this callback after each page retrieval (will be used as success callback for each fetchNextPage() call)
    },
    error: function(collection) {
        //Run this callback if there is any error (will be used as error callback for each fetchNextPage() call)
    }
});

Use API Search to find the real name of the best superhero ever

var searchCollection = new client.Search("Batman","character");

//Now searchCollection is a regular paginated collection. You can set pageSize, use .fetch(), .fetchNextPage()...
searchCollection.fetchAll({
    success: function(results) {
        var batman = results.where({"name": "Batman"})[0];
        console.log( batman.get("real_name") );
    }
})

Note that ComicVine Search is a bit too user-friendly: it will return any character with "Batman" or some variation in the name (like, "Bat-Man" or "Batmankoff"). Probably you will need to filter the resutling list on your own, using .filter() or .where().

TODO

  • Allow limit the number of fields returned in each request
  • Add tests for fetchAll()
  • Add a method to detect if a Model has been loaded completly
  • Better error detection