okgrow/rest2ddp

Name: rest2ddp

Owner: OK GROW!

Description: DEPRECATED - this package is no longer supported

Created: 2015-10-10 17:46:19.0

Updated: 2018-03-27 19:56:17.0

Pushed: 2016-07-22 17:01:19.0

Homepage:

Size: 169

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Deprecated

DISCLAIMER - Development of this package is currently on hiatus. We are currently not actively developing this package due to both resource constraints and uncertainty about how well supported it will be in the future. We are using this in our active projects, so we will continue to do bug fixes as we encounter them, but feature requests may go unanswered. PRs are still welcome.

REST2DDP Meteor Atmosphere Package

Convert REST APIs into DDP publications for your client side to reactively consume.

Add it to your project meteor add okgrow:rest2ddp.

Examples
1. Collection (Client and/or Server)

REST2DDP requires a Meteor collection to interact with. Typically this is called on the client but can be on the server or both as well.

ballPlayers = new Mongo.Collection('baseballPlayers');
2. Config Objects (Server)

REST2DDP.configs is a global array of objects which hold configuration settings for each publication. Since this object could hold private keys it is recommended to only have these configs on the server-side.

| Setting | Type | Required | Description | | — | — | — | — | |name | string | true | Name of the publication to subscribe to. | |collection | string | true | Specify which collection to send data. | |restUrl | string | true | The URL of the REST call. Dynamic parameters are held by a dollar sign blocks, ${varName}. | |jsonPath | string | true | Tell REST2DDP where to find the array in the API response. The path must always be an array and end with a wildcard (). Check out the jsonpath docs. | |pollInterval| number | false | Sets the interval in seconds of pinging the API. Defaults to 10 seconds. | |headerKeys | array | false | An array of strings. Specifies which keys are allowed in the header of a call. Good idea to set since clients can modify the header. | |headers* | object | false | Pass an object of default key values passed with every call. Client can override key values. Values must be a string. |

----------------
ASIC EXAMPLE
----------------
2DDP.configs.push({
me: 'basic-baseball-player-stats',
llectionName: 'baseballPlayers',
stUrl:'http://dev.mlb.com/api/teamStats&team=cubs',
onPath: '$.results.players.*'


----------------
DVANCE EXAMPLE
----------------
apiToken = process.env.MLB_API_TOKEN;

2DDP.configs.push({
me: 'adv-baseball-player-stats',
llectionName: 'baseballPlayers',
stUrl:'http://dev.mlb.com/api/teamStats&team=${teamName}',
onPath: '$.results.players.*',
llInterval: 30,
aderKeys: ['token', 'Content-Type'],
aders: {
token:apiToken,
'Content-Type': 'application/json'


3. Subscribing (Client or Server)

On the client you will subscribe to REST2DDP like you would any other publication and pass it parameters. The name of the publication you are subscribing to will always be 'REST2DDP'.

| Argument | Type | Required | Description | | — | — | — | — | | 1 | string | true | Name of the publication you are subscribing to will always be 'REST2DDP'. | | 2 | string | true | Name of configuration to call. | | 3 | object | false | Takes upto two optional keys which are objects, variables: {object} and headers: {object}. |

late.playersList.onCreated(function () {
r self = this;

 -----------------
 BASIC EXAMPLE
 -----------------
lf.autorun(function () {
self.subscribe('REST2DDP', 'basic-baseball-player-stats');
;

 -----------------
 ADVANCE EXAMPLE
 -----------------
lf.autorun(function () {
self.subscribe('REST2DDP', 'adv-baseball-player-stats', {
  variables: {
    teamName: 'cubs'
  },
  headers: {}
});
;

How to help/future features
Contributing

Issues and Pull Requests are always welcome. Please read our contribution guidelines.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.