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

aweber-api

v1.0.0

Published

Minimal higher-level wrapper around AWeber's API for Node.js

Downloads

120

Readme

aweber-api

Minimal higher-level wrapper around AWeber's API for Node.js.

npm Version Build Status Test Coverage Dependency Status

Features

  • Promise-based
  • Minimal
  • Resilient to upstream changes to the AWeber API

Installation

Install using npm:

$ npm install aweber-api --save

Getting Started

  1. In order to use the AWeber API, you will first need to register for a free developer account.
  2. Once you have an account, log in and create an app, making note of your consumer key and secret.

With a consumer key and secret, you are now ready to authenticate your app and verify one or more accounts. We'll start by verifying a single account. Open a Node.js console session:

$ node
> Aweber = require('aweber-api')
[Function: Aweber]
> aw = Aweber('your-consumer-key', 'your-consumer-secret')
> aw.getAuthorizationUrl().then(console.log).catch(console.log)
Promise { <pending> }
> https://auth.aweber.com/1.0/oauth/authorize?oauth_token=XXXXXXXXXXXXXXXXXXXXXXXX

Visit the URL this generates. You will be prompted to enter the credentials for the AWeber account you'd like to access via the API (NOTE: AWeber account, NOT your labs developer account).

After submitting the form, copy the verifier code that was generated and return to your node console session:

> aw.getAccessToken('your-verifier-token').then(console.log).catch(console.log)
Promise { <pending> }
{ token: "XXXXXXXXXXXXXXXXXXXXXXXX", tokenSecret: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" }

At this point, your account is fully authenticated. Make note of your token and token secret. These should be stored securely for future use.

Usage

aweber-api exports a factory function for creating new aweber instances. Consumer key and secret are required.

const Aweber = require('aweber-api');

// ...

const aw = Aweber(config.consumerKey, config.consumerSecret, {
  token: session.token,
  tokenSecret: session.tokenSecret
});

Available Options

Overview of defaults:

Aweber(consumerKey, consumerSecret, {
  token: null,
  tokenSecret: null,
  userAgent: 'aweber-api (https://github.com/jimf/aweber-api)',
  Promise: Promise
});

Methods

OAuth

Aweber#getAuthorizationUrl([callbackUrl])

Resets the instance's internal token value to an empty string, requests a new temporary token, stores the new token internally, and returns the URL where authorization can be made. An optional callback url may be specified. Returns a Promise.

Aweber#getAccessToken(verifier)

Request a new token and token secret. This method requires the verifier code obtained from the user authorization process. Returns a Promise.

HTTP Verbs

See the official AWeber API docs for specifics on using individual endpoints.

Aweber#del(url, options)

Makes a single DELETE request to the AWeber API for the given resource, returning a Promise.

Params

  • url {String}: URL of the resource to be deleted (host and query params optional)
  • options {Object}: Options object
  • options.params {Object}: Dictionary of query parameters to specify

Example

// All of the following are equivalent:
aw.del('https://api.aweber.com/1.0/example/1?ws.op="delete"').then(/* ... */);
aw.del('/1.0/example/1?ws.op="delete"').then(/* ... */);
aw.del('/1.0/example/1', { params: { 'ws.op': 'delete' } }).then(/* ... */);

Aweber#get(url, options)

Makes a single GET request to the AWeber API for the given resource, returning a Promise.

Params

  • url {String}: URL of the resource to be retrieved (host and query params optional)
  • options {Object}: Options object
  • options.params {Object}: Dictionary of query parameters to specify

Example

// All of the following are equivalent:
aw.get('https://api.aweber.com/1.0/example?status="new"').then(/* ... */);
aw.get('/1.0/example?status="new"').then(/* ... */);
aw.get('/1.0/example', { params: { status: 'new' } }).then(/* ... */);

Aweber#patch(url, options)

Makes a single PATCH request to the AWeber API for the given resource, returning a Promise.

Params

  • url {String}: URL of the resource to be updated (host and query params optional)
  • options {Object}: Options object
  • options.data {Object}: Dictionary of fields with their updated values
  • options.params {Object}: Dictionary of query parameters to specify

Example

const opts = { data: { subject: 'new value' } };

// All of the following are equivalent:
aw.patch('https://api.aweber.com/1.0/example/1', opts).then(/* ... */);
aw.patch('/1.0/example/1', opts).then(/* ... */);

Aweber#post(url, options)

Makes a single POST request to the AWeber API for the given resource, returning a Promise.

Params

  • url {String}: URL of the resource to be created (host and query params optional)
  • options {Object}: Options object
  • options.data {Object}: Dictionary of field/value pairs
  • options.params {Object}: Dictionary of query parameters to specify

Example

const data = { foo: 1, bar: true };
const params = { 'ws.op': 'create' };

// All of the following are equivalent:
aw.post('https://api.aweber.com/1.0/example?ws.op=create', { data }).then(/* ... */);
aw.post('https://api.aweber.com/1.0/example', { data, params }).then(/* ... */);
aw.post('/1.0/example?ws.op=create', { data }).then(/* ... */);
aw.post('/1.0/example', { data, params }).then(/* ... */);

Aweber#put(url, options)

Makes a single PUT request to the AWeber API for the given resource, returning a Promise.

Params

  • url {String}: URL of the resource to be updated (host and query params optional)
  • options {Object}: Options object
  • options.data {Object}: Dictionary containing fully updated record
  • options.params {Object}: Dictionary of query parameters to specify

Example

const opts = { data: { id: 1, foo: 1, bar: true } };

// All of the following are equivalent:
aw.post('https://api.aweber.com/1.0/example', opts).then(/* ... */);
aw.post('/1.0/example', opts).then(/* ... */);

License

MIT