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

sndapi-js

v1.0.1

Published

SND news API ajax call wrapper for the browser

Downloads

2

Readme

snd-api-js

sndapi.js is Schibsted Norge Digital news API utility library to access the API from JavaScript. It only manages the tokens thrown back and forth for authorization of the requests. If you are looking for a full-blown NewsClient SDK for JavaScript, you may want to try (work in progress) the snd-api-newsclient-js project.

The name in probably misleading because of this, we know. Unforeseen project decisions.

It is lightweight (only 3.8 KiB when minified, 2.2 KiB to download!) and very simple to use (construct, init, ajax!). It has no external dependencies and requires CORS-aware browser — consult http://caniuse.com/cors if in doubt.

Installation

You can either:

  • include the JavaScript file before you use it with a script tag or
  • install it as a bower package

bower

If you use bower, you can install this package via package name from bower registry:

bower install snd-api-js

It should include the minified output file and some documentation in your bower_components directory:

    ➜  your_project $  tree bower_components -L 2
    bower_components
    `-- snd-api-js
        |-- README.md
        |-- bower.json
        |-- docs
        |-- sndapi.js
        `-- sndapi.min.js

Usage

Then, in your code, you create an instance of SNDAPI object (providing at least your API client id key, for more options refer to the JSDoc in docs directory), initialize it and there make AJAX calls in a familiar way:

	var api = new SNDAPI({
        key: "your123secret789key" // also known as client ID in some docs.
    });
    api.init(); // This makes a HTTP request! You can also attach .success and .fail here
	api.ajax({ url: "publication/common/sections/1/auto" })
	    .success(function(data, statusDetails) {
	        console.log("HTTP response code: " + statusDetails.statusCode);
	        console.log("HTTP status text:   " + statusDetails.statusText);
	        ok(data === statusDetails.response);
	        ok(data, "data received");
	    })
	    .fail(function(statusDetails) {
	        console.error("request failed");
	        console.error("Response code: " + statusDetails.statusCode);
	    });

More documentation

JSDoc is generated with gulp-jsdoc and can be viewed in the docs/SNDAPI.html. Because of most git repo viewers' security limitations, it's best viewed offline, from your hard disk.

Contributing and building

npm and gulp are required to build this project. Then just run

gulp

and the build/sndapi.min.js file should be updated (and the tests run, and the filesystem watched for changes). If you don't want waching for changes and want to build+test only once, use gulp once.

We use semantic versioning which is made easy with the following commands:

gulp patch # after you patched a bug in a backwards-compatible manner
gulp feature # after you added a new feature that doesn't break backward-compatibility, bumps minor version
gulp release # after you created a new backwards-incompatible release, bumps major version number

These will bump the version both in package.json and bower.json, tag the repository and push the tags. The commands are more documented in the gulpfile.

Testing

That's under development. You can simply run gulp test or npm test now, but it doesn't finish the process automatically yet. Tests are written for QUnit and placed in sndapi-test.js file.

Unfortunately right now the gulp-qunit plugin didn't seem to accept a HTTP protocol URL as the argument, only a local file, and when it uses a local file, its PhantomJS doesn't resolve other local files referenced by just src="qunit.js" and such (though might be fixed by gulp-qunit pull request #8). Therefore we start an Express server that hosts the test files and provides simple mock responses that the real API server should return. The tests will be changed to use this server instead of the real one (that does not work, he he).

To serve everything that's required and run the tests, run:

	gulp test

It will use port 8081 for serving content to PhantomJS with QUnit.