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

atrigger

v0.0.365

Published

A Trigger API JavaScript library

Downloads

24

Readme

atrigger

Build Status

A very simple A Trigger JavaScript library that helps you schedule and manage tasks using A Trigger's API.

What is A Trigger?

A Trigger is a tool/service that helps you schedule periodic and fixed-time tasks by sending a GET request to a given url. It is a very simple and considerably flexible alternative to using Cron for job scheduling.

I use it a lot, so I wrote this simple abstraction to make my life easier and hopefully yours too.

Features

This module helps you create, delete, pause, and resume tasks with ease and without worrying about URI Encoding, enormous URIs, GET requests, or anything other than your actual work. Also, with this module you can check if an IP address belongs to an atrigger.com server so you can verify the authenticity of a task call.

This is basically a simple abstraction of the A Trigger Rest API. The main purpose of this mini-project was to create and publish my first npm module as I learn more and more about Node.js and JavaScript. But I didn't want to do something useless, so I built this. :smiley:

Usage Example

atrigger is very simple to use:

// Require the atrigger module
var ATrigger = require('atrigger');

// Create a new ATrigger client instance with your API Key and Secret
var tasks = new ATrigger({
  APIKey: 'API_KEY',
  APISecret: 'API_SECRET'
});

// Create a new task
tasks.create({
  url: 'http://www.krismuniz.com/',
  timeSlice: '10min',
  count: 10,
  tags: {
    'title': 'call-my-site',
    'id': 'OtftvvsJ'
  }
});

You can handle request errors and API responses, too.

tasks.create({
  url: 'http://www.krismuniz.com/',
  timeSlice: '10min',
  count: 10,
}, function(err, res) {
  if (err) {
    // Handle error
  } else {
    // Do stuff with APIs response
  }
});

Installation

Installing the atrigger module is as simple as installing any other npm module:

$ npm install atrigger

API Reference

create method

Creates a new task given a specific set of parameters. The callback function is optional.

tasks.create({
  // parameters
}, callback(err, res));
Required Parameters:
  • url ([string]): The target url that A Trigger will call at defined timeSlice. Note: There is no need to use URIEncode(), the module does that for you.

  • timeSlice ([string]): The time frequency at which your task needs to be executed. (e.g. 'Xminute', 'Xhour', 'Xday', 'Xmonth', 'Xyear' where X is a positive integer)

  • tags ([object]): An object containing tags (e.g. { tagname: tagvalue, tagname2: tagvalue2 }). You need to tag your tasks for future identification and to control them using the API.

Optional Parameters:
  • retries ([integer]): How many times A Trigger should try if your server failed (or was down)? Default value: 3

  • count ([integer]): How many cycles should be repeated? For an infinite amount of times write -1. Read more at count parameter (Wiki).

  • first ([string from date in ISO 8601 format]): When should the first call be made? You are not required to set time value by default. Read more at first parameter (Wiki). Hint: use .toISOString() to convert a date to the proper format.

delete method

Deletes all tasks containing a specified set of tags. The callback function is optional.

tasks.delete({
  // parameters
}, callback(err, res));
Required Parameters:
  • tags ([object]): An object containing tags (e.g. { tagname: tagvalue, tagname2: tagvalue2 }). You need to tag your tasks for future identification and to control them using the API.

pause method

Pauses all currently-active tasks that contain a specified set of tags. The callback function is optional.

tasks.pause({
  // parameters
}, callback(err, res));
Required Parameters:
  • tags ([object]): An object containing tags (e.g. { tagname: tagvalue, tagname2: tagvalue2 }). You need to tag your tasks for future identification and to control them using the API.

resume method

Resumes all currently-paused tasks that contain a specified set of tags. The callback function is optional.

tasks.resume({
  // parameters
}, callback(err, res));
Required Parameters:
  • tags ([object]): An object containing tags (e.g. { tagname: tagvalue, tagname2: tagvalue2 }). You need to tag your tasks for future identification and to control them using the API.

verifyRequest method

Pass an IP address and the A Trigger API will respond if the call comes from an A Trigger server. The callback function is required (otherwise the method's existence would be pointless).

tasks.verifyRequest({
  ip: '192.168.1.1'
}, callback(err, res));
Required Parameters:
  • ip ([string]): The IP address you want to verify.

Testing

Want to run some tests?

$ npm install
$ npm test

License

The MIT License (MIT)

Copyright (c) 2015 Kristian Muñiz [http://krismuniz.com/]

Disclaimer

I am not affiliated in any way to A Trigger and this library is not official. I just use this service and wanted to build this library for educational and productivity reasons.