Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

cloudrail-si

CloudRail602.21.12TypeScript support: included

The CloudRail SI SDK for Node.JS, a simple, universal, unified API for the most popular cloud services. Supports: AmazonS3, Box, Backblaze, Dropbox, Egnyte, Facebook, FacebookPage, Foursquare, GitHub, GoogleCloudPlatform, GoogleDrive, GooglePlaces, Google

AmazonS3, Box, Backblaze, Dropbox, Egnyte, Facebook, FacebookPage, Foursquare, GitHub, GoogleCloudPlatform, GoogleDrive, GooglePlaces, GooglePlus, Heroku, Instagram, LinkedIn, MailJet, MicrosoftAzure, MicrosoftLive, Microsoft, Nexmo, OneDrive, OneDriveBusiness, PayPal, ProductHunt, Rackspace, SendGrid, Slack, SlackBot, Stripe, Twilio, Twitter, Twizo, Yahoo, Yelp, GMail, FacebookMessenger, Viber, Line, Telegram, PCloud

readme

npm version

CloudRail SI for node.js

Integrate Multiple Services With Just One API

CloudRail is an API integration solution which abstracts multiple APIs from different providers into a single and universal interface.

--- ---

Learn more about CloudRail at https://cloudrail.com

Full documentation can be found here



With CloudRail, you can easily integrate external APIs into your application. CloudRail provides abstracted interfaces that take several services and then exposes a developer-friendly API that uses common functions between all providers. This means that, for example, upload() works in exactly the same way for Dropbox as it does for Google Drive, OneDrive, and other Cloud Storage Services, and getEmail() works similarly the same way across all social networks.

NPM

npm install cloudrail-si

Current Interfaces

Interface Included Services
Cloud Storage Dropbox, Google Drive, OneDrive, OneDrive Business, Box, Egnyte
Business Cloud Storage Amazon S3, Microsoft Azure, Google Cloud Services, Rackspace, Backblaze
Social Profile Facebook, GitHub, Google+, LinkedIn, Slack, Twitter, Windows Live, Yahoo, Instagram, Heroku
Social Interaction Facebook, Facebook Page, Twitter
Payment PayPal, Stripe
Email Maljet, Sendgrid
SMS Twilio, Nexmo
Point of Interest Google Places, Foursquare, Yelp
Video YouTube, Twitch, Vimeo
Messaging Facebook Messenger, Telegram, Line, Viber
---
### Cloud Storage Interface:
  • Dropbox
  • Box
  • Google Drive
  • Microsoft OneDrive
  • Microsoft OneDrive for Business
  • Egnyte

Features:

  • Download files from Cloud Storage.
  • Upload files to Cloud Storage.
  • Get Meta Data of files, folders and perform all standard operations (copy, move, etc) with them.
  • Retrieve user and quota information
  • Generate share links for files and folders
  • Get thumbnails for images

Full Documentation

Code Example:

const cloudrail = require("cloudrail-si");
cloudrail.Settings.setKey("[CloudRail License Key]");

// let cs = new cloudrail.services.Box(redirectReceiver, "[clientIdentifier]", "[clientSecret]", "[redirectUri]", "[state]");
// let cs = new cloudrail.services.OneDrive(redirectReceiver, "[clientIdentifier]", "[clientSecret]", "[redirectUri]", "[state]");
// let cs = new cloudrail.services.OneDriveBusiness(redirectReceiver, "[clientIdentifier]", "[clientSecret]", "[redirectUri]", "[state]");
// let cs = new cloudrail.services.GoogleDrive(redirectReceiver, "[clientIdentifier]", "[clientSecret]", "[redirectUri]", "[state]");
let cs = new cloudrail.services.Dropbox(redirectReceiver, "[clientIdentifier]", "[clientSecret]", "[redirectUri]", "[state]");

cs.createFolder("/TestFolder", (err) => { // <---
    if (err) throw err;
    let fileStream = fs.createReadStream("UserData.csv");
    let size = fs.statSync("UserData.csv").size;
    cs.upload("/TestFolder/Data.csv", fileStream, size, false, (err) => { // <---
        if (err) throw err;
        console.log("Upload successfully finished");
    });
});

Business/Bucket Cloud Storage Interface:

  • Amazon Web Services S3
  • Microsoft Azure
  • Google Cloud Services
  • Rackspace
  • Backblaze

Features

  • Create, delete and list buckets
  • Upload files
  • Download files
  • List files in a bucket and delete files
  • Get file metadata (last modified, size, etc.)

Full Documentation

Code Example

const cloudrail = require("cloudrail-si");
cloudrail.Settings.setKey("[CloudRail License Key]");

// let bcs = new cloudrail.services.AmazonS3(null, "[accessKeyId]", "[secretAccessKey]", "[region]");
// let bcs = new cloudrail.services.MicrosoftAzure(null, "[accountName]", "[accessKey]");
// let bcs = new cloudrail.services.GoogleCloudServices(null, "[clientEmail]", "[privateKey]", "[projectId]");
// let bcs = new cloudrail.services.Rackspace(null, "[userName]", "[apiKey]", "[region]");
let bcs = new cloudrail.services.Backblaze(null, "[accountId]", "[appKey]");

bcs.createBucket("myNewBucket", (err, bucket) => {
    if (err) throw err;
    let fileStream = fs.createReadStream("UserData.csv");
    let size = fs.statSync("UserData.csv").size;
    bcs.upload(bucket, "Data.csv", fileStream, size, (err) => { // <---
        if (err) throw err;
        console.log("Upload successfully finished");
    });
});

Social Profile Interface:

  • Facebook
  • Github
  • Google Plus
  • LinkedIn
  • Slack
  • Twitter
  • Windows Live
  • Yahoo
  • Instagram
  • Heroku

Features

  • Get profile information, including full names, emails, genders, date of birth, and locales.
  • Retrieve profile pictures.
  • Login using the Social Network.

Full Documentation

Code Example:

const cloudrail = require("cloudrail-si");
cloudrail.Settings.setKey("[CloudRail License Key]");

// let profile = new cloudrail.services.GooglePlus(redirectReceiver, "[clientIdentifier]", "[clientSecret]", "[redirectUri]", "[state]");
// let profile = new cloudrail.services.GitHub(redirectReceiver, "[clientIdentifier]", "[clientSecret]", "[redirectUri]", "[state]");
// let profile = new cloudrail.services.Slack(redirectReceiver, "[clientIdentifier]", "[clientSecret]", "[redirectUri]", "[state]");
// let profile = new cloudrail.services.Instagram(redirectReceiver, "[clientIdentifier]", "[clientSecret]", "[redirectUri]", "[state]");
// ...
let profile = new cloudrail.services.Facebook(redirectReceiver, "[clientIdentifier]", "[clientSecret]", "[redirectUri]", "[state]");

profile.getFullName((err, fullName) => {
    if (err) throw err;
    console.log("User's full name is " + fullName);
});

profile.getEmail((err, email) => {
    if (err) throw err;
    console.log("User's email address is " + email);
});

Social Interaction Interface:

  • Facebook (interacts with a user)
  • Facebook Pages (interacts with a page)
  • Twitter

Features

  • Get the IDs of a user's friends/followers. Works well with the Profile interface's "login with" to check if two of your users are friends on a platform
  • Post messages to a wall/stream
  • Post pictures and videos to a wall/stream

Full Documentation

Code Example:

const cloudrail = require("cloudrail-si");
cloudrail.Settings.setKey("[CloudRail License Key]");

// let social = new cloudrail.services.Facebook(redirectReceiver, "[clientIdentifier]", "[clientSecret]", "[redirectUri]", "[state]");
// let social = new cloudrail.services.FacebookPage(redirectReceiver, "[pageName]", "[clientIdentifier]", "[clientSecret]", "[redirectUri]", "[state]");
let social = new cloudrail.services.Twitter(redirectReceiver, "[clientIdentifier]", "[clientSecret]", "[redirectUri]");

social.postUpdate("Hello from CloudRail", (err) => {
    if (err) throw err;
    console.log("Update posted");
});

let fileStream = fs.createReadStream("video.mp4");
let size = fs.statSync("video.mp4").size;
social.postVideo("This is a test video", fileStream, size, "video/mp4", (err) => {
    if (err) throw err;
    console.log("Video posted");
});

Payment Interface:

  • PayPal
  • Stripe

Features

  • Perform charges
  • Refund previously made charges
  • Manage subscriptions

Full Documentation

Code Example

const cloudrail = require("cloudrail-si");
cloudrail.Settings.setKey("[CloudRail License Key]");

// let payment = new cloudrail.services.Stripe(null, "[secretKey]");
let payment = new cloudrail.services.PayPal(null, true, "[clientIdentifier]", "[clientSecret]");

let source = new cloudrail.types.CreditCard(null, 6, 2021, "xxxxxxxxxxxxxxxx", "visa", "<FirstName>", "<LastName>", null);
payment.createCharge(500, "USD", source, (err, charge) => {
    if (err) throw err;
    console.log("Successfully charged " + charge.amount + " " + charge.currency);
});

Email Interface:

  • Mailjet
  • Sendgrid

Features

  • Send Email

Full Documentation

Code Example

const cloudrail = require("cloudrail-si");
cloudrail.Settings.setKey("[CloudRail License Key]");

// let email = new cloudrail.services.Mailjet(null, "[clientID]", "[clientSecret]");
let email = new cloudrail.services.Sendgrid(null, "[APIKey]");

email.sendEmail("info@cloudrail.com", "CloudRail", ["foo@bar.com", "bar@foo.com"], "Welcome", "Hello from CloudRail", null, null, null, (err) => {
    if (err) throw err;
    console.log("Email successfully sent");
});

SMS Interface:

  • Twilio
  • Nexmo

Features

  • Send SMS

Full Documentation

Code Example

const cloudrail = require("cloudrail-si");
cloudrail.Settings.setKey("[CloudRail License Key]");

// let sms = new cloudrail.services.Nexmo(null, "[clientIdentifier]", "[clientSecret]");
let sms = new cloudrail.services.Twilio(null, "[clientIdentifier]", "[clientSecret]");

sms.sendSMS("CloudRail", "+4912345678", "Hello from CloudRail", (err) => {
    if (err) throw err;
    console.log("SMS successfully sent");
});

Points of Interest Interface:

  • Google Places
  • Foursquare
  • Yelp

Features

  • Get a list of POIs nearby
  • Filter by categories or search term

Full Documentation

Code Example

const cloudrail = require("cloudrail-si");
cloudrail.Settings.setKey("[CloudRail License Key]");

// let poi = new cloudrail.services.Foursquare(null, "[clientID]", "[clientSecret]");
// let poi = new cloudrail.services.Yelp(null, "[consumerKey]", "[consumerSecret]", "[token]", "[tokenSecret]");
let poi = new cloudrail.services.GooglePlaces(null, "[apiKey]");

poi.getNearbyPOIs(49.4557091, 8.5279138, 1000, "restaurant", null, (err, pois) => {
    if (err) throw err;
    console.log("Amount of locations called 'restaurant' in a 1 km radius around the given coordinates: " + pois.length);
});

Video Interface:

  • YouTube
  • Twitch
  • Vimeo

Features

  • Get channel metadata
  • List videos for a channel
  • Get video metadata
  • Search for videos
  • Upload a video

Full Documentation

Code Example

const cloudrail = require("cloudrail-si");
cloudrail.Settings.setKey("[CloudRail License Key]");

// let video = new cloudrail.services.Twitch(redirectReceiver, "[clientID]", "[clientSecret]");
// let video = new cloudrail.services.Vimeo(redirectReceiver, "[clientID]", "[clientSecret]");
let video = new cloudrail.services.YouTube(redirectReceiver, "[clientID]", "", "com.cloudrail.example:/auth", "state");

video.searchVideos("CloudRail", 0, 50, (err, videos) => {
    if (err) throw err;
    console.log("Videos: " + videos);
});

Messaging Interface:

  • Facebook Messenger
  • Telegram
  • Line
  • Viber

Features

  • Send text messages
  • Send files, images, videos and audios
  • Parse a message received on your webhook
  • Download the content of an attachment sent to your webhook

Full Documentation

Code Example

const cloudrail = require("cloudrail-si");
cloudrail.Settings.setKey("[CloudRail License Key]");

// let messaging = new cloudrail.services.Line(null, "[BotToken]");
// let messaging = new cloudrail.services.Telegram(null, "[BotToken]", "[WebhookUrl]");
// let messaging = new cloudrail.services.Viber(null, "[BotToken]", "[WebhookUrl]", "[BotName]");
let messaging = new cloudrail.services.FacebookMessenger(null, "[BotToken]");

messaging.sendMessage("92hf2f83f9", "Greetings from CloudRail!", (err, message) => {
    if (err) throw err;
    console.log("Message: " + message);
});

More interfaces are coming soon.

Advantages of Using CloudRail

  • Consistent Interfaces: As functions work the same across all services, you can perform tasks between services simply.

  • Easy Authentication: CloudRail includes easy ways to authenticate, to remove one of the biggest hassles of coding for external APIs.

  • Switch services instantly: One line of code is needed to set up the service you are using. Changing which service is as simple as changing the name to the one you wish to use.

  • Simple Documentation: There is no searching around Stack Overflow for the answer. The CloudRail Wiki is regularly updated, clean, and simple to use.

  • No Maintenance Times: The CloudRail Libraries are updated when a provider changes their API.

  • Direct Data: Everything happens directly in the Library. No data ever passes a CloudRail server.

NPM

npm install cloudrail-si

Typescript

(this only concerns Typescript users)

The package includes an index.d.ts file. To use the typings provided, include services and types like so:

/// <reference path="node_modules/cloudrail-si/index.d.ts" />

import {PointsOfInterest} from "cloudrail-si/interfaces/PointsOfInterest";
import {Foursquare} from "cloudrail-si/services/Foursquare";
import {POI} from "cloudrail-si/types/POI";

let poi:PointsOfInterest = new Foursquare(null, "[clientID]", "[clientSecret]");

poi.getNearbyPOIs(49.4557091, 8.5279138, 1000, "restaurant", null, (err:Error, pois:POI[]) => {
    if (err) console.log(err);
    console.log("Amount of locations called 'restaurant' in a 1 km radius around the given coordinates: " + pois.length);
});

Examples

Check out https://github.com/CloudRail/cloudrail-si-node-sdk/tree/master/examples for examples of how to e.g. implement a redirectReceiver and more complex use cases.

License Key

CloudRail provides a developer portal which offers usage insights for the SDKs and allows you to generate license keys.

It's free to sign up and generate a key.

Head over to https://developers.cloudrail.com

Pricing

Learn more about our pricing on https://cloudrail.com/cloudrail-pricing/

Other Platforms

CloudRail is also available for other platforms like Android, iOS and Java. You can find all libraries on https://cloudrail.com

Questions?

Get in touch at any time by emailing us: support@cloudrail.com

or

Tag a question with cloudrail on StackOverflow

changelog

CloudRail SI Node.JS SDK changelog

  • 2.21.12

    • OneDriveBusiness: Fix Authentication process
    • GoogleDrive: Fix fileExists method
    • Backblaze: Fix an issue related to advanced request
  • 2.21.11

    • OneDriveBusiness: Fix missing url encoding of the client secret on refreshing tokens
    • GoogleCloudPlatform: Add a missing internal function
    • MicrosoftAzure: Fix an issue in the advanced request function
  • 2.21.10

    • OneDrive: Attach missing state parameter to authentication url
    • Facebook: Removed user_about_me scope which shows description. This is removed from Facebook
    • Google Cloud: Added object name encoding to google cloud
  • 2.21.9

    • Business Cloud Storage : Implement listFilesWithPrefix method .
    • Minor fixes for Google Drive API.
  • 2.21.8

    • Google Cloud Platform: Implement missing paging in listFiles() method
    • Egnyte & Google Drive: Minor fixes
    • Google Cloud Platform & Amazon S3: Add missing advanced request feature
    • Microsoft Azure: Fix listFiles() method and implement advanced request
    • Yelp: Update to a new API version including a different authentication
  • 2.21.7

    • Add a new method to the CloudStorage interface that allows uploading files with a custom modified date
    • Fix a missing Authorization header in getChildren and getChildrenPage of OneDrive
    • Fix error handling in Dropbox
    • Fix an issue with upload in PCloud
  • 2.21.6

    • Add PCloud as a new service to the CloudStorage interface
    • Bugfix for GoogleDrive
  • 2.21.4

    • Bugfix for GoogleDrive and SlackBot
  • 2.21.3

    • Add a fix for AmazonS3's listFiles method
    • Bug fixes for GMail and Telegram
    • Add SlackBot as a new service for the messaging interface
  • 2.21.0

    • Full release of the messaging interface including FacebookMessanger, Viber, Line and Telegram
    • Bugfix for Amazon S3: The getChildrenPage() method was not returning more than 1000 files
    • OneDriveBusiness is now using the new Microsoft Graph API
    • GoogleDrive now uses the state parameter during authentication
    • Box: Locating a file within a folder containing more than 100 files was not working properly
    • GoogleDrive: Some files could not be found even though the files existed and the getChildrenPage method was not working properly for large folders
    • CloudStorage: The exists method now returns true for the root folder
  • 2.20.0

    • Release the new video interface containing YouTube, Twitch and Vimeo. This interface allows you to upload and search for videos as well as querying all kinds of metadata.
  • 2.19.0

    • Add the possibility to send attachments to the Email interface and also introduce GMail as a new integration
    • Update Yelp to their new API
    • Update OneDrive to use the new Microsoft Graph API
    • Egnyte now correctly returns the username
    • Fix an issue within getChildrenPage that occurred in most CloudStorage services
  • 2.18.1

    • Fix the authentication for Twitter which did not allow a user to successfully authenticate
  • 2.18.0

    • Add a new method to the cloud storage interface that allows to search for files and folders
  • 2.17.4

    • Add Twizo to the SMS interface
    • Add the Microsoft service which uses the new Microsoft Graph API to access OneDrive
  • 2.17.3

    • Fixed issues with OneDrive for files and folders having whitespace in their names. Caused by an unannounced API change by Microsoft.
    • Downloading a Google Documents file with Google Drive now downloads an export of the file as PDF.
  • 2.17.2

    • Minor fix for an issue where potential errors would be misattributed to another service
  • 2.17.1

    • Fixed broken Facebook constructor
    • Small fixes for optional scopes parameter
  • 2.17.0

    • Added Product Hunt as a new service to the Profile interface
    • Added an additional, optional "scopes" constructor parameter to all services doing OAuth with programatically settable scopes
  • 2.16.0

    • Advanced Request now available for all services
  • 2.15.0

    • Advanced Request now available for the services implementing the Profile interface
  • 2.14.0

    • Added a new function to make supported raw HTTP requests to the services implementing Cloud Storage (advanced request)
  • 2.13.0

    • Added functions to post pictures and videos to a user's wall to the Social interface, Facebook and Twitter have been extended accordingly
    • Added FacebookPage as a new service to the Social interface. It allows posting updates/pictures/videos to a Facebook page
  • 2.12.0

    • Google Cloud Services added as a new integration in the Business Cloud Storage interface
    • Fixed an issue with Google Drive reauthentication
  • 2.11.1

    • Fixed an issue where Box would return incorrect lastModified timestamps
    • Fixed an issue with file/folder names containing single quotes on Google Drive
    • Dropbox now returns an already created share link
  • 2.11.0

    • Added OneDrive for Business as a new service to the Cloud Storage interface
    • Bugfixes to OneDrive and Dropbox concerning files and folders with special characters
    • Fixed an issue where Box would return maximally 100 children of a folder
    • Added a function to retrieve children in chunks to all Cloud Storage services
    • Updated Google Drive from API version 2 to 3
  • 2.10.1

    • Heroku has been added as a new service implementing Profile. It supports the retrieval of a unique ID, the full name and the email address. It is still in Beta and not officially listed or documented.
  • 2.10.0

    • Introduced new interface called Business Cloud Storage
    • Amazon S3 has been added as a new service implementing Business Cloud Storage
    • Microsoft Azure has been added as a new service implementing Business Cloud Storage
    • Backblaze has been added as a new service implementing Business Cloud Storage
    • Rackspace has been added as a new service implementing Business Cloud Storage
  • 2.9.3

    • Small fixes to error reporting of some services
    • Facebook integration now uses newest version of the Facebook API
  • 2.9.2

    • Fixed an issue where a timeout would keep code using the library running indefinitely
  • 2.9.1

    • Added Egnyte as a new service, implementing the CloudStorage interface. It does not support retrieval of user login, user name, available and used space or thumbnails since the API exposes no such information yet.
    • Fixed bugs where GoogleDrive and OneDrive would not return ImageMetaData on elements retrieved through getChildren()
  • 2.9.0

    • The services in the CloudStorage interface now have an additional method to get thumbnails
    • The CloudMetaData objects now have additional dimension information for images
  • 2.8.1

    • Fixed an issue where an Error was thrown when logging out an already logged out instance of Box
  • 2.8.0

    • BREAKING: License key is now mandatory
    • Bugfixes for Box and Dropbox integrations
  • 2.7.0

    • BREAKING: The RedirectReceiver's callback function has a Node-style signature now
    • Added standard implementation for a RedirectReceiver with "electron" framework
    • Minor bugfixes
  • 2.6.2

    • Added standard implementation for local RedirectReceiver
  • 2.6.1

    • Made SendGrid integration more robust by updating to API v3
  • 2.6.0

    • Added "exists" function to "CloudStorage" interface
    • Added optional license key integration
  • 2.5.3

    • Fixed incompatibility with older Node versions
    • Better quality of error messages
  • 2.5.2

    • Bugfix to have errors contain messages
  • 2.5.1

    • Compile to ES5 instead of ES6 for compatibility reasons
    • Minor bugfixes
  • 2.5.0

    • Included "Social" interface
    • Added space allocation information to "CloudStorage"
  • 2.4.0

    • Initial release (Non-minor version numbers between SDKs for different platforms used to be synchronized)