1.0.1 • Published 8 years ago

fb-ninja v1.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

fb-ninja

Makes batch requests to facebook API an easy task for you

Features

  • Can handle a lot of API calls by split and defer them
  • Accept callbacks before, after, afterEach, beforeEach
  • Lightweight and fast

Install

npm install --save fb-ninja

Get started

const ninja = require("fb-ninja")

// define what you need for every request
const request = {
  method: "get",
  api: "me/accounts"
}

// top level access token
const options = { accessToken: process.env.ACCESS_TOKEN }

// get all result in one place as well as result per request
// place as many requests as you want
ninja(request, options)
  .then(detailedResult => console.log(detailedResult))
  .catch(err => console.error(err))

Arguments

Request

It's the first parameter. All of them reffers to the api call itself.
Message or link are required. It's part of facebook field itself.

RequiredKeyDescripitonTypeDefault
yesaccessTokenLow level access tokenString
yesmessageMessage or link are requiredString
nolinkMessage or link are requiredString
nomethodLow level methodStringGET

Options

it's the second parameter

RequiredKeyDescripitonTypeDefault
yesaccessTokenTop level access tokenString""
nomethodTop level method (POST in batch requests always)StringPOST
noapiTop level api ("" in batch requests always)String""
noincludeHeadersinclude headers in response or notBooleanfalse
noappIdTop level facebook application IDnull
notimeoutAmount of time between batch requestsms60000
nobeforeBefore first loopFunctionnull
noafterAfter last loopFunctionnull
nobeforeEachBefore each loopFunctionnull
noafterEachAfter each loopFunctionnull
noretryRetry canceled requests?Booleantrue

Tests

First of all make sure you have installed dev dependencies:

npm install

To run tests you should make file at the root folder facebook.json and put there expected expected by you information that you can get fromFacebook Graph API Explorer.

{
  "me": {  
    "name": "[FACEBOOK_NAME]",
    "id": "[FACEBOOK_ID]",
    "accessToken": "[FACEBOOK_ACCESS_TOKEN]"
  },
  "page": {
    "accessToken": "[PAGE_FACEBOOK_ACCESS_TOKEN]"
  }
}

Then run

npm test