first commit
This commit is contained in:
Коммит
4c0d4dbea5
|
@ -0,0 +1,30 @@
|
|||
# Ignore build
|
||||
dist/
|
||||
|
||||
# Ignore extensions
|
||||
*.diff
|
||||
*.err
|
||||
*.log
|
||||
*.orig
|
||||
*.rej
|
||||
*.swo
|
||||
*.swp
|
||||
*.vi
|
||||
*.zip
|
||||
*~
|
||||
|
||||
# Ignore OS or Editor folders
|
||||
._*
|
||||
.cache
|
||||
.DS_Store
|
||||
.project
|
||||
.settings
|
||||
.idea
|
||||
.tmproj
|
||||
*.esproj
|
||||
*.sublime-workspace
|
||||
*.sublime-project
|
||||
|
||||
# Ignore node
|
||||
node_modules/
|
||||
npm-debug.log
|
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"curly": false,
|
||||
"eqeqeq": true,
|
||||
"immed": true,
|
||||
"latedef": true,
|
||||
"newcap": true,
|
||||
"noarg": true,
|
||||
"sub": true,
|
||||
"undef": true,
|
||||
"boss": true,
|
||||
"eqnull": true,
|
||||
"node": true,
|
||||
"expr": true,
|
||||
"maxdepth": 3,
|
||||
"unused": true,
|
||||
"trailing": true,
|
||||
"quotmark": "simple",
|
||||
"strict": false,
|
||||
"browser": true,
|
||||
"newcap": false
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
|
||||
This program is licensed to you under the terms of Version 2.0 of the
|
||||
Apache License. This program is distributed WITHOUT
|
||||
ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
details.
|
|
@ -0,0 +1,201 @@
|
|||
JavaScript Client Library for DeployR
|
||||
=====================================
|
||||
|
||||
The JavaScript client library is a light-weight fluent API used to communicate
|
||||
with DeployR from both the browser and Node.js environments. It is crafted for
|
||||
flexibility, readability, and a low learning curve.
|
||||
|
||||
Links
|
||||
-----
|
||||
|
||||
* [Download](http://deployr.revolutionanalytics.com/docanddown/#clientlib)
|
||||
* [User Guide Documentation](http://deployr.revolutionanalytics.com/documents/dev/client-jsdoc)
|
||||
* [API Documentation](http://deployr.revolutionanalytics.com/documents/dev/client-jsdoc/api/)
|
||||
* [Installation](http://deployr.revolutionanalytics.com/documents/dev/client-jsdoc/#install)
|
||||
* [Simple examples](#examples)
|
||||
* [Gulp, for building](#building)
|
||||
* [Tests](#tests)
|
||||
* [License](#license)
|
||||
|
||||
Environments
|
||||
============
|
||||
|
||||
We recommend you [download and install](http://nodejs.org/download/) Node.js.
|
||||
It is __not__ a requirement for the browser however using the JavaScript client
|
||||
library from within a server or from the command line in addition to the browser
|
||||
can be powerful!
|
||||
|
||||
Browser
|
||||
-------
|
||||
|
||||
If your environment is the browser the JavaScript client library can be found
|
||||
here:
|
||||
|
||||
```
|
||||
./deployr/browser/deployr.js
|
||||
./deployr/browser/deployr.min.js
|
||||
```
|
||||
|
||||
Node.js
|
||||
-------
|
||||
|
||||
If your environment is Node then the entire root ```./deployr/``` directory
|
||||
represents the JavaScript client library as it uses the same source for both
|
||||
environments.
|
||||
|
||||
Installation
|
||||
============
|
||||
|
||||
Browser
|
||||
-------
|
||||
|
||||
Using the browser version:
|
||||
|
||||
```bash
|
||||
./deployr/browser/deployr.js
|
||||
./deployr/browser/deployr.min.js
|
||||
```
|
||||
|
||||
Include either one on your page in the `<script>` tag:
|
||||
|
||||
```html
|
||||
<!-- Latest compiled raw JavaScript variation -->
|
||||
<script src="./browser/deployr.js"></script>
|
||||
|
||||
Or
|
||||
|
||||
<!-- Latest compiled minified JavaScript variation -->
|
||||
<script src="./browser/deployr.min.js"></script>
|
||||
```
|
||||
|
||||
Node.js
|
||||
-------
|
||||
|
||||
1. [Download and install](http://nodejs.org/download/) Node.js, which includes
|
||||
npm. npm, which stands for _node packaged modules_, is a way to manage
|
||||
development dependencies through Node.js.
|
||||
|
||||
2. ```$npm install deployr```
|
||||
|
||||
3. `require` the directory:
|
||||
|
||||
```
|
||||
var deployr = require('deployr');
|
||||
```
|
||||
|
||||
Examples
|
||||
========
|
||||
|
||||
The DeployR JavaScript client library ships with a set of small examples under
|
||||
the __./deployr/examples__ directory that run in both the browser and Node.js
|
||||
environments. The intention of the examples are to demonstrate the syntax and
|
||||
core areas of the JavaScript API. They are not intended to be a tutorial on how
|
||||
to write web applications.
|
||||
|
||||
We encourage you to start here and customise these examples and adapt them to
|
||||
suit your needs as you explore the API.
|
||||
|
||||
- __./examples/js-api:__ Introduces the core areas of the JavaScript API.
|
||||
|
||||
- __./examples/tutorial:__ Introduces the top-level R analytics services exposed
|
||||
on the DeployR API.
|
||||
|
||||
Running
|
||||
-------
|
||||
|
||||
__Browser:__
|
||||
|
||||
- Copy the _.html_ files under `./examples` to your webserver
|
||||
- Copy the `./examples/config.json` file under `./examples` to your webserver
|
||||
- Set the DeployR endpoint and basic authentication credentials in
|
||||
`./examples/config.json`
|
||||
|
||||
```
|
||||
{
|
||||
"endpoint": "http://dhost:port",
|
||||
"credentials": {
|
||||
"username": "testuser",
|
||||
"password": "changeme"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Alternatively, you can run the examples as is without moving them via the
|
||||
embedded web server if you have Node.js installed:
|
||||
|
||||
`$ npm install --global gulp`
|
||||
|
||||
`$ cd ./deployr`
|
||||
|
||||
`$ npm install`
|
||||
|
||||
`$gulp start`
|
||||
|
||||
Open your browser to _http://localhost:3000/examples/_ and select an example
|
||||
.html file to run.
|
||||
|
||||
__Node.js:__
|
||||
|
||||
Set the DeployR endpoint and basic authentication credentials in
|
||||
`./examples/config.json`
|
||||
|
||||
```
|
||||
{
|
||||
"endpoint": "http://dhost:port",
|
||||
"credentials": {
|
||||
"username": "testuser",
|
||||
"password": "changeme"
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
From the command line run one of the Node.js examples:
|
||||
|
||||
```$ node ./examples/PATH_TO_EXAMPLE_FILE.js```
|
||||
|
||||
Building
|
||||
========
|
||||
|
||||
This section only pertains to the _Browser_ environment.
|
||||
|
||||
Our dev and release builds are handled by [gulp.js](http://gulpjs.com/).
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
First you need to install `gulp` (`$ sudo npm install --global gulp`)
|
||||
|
||||
After cloning you can simply do an NPM install.
|
||||
|
||||
`$ npm install`
|
||||
|
||||
This will install the development tools needed to build locally.
|
||||
|
||||
Shortcuts
|
||||
---------
|
||||
|
||||
* `gulp` Runs a build.
|
||||
* `gulp start` Runs a build and starts a local webserver with LiveReload
|
||||
(port __3000__) rebuilding on file changes.
|
||||
|
||||
Destination
|
||||
-----------
|
||||
The browser build destination is located in the __./browser__ directory.
|
||||
|
||||
Tests
|
||||
=====
|
||||
|
||||
Coming soon...
|
||||
|
||||
License
|
||||
=======
|
||||
|
||||
Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
|
||||
This program is licensed to you under the terms of Version 2.0 of the
|
||||
Apache License. This program is distributed WITHOUT
|
||||
ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
details.
|
|
@ -0,0 +1,426 @@
|
|||
{
|
||||
"/r/user/login" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/user/logout" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/user/about" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/user/autosave" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/user/release" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/project/create" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/project/pool" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/project/recycle" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/project/list" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/project/ping" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/project/about" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/project/about/update" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/project/save" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/project/saveas" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/project/close" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/project/grant" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/project/import" : {
|
||||
"method": "POST",
|
||||
"format": "json",
|
||||
"upload": true
|
||||
},
|
||||
|
||||
"/r/project/export" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/project/delete" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/project/execute/code" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/project/execute/script" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/project/execute/interrupt" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/project/execute/console" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/project/execute/history" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/project/execute/flush" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/project/execute/result/list" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/project/execute/result/download" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/project/execute/result/delete" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/project/workspace/list" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/project/workspace/get" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/project/workspace/upload" : {
|
||||
"method": "POST",
|
||||
"format": "json",
|
||||
"upload": true
|
||||
},
|
||||
|
||||
"/r/project/workspace/transfer" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/project/workspace/push" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/project/workspace/save" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/project/workspace/store" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/project/workspace/load" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/project/workspace/delete" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/project/directory/list" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/project/directory/upload" : {
|
||||
"method": "POST",
|
||||
"format": "json",
|
||||
"upload": true
|
||||
},
|
||||
|
||||
"/r/project/directory/transfer" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/project/directory/write" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/project/directory/update" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/project/directory/store" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/project/directory/load" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/project/directory/download" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/project/directory/delete" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/project/package/list" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/project/package/attach" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/project/package/detach" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/job/list" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/job/submit" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/job/schedule" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/job/query" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/job/cancel" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/job/delete" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/repository/directory/list" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/repository/directory/create" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/repository/directory/rename" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/repository/directory/copy" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/repository/directory/move" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/repository/directory/update" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/repository/script/list" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/repository/script/execute" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/repository/script/render" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/repository/script/interrupt" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/repository/directory/archive" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/repository/directory/upload" : {
|
||||
"method": "POST",
|
||||
"format": "json",
|
||||
"upload": true
|
||||
},
|
||||
|
||||
"/r/repository/directory/download" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/repository/directory/delete" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/repository/file/list" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/repository/file/fetch" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/repository/file/fetch" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/repository/file/upload" : {
|
||||
"method": "POST",
|
||||
"format": "json",
|
||||
"upload": true
|
||||
},
|
||||
|
||||
"/r/repository/file/transfer" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/repository/file/write" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/repository/file/update" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/repository/file/diff" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/repository/file/revert" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/repository/file/grant" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/repository/file/download" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/repository/file/delete" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/repository/file/copy" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/repository/file/move" : {
|
||||
"method": "POST",
|
||||
"format": "json"
|
||||
},
|
||||
|
||||
"/r/server/info" : {
|
||||
"method": "GET",
|
||||
"format": "json"
|
||||
}
|
||||
}
|
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"endpoint": "http://localhost:7300",
|
||||
"cors": true,
|
||||
"credentials": {
|
||||
"username": "testuser",
|
||||
"password": "changeme"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/*
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* usage: $ node agency.js
|
||||
*
|
||||
* Runs DeployR request chains using diffrent cookies.
|
||||
*
|
||||
* @NOTE - Any time deployr.io(...) is called it will create a new jsessionid,
|
||||
* in other words requests will not by sticky. Cookies are shared across
|
||||
* requests if you use the same `agent` (i.e. same authenticated user)
|
||||
* to make .io() calls to DeployR.
|
||||
*
|
||||
*/
|
||||
|
||||
var deployr = require('../../deployr'),
|
||||
config = require('../config'),
|
||||
credentials = config.credentials;
|
||||
|
||||
deployr.configure( { host: config.endpoint, sticky: false });
|
||||
|
||||
// ====================================================================
|
||||
// should start with empty session and should gain a session cookie for
|
||||
// the chained requests
|
||||
// ====================================================================
|
||||
|
||||
var agent1 = deployr.io('/r/user/login')
|
||||
.data(credentials)
|
||||
.end(function(res) {
|
||||
console.log('agent1-HTTP COOKIE:: ' + res.get('httpcookie'));
|
||||
});
|
||||
|
||||
// ====================================================================
|
||||
// should persist cookies across requests
|
||||
// ====================================================================
|
||||
|
||||
agent1.io('/r/project/create')
|
||||
.on('deployr-io:401', function(err) {
|
||||
console.log(err);
|
||||
})
|
||||
.end(function(res) {
|
||||
console.log('agent1-HTTP COOKIE:: ' + res.get('httpcookie'));
|
||||
|
||||
// add project-id to next `agent1.io` call which is `/r/project/close`
|
||||
return { project: res.get('project').project };
|
||||
});
|
||||
|
||||
agent1.io('/r/project/close')
|
||||
.end(function(res) {
|
||||
console.log('agent1-HTTP COOKIE:: ' + res.get('httpcookie'));
|
||||
})
|
||||
|
||||
agent1.io('/r/user/about')
|
||||
.end(function(res) {
|
||||
console.log('agent1-HTTP COOKIE:: ' + res.get('httpcookie'));
|
||||
});
|
||||
|
||||
// ====================================================================
|
||||
// should (not) share cookies with `agent1`
|
||||
// ====================================================================
|
||||
|
||||
// wait to send `agent3` until `agent2` returns so we can use agent2's cookies
|
||||
// notice no `.end()` used here. Remember `.end()` sends the request to DeployR
|
||||
var agent3 = deployr.script('/testuser/root/DeployR - Hello World.R');
|
||||
|
||||
var agent2 = deployr.script('/testuser/root/DeployR - Hello World.R')
|
||||
.end(function(res) {
|
||||
console.log('agent2-HTTP COOKIE:: ' + res.get('httpcookie'));
|
||||
|
||||
|
||||
// ====================================================================
|
||||
// should share cookies with `agent2`
|
||||
// ====================================================================
|
||||
agent3.share(agent2.getCookies()).end(function(ires) {
|
||||
console.log('agent3-HTTP COOKIE:: ' + ires.get('httpcookie'));
|
||||
});
|
||||
});
|
||||
|
||||
// ====================================================================
|
||||
// should not lose cookies between `agent2`
|
||||
// ====================================================================
|
||||
|
||||
agent1.script('/testuser/root/DeployR - Hello World.R')
|
||||
.end(function(res) {
|
||||
console.log('agent1-HTTP COOKIE:: ' + res.get('httpcookie'));
|
||||
});
|
|
@ -0,0 +1,133 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title>Example using request chaining</title>
|
||||
<script src="../../../../browser/deployr.min.js"></script>
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Example using request chaining</h1>
|
||||
<hr>
|
||||
<ol>
|
||||
<li>Populate <strong>/examples/config.json</strong> with the proper values before running.</li>
|
||||
<li>Open the browser's debug window to view print logs for this example.</li>
|
||||
<li>View <a href="http://deployr.revolutionanalytics.com/documents/dev/client-jsdoc/">documentation</a> for more information.</li>
|
||||
</ol>
|
||||
|
||||
<script>
|
||||
/*
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* usage: http://localhost:8080/examples/js-api/chain.html
|
||||
* Runs a DeployR request chain in sequence but asynchronous:
|
||||
* ----------------------------------------------------------------------
|
||||
* 0. configure request to DeployR server `http://dhost:port`
|
||||
* 1. /r/user/login
|
||||
* 2. /r/repository/script/execute
|
||||
* 3. /r/project/create
|
||||
* 4. /r/project/execute/script
|
||||
* 5. /r/project/close
|
||||
* 6. /r/user/logout
|
||||
*
|
||||
* @NOTE - If error occures somewhere in the call chain it is aborted.
|
||||
* ----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
* Run example.
|
||||
*/
|
||||
function run(config) {
|
||||
var credentials = config.credentials;
|
||||
|
||||
/*
|
||||
* Configure the DeployR server endpoint.
|
||||
*/
|
||||
deployr.configure({
|
||||
logging: true,
|
||||
host: config.endpoint,
|
||||
cors: config.cors
|
||||
});
|
||||
|
||||
// ====================================================================
|
||||
|
||||
var ruser = deployr.auth(credentials.username, credentials.password);
|
||||
|
||||
// ================================================================
|
||||
ruser.io('/r/repository/script/execute')
|
||||
.data({
|
||||
filename: 'DeployR - Hello World',
|
||||
author: 'testuser'
|
||||
})
|
||||
//.data({ httpEventOnly: true })
|
||||
//.data({ revoEventOnly: true })
|
||||
.data({ consoleoff: false })
|
||||
.data( { enableConsoleEvents: true })
|
||||
.numeric('input_randomNum', 10)
|
||||
.character('input_character', 'hello')
|
||||
.error(function(err) {
|
||||
// do something with the error
|
||||
})
|
||||
.end(function(res, chain) {
|
||||
// do something with the success response
|
||||
})
|
||||
// ================================================================
|
||||
.io('/r/project/create')
|
||||
.error(function(err) {
|
||||
// do something with the error
|
||||
})
|
||||
.end(function(res, chain) {
|
||||
// attach project from `/r/project/create` on this io() call [2]
|
||||
return {
|
||||
project: res.deployr.response.project.project
|
||||
};
|
||||
})
|
||||
// ================================================================
|
||||
.io('/r/project/execute/script')
|
||||
.data({
|
||||
filename: 'DeployR - Hello World',
|
||||
author: 'testuser'
|
||||
})
|
||||
.data({ httpEventOnly: true })
|
||||
//.data({ revoEventOnly: true })
|
||||
.numeric('input_randomNum', 10)
|
||||
.error(function(err) {
|
||||
// do something with the error
|
||||
})
|
||||
.end(function(res, chain) {
|
||||
// attach project from `/r/project/create` on this io() call [2]
|
||||
return {
|
||||
project: chain[2].deployr.response.project.project
|
||||
};
|
||||
})
|
||||
// ================================================================
|
||||
.io('/r/project/close')
|
||||
.end(function(res, chain) {
|
||||
// do something with the success response
|
||||
})
|
||||
// ================================================================
|
||||
.io('/r/user/logout')
|
||||
.end(function(res, chain) {
|
||||
// do something with the success response
|
||||
});
|
||||
// ================================================================
|
||||
}
|
||||
|
||||
// -- load configuration and run example --
|
||||
$.getJSON('/examples/config.json').done(function(config) { run(config); });
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -0,0 +1,82 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/*
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* usage: $ node chain.js
|
||||
*
|
||||
* Runs a DeployR request chain in sequence but asynchronous:
|
||||
* --------------------------------------------------------------------
|
||||
* 0. configure request to DeployR server endpoint
|
||||
* 1. /r/user/login
|
||||
* 2. /r/repository/script/execute
|
||||
* 3. /r/project/create
|
||||
* 4. /r/project/execute/script
|
||||
* 5. /r/project/close
|
||||
* 6. /r/user/logout
|
||||
* --------------------------------------------------------------------
|
||||
* @NOTE - If error occures somewhere in the call chain it is aborted.
|
||||
*/
|
||||
|
||||
var deployr = require('../../deployr'),
|
||||
config = require('../config'),
|
||||
credentials = config.credentials;
|
||||
|
||||
deployr.configure( { logging: true, host: config.endpoint })
|
||||
|
||||
// ====================================================================
|
||||
|
||||
var ruser = deployr.auth(credentials.username, credentials.password);
|
||||
|
||||
// ====================================================================
|
||||
|
||||
ruser.io('/r/repository/script/execute')
|
||||
.data({ filename : 'DeployR - Hello World', author: 'testuser' })
|
||||
.numeric('input_randomNum', 10)
|
||||
.character('input_character', 'hello')
|
||||
.error(function(err) {
|
||||
// do something with the error
|
||||
})
|
||||
.end(function(res, chain) {
|
||||
// do something with the success response
|
||||
})
|
||||
// ====================================================================
|
||||
.io('/r/project/create')
|
||||
.error(function(err) {
|
||||
// do something with the error
|
||||
})
|
||||
.end(function(res, chain) {
|
||||
// attach project from `/r/project/create` on this io() call [2]
|
||||
return { project: res.get('project').project };
|
||||
})
|
||||
// ====================================================================
|
||||
.io('/r/project/execute/script')
|
||||
.data({ filename : 'DeployR - Hello World', author: 'testuser' })
|
||||
.numeric('input_randomNum', 10)
|
||||
.error(function(err) {
|
||||
// do something with the error
|
||||
})
|
||||
.end(function(res, chain) {
|
||||
// attach project from `/r/project/create` on this io() call [2]
|
||||
return { project: chain[2].deployr.response.project.project };
|
||||
})
|
||||
// ====================================================================
|
||||
.io('/r/project/close')
|
||||
.end(function(res, chain) {
|
||||
// do something with the success response
|
||||
})
|
||||
// ====================================================================
|
||||
.io('/r/user/logout')
|
||||
.end(function(res, chain) {
|
||||
// do something with the success response
|
||||
});
|
||||
// ====================================================================
|
|
@ -0,0 +1,187 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title>Deprecated API Example</title>
|
||||
<script src="../../../../browser/deployr.min.js"></script>
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Deprecated API Example</h1>
|
||||
<hr>
|
||||
<ol>
|
||||
<li>Populate <strong>/examples/config.json</strong> with the proper values before running.</li>
|
||||
<li>Open the browser's debug window to view print logs for this example.</li>
|
||||
<li>View <a href="http://deployr.revolutionanalytics.com/documents/dev/client-jsdoc/">documentation</a> for more information.</li>
|
||||
</ol>
|
||||
|
||||
<script>
|
||||
/*
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/* -----------------------------------------------------------------------
|
||||
* usage: http://localhost:8080/examples/js-api/deprecated-api.html
|
||||
*
|
||||
* Example using the deprecated `jsDeployr.js` interface
|
||||
* -----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
* Run example.
|
||||
*/
|
||||
function run(config) {
|
||||
|
||||
var R = window.Revolution,
|
||||
credentials = config.credentials;
|
||||
|
||||
// All possible RInputs
|
||||
function createAllRInputs() {
|
||||
var rinputs = [];
|
||||
rinputs.push(R.RDataFactory.createNumeric('input_numeric', 5));
|
||||
rinputs.push(R.RDataFactory.createInteger('input_integer', 10));
|
||||
rinputs.push(R.RDataFactory.createBoolean('input_boolean', true));
|
||||
rinputs.push(R.RDataFactory.createString('input_string', 'Hello'));
|
||||
rinputs.push(R.RDataFactory.createDate('input_date', new Date()));
|
||||
rinputs.push(R.RDataFactory.createPOSIXDate('input_posixct', new Date()));
|
||||
rinputs.push(R.RDataFactory.createNumericVector('input_numericVector', [1.1, 2.1, 3.1, 4.1, 5.1]));
|
||||
rinputs.push(R.RDataFactory.createIntegerVector('input_integerVector', [1, 2, 3, 4, 5]));
|
||||
rinputs.push(R.RDataFactory.createBooleanVector('input_booleanVector', [true, false, true, true]));
|
||||
rinputs.push(R.RDataFactory.createStringVector('input_StringVector', ['Hello', 'how', 'are', 'you?']));
|
||||
rinputs.push(R.RDataFactory.createDateVector('input_dateVector', [new Date(), new Date(), new Date()]));
|
||||
rinputs.push(R.RDataFactory.createPOSIXDateVector('input_posixctVector', [new Date(), new Date(), new Date()]));
|
||||
rinputs.push(R.RDataFactory.createFactor('input_orderedfactor', [1, 2, 3], true, [4, 5, 6], ['a', 'b', 'c']));
|
||||
rinputs.push(R.RDataFactory.createFactor('input_unorderedfactor', [1, 2, 3], false, [4, 5, 6], ['a', 'b', 'c']));
|
||||
rinputs.push(R.RDataFactory.createNumericMatrix('input_numericMatrix', [
|
||||
[1.1, 2.1, 3.1, 4.1, 5.1]
|
||||
]));
|
||||
rinputs.push(R.RDataFactory.createIntegerMatrix('input_integerMatrix', [
|
||||
[1, 2, 3, 4, 5]
|
||||
]));
|
||||
rinputs.push(R.RDataFactory.createBooleanMatrix('input_logicalMatrix', [
|
||||
[true, false, true, true]
|
||||
]));
|
||||
rinputs.push(R.RDataFactory.createStringMatrix('input_characterMatrix', [
|
||||
['Hello', 'how', 'are', 'you?']
|
||||
]));
|
||||
|
||||
return rinputs;
|
||||
}
|
||||
|
||||
R.DeployR.init({
|
||||
deployrURI: config.endpoint,
|
||||
events: {
|
||||
|
||||
unload: {
|
||||
disableautosave: true,
|
||||
dropworkspace: true,
|
||||
dropdirectory: true,
|
||||
drophistory: true,
|
||||
flushhistory: true
|
||||
},
|
||||
|
||||
globalIO: {
|
||||
scope: this,
|
||||
lifecycle: {
|
||||
|
||||
start: function() {
|
||||
console.log('GLOBAL:START');
|
||||
},
|
||||
|
||||
success: function(res, api) {
|
||||
console.log('GLOBAL:SUCCESS');
|
||||
},
|
||||
|
||||
failure: function(code, res, api) {
|
||||
console.log('GLOBAL:FAILURE');
|
||||
},
|
||||
|
||||
complete: function() {
|
||||
console.log('GLOBAL:COMPLETE');
|
||||
},
|
||||
|
||||
end: function() {
|
||||
console.log('GLOBAL:END');
|
||||
}
|
||||
},
|
||||
|
||||
statusCode: {
|
||||
500: function(api, res) {
|
||||
console.log('GLOBAL:500');
|
||||
console.log('API::: ' + api);
|
||||
},
|
||||
|
||||
900: function(api, res) {
|
||||
console.log('GLOBAL:900');
|
||||
console.log('API::: ' + api);
|
||||
},
|
||||
|
||||
940: function(api, res) {
|
||||
console.log('GLOBAL:940');
|
||||
console.log('API::: ' + api);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
R.DeployR.userLogin({
|
||||
username: credentials.username,
|
||||
password: credentials.password,
|
||||
transaction: {
|
||||
scope: this,
|
||||
'arguments': {
|
||||
foo: 'FOO',
|
||||
bar: 'BAR'
|
||||
},
|
||||
statusCode: {
|
||||
940: function() {
|
||||
console.log('TRANSACTION:940');
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
scope: this,
|
||||
success: function(res) {
|
||||
console.log('end----/r/user/login------');
|
||||
console.log(res);
|
||||
console.log('--------------------------');
|
||||
|
||||
R.DeployR.repositoryScriptExecute({
|
||||
filename: 'DeployR - Hello World',
|
||||
author: 'testuser',
|
||||
inputs: createAllRInputs()
|
||||
}, {
|
||||
scope: this,
|
||||
success: function(res) {
|
||||
console.log(res);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
failure: function(res) {
|
||||
console.log('error----/r/user/login------');
|
||||
console.log(res);
|
||||
console.log('----------------------------');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// -- load configuration and run example --
|
||||
$.getJSON('/examples/config.json').done(function(config) {
|
||||
run(config);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -0,0 +1,49 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/*
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* usage: $ node ensure.js
|
||||
*
|
||||
* Simple promise chaining using `.ensure()` and `.then()` based on the
|
||||
* Promises/A+ specs.
|
||||
*/
|
||||
|
||||
var config = require('../config'),
|
||||
credentials = config.credentials,
|
||||
deployr = require('../../deployr').configure( { host: config.endpoint });
|
||||
|
||||
var ruser = deployr.auth(credentials.username, credentials.password);
|
||||
|
||||
ruser.script('/testuser/root/DeployR - Hello World.R')
|
||||
.end(function() {
|
||||
console.log('script');
|
||||
})
|
||||
.ensure(function() {
|
||||
console.log('finally cleanup...');
|
||||
// using `ruser` implies that a logout occurs on the same user session
|
||||
ruser.release();
|
||||
})
|
||||
.then(function(res) {
|
||||
console.log('then this.');
|
||||
return res; // pass result to the next `.then()`
|
||||
}, function(err) {
|
||||
console.log(err);
|
||||
})
|
||||
.then(function(res) {
|
||||
console.log('after that then this.');
|
||||
return res; // pass result to the next `.then()`
|
||||
})
|
||||
.then(function(res) {
|
||||
console.log('after that then we are done.');
|
||||
console.log(res);
|
||||
});
|
|
@ -0,0 +1,46 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/*
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* usage: $ node entiry.js
|
||||
*
|
||||
* Runs a DeployR basic auth using the `.entity('user')` helper method to
|
||||
* filter-out and return only the Top Level `user` entity from the response.
|
||||
*
|
||||
* The supported `Top Level` entities are:
|
||||
* - 'user'
|
||||
* - 'project'
|
||||
* - 'workspace'
|
||||
* - 'execution'
|
||||
* - 'directory'
|
||||
* - 'repository',
|
||||
* - 'packages'
|
||||
*/
|
||||
|
||||
var config = require('../config'),
|
||||
credentials = config.credentials,
|
||||
deployr = require('../../deployr').configure( { host: config.endpoint });
|
||||
|
||||
deployr.io('/r/user/login')
|
||||
.data(credentials)
|
||||
.entity('user')
|
||||
.error(function(err) {
|
||||
console.log(err);
|
||||
})
|
||||
.end(function(res) {
|
||||
// viewing the response will show only the `user` section returned and the
|
||||
// rest filtered out
|
||||
console.log(res);
|
||||
})
|
||||
.io('/r/user/logout')
|
||||
.end();
|
|
@ -0,0 +1,130 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/*
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* usage: $ node es-client.js
|
||||
*
|
||||
* Example binding to the DeployR EventStream API '/r/event/stream'
|
||||
*
|
||||
* example dependencies: express
|
||||
* - $ npm install express
|
||||
*/
|
||||
|
||||
var deployr = require('../../deployr'),
|
||||
config = require('../config'),
|
||||
util = require('util'),
|
||||
app = require('express')();
|
||||
|
||||
/*
|
||||
* stdout helper to print a string representation of object for the example.
|
||||
*/
|
||||
var printf = function(obj) {
|
||||
console.log(util.inspect(obj, false, null, true));
|
||||
console.log('\n\n');
|
||||
};
|
||||
|
||||
deployr.configure( { logging: false, host: config.endpoint });
|
||||
|
||||
var es = deployr.es(config.credentials)
|
||||
// -- connection choices for event types --
|
||||
.session() // default
|
||||
//.all()
|
||||
//.project(id)
|
||||
//.job(id)
|
||||
//.management()
|
||||
// -- end connection choices for event types --
|
||||
.on('es:error', function(data) {
|
||||
console.log('===================');
|
||||
console.log('es:error');
|
||||
console.log('===================');
|
||||
printf(data);
|
||||
})
|
||||
.on('es:connecting', function(data) {
|
||||
console.log('===================');
|
||||
console.log('es:connecting');
|
||||
console.log('===================');
|
||||
printf(data);
|
||||
})
|
||||
.on('es:disconnect', function(data) {
|
||||
console.log('===================');
|
||||
console.log('es:disconnect');
|
||||
console.log('===================');
|
||||
printf(data);
|
||||
})
|
||||
.on('es:streamConnect', function(data) {
|
||||
console.log('===================');
|
||||
console.log('es:streamConnect');
|
||||
console.log('===================');
|
||||
printf(data);
|
||||
})
|
||||
.on('es:streamDisconnect', function(data) {
|
||||
console.log('===================');
|
||||
console.log('es:streamDisconnect');
|
||||
console.log('===================');
|
||||
printf(data);
|
||||
})
|
||||
.on('es:executionConsole', function(data) {
|
||||
console.log('===================');
|
||||
console.log('es:executionConsole');
|
||||
console.log('===================');
|
||||
printf(data);
|
||||
})
|
||||
.on('es:executionRevo', function(data) {
|
||||
console.log('===================');
|
||||
console.log('es:executionRevo');
|
||||
console.log('===================');
|
||||
printf(data);
|
||||
})
|
||||
.on('es:executionError', function(data) {
|
||||
console.log('===================');
|
||||
console.log('es:executionError');
|
||||
console.log('===================');
|
||||
printf(data);
|
||||
})
|
||||
.on('es:jobLifecycle', function(data) {
|
||||
console.log('===================');
|
||||
console.log('es:jobLifecycle');
|
||||
console.log('===================');
|
||||
printf(data);
|
||||
})
|
||||
.on('es:gridHeartbeat', function(data) {
|
||||
console.log('===================');
|
||||
console.log('es:gridHeartbeat');
|
||||
console.log('===================');
|
||||
printf(data);
|
||||
})
|
||||
.on('es:gridActivity', function(data) {
|
||||
console.log('===================');
|
||||
console.log('es:gridActivity');
|
||||
console.log('===================');
|
||||
printf(data);
|
||||
})
|
||||
.on('es:gridWarning', function(data) {
|
||||
console.log('===================');
|
||||
console.log('es:gridWarning');
|
||||
console.log('===================');
|
||||
printf(data);
|
||||
})
|
||||
.on('es:securityLogin', function(data) {
|
||||
console.log('===================');
|
||||
console.log('es:securityLogin');
|
||||
console.log('===================');
|
||||
printf(data);
|
||||
})
|
||||
.on('es:securityLogout', function(data) {
|
||||
console.log('===================');
|
||||
console.log('es:securityLogout');
|
||||
console.log('===================');
|
||||
printf(data);
|
||||
})
|
||||
.open();
|
|
@ -0,0 +1,170 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title>Example using no request chaining</title>
|
||||
<script src="../../../../browser/deployr.min.js"></script>
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Example using no request chaining</h1>
|
||||
<hr>
|
||||
<ol>
|
||||
<li>Populate <strong>/examples/config.json</strong> with the proper values before running.</li>
|
||||
<li>Open the browser's debug window to view print logs for this example.</li>
|
||||
<li>View <a href="http://deployr.revolutionanalytics.com/documents/dev/client-jsdoc/">documentation</a> for more information.</li>
|
||||
</ol>
|
||||
|
||||
<script>
|
||||
/*
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* usage: http://localhost:8080/examples/js-api/no-chain.html
|
||||
*
|
||||
* Example using no request chaining. Runs a sequence of DeployR
|
||||
* requests via callbacks:
|
||||
* ----------------------------------------------------------------------
|
||||
* 0. configure request to DeployR server `http://dhost:dport`
|
||||
* 1. /r/user/login
|
||||
* 2. /r/repository/script/execute
|
||||
* 3. /r/project/create
|
||||
* 4. /r/project/execute/script
|
||||
* 5. /r/project/close
|
||||
* 6. /r/user/logout
|
||||
* ----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
var ruser = null;
|
||||
|
||||
/*
|
||||
* Run example.
|
||||
*/
|
||||
function run(config) {
|
||||
|
||||
deployr.configure({
|
||||
logging: true,
|
||||
cors: config.cors,
|
||||
host: config.endpoint
|
||||
});
|
||||
|
||||
|
||||
// --- kick off sequence of callbacks ---
|
||||
userLogin(config.credentials);
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
|
||||
function userLogin(credentials) {
|
||||
|
||||
ruser = deployr.io('/r/user/login');
|
||||
|
||||
ruser.data(credentials);
|
||||
|
||||
ruser.error(function(err) {
|
||||
// do something with the error
|
||||
});
|
||||
|
||||
ruser.end(function(res) {
|
||||
repositoryScriptExecute();
|
||||
});
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
|
||||
function repositoryScriptExecute() {
|
||||
ruser = ruser.io('/r/repository/script/execute');
|
||||
|
||||
ruser.data({ filename: 'DeployR - Hello World', author: 'testuser' });
|
||||
|
||||
ruser.numeric('input_randomNum', 10);
|
||||
|
||||
ruser.error(function(err) {
|
||||
// do something with the error
|
||||
});
|
||||
|
||||
ruser.end(function(res) {
|
||||
projectCreate();
|
||||
});
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
|
||||
function projectCreate() {
|
||||
ruser = ruser.io('/r/project/create');
|
||||
|
||||
ruser.error(function(err) {
|
||||
// do something with the error
|
||||
});
|
||||
|
||||
ruser.end(function(res) {
|
||||
projectExecuteScript(res.get('project').project);
|
||||
});
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
|
||||
function projectExecuteScript(project) {
|
||||
ruser = ruser.io('/r/project/execute/script');
|
||||
|
||||
ruser.data({
|
||||
filename: 'DeployR - Hello World',
|
||||
author: 'testuser',
|
||||
project: project
|
||||
});
|
||||
|
||||
ruser.numeric('input_randomNum', 10);
|
||||
|
||||
ruser.error(function(err) {
|
||||
// do something with the error
|
||||
});
|
||||
|
||||
ruser.end(function(res) {
|
||||
projectClose(project);
|
||||
});
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
|
||||
function projectClose(project) {
|
||||
ruser = ruser.io('/r/project/close');
|
||||
|
||||
ruser.data({ project: project });
|
||||
|
||||
ruser.end(function(res) {
|
||||
userLogout();
|
||||
});
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
|
||||
function userLogout() {
|
||||
ruser = ruser.io('/r/user/logout');
|
||||
|
||||
ruser.end(function(res) {
|
||||
// do something with the success response
|
||||
});
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
|
||||
|
||||
// -- load configuration and run example --
|
||||
$.getJSON('/examples/config.json').done(function(config) {
|
||||
run(config);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -0,0 +1,33 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/*
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* usage: $ node pipe.js
|
||||
*
|
||||
* Streaming JSON parser to pull out all `artifact urls` from a DeployR response
|
||||
* and prints them to stdout.
|
||||
*
|
||||
* dependencies: JSONStream
|
||||
* - $ npm install JSONStream
|
||||
*/
|
||||
|
||||
var JSONStream = require('JSONStream'),
|
||||
config = require('../config'),
|
||||
credentials = config.credentials,
|
||||
deployr = require('../../deployr').configure({ host: config.endpoint });
|
||||
|
||||
deployr.script('/testuser/root/DeployR - Hello World.R')
|
||||
.numeric('input_randomNum', 10)
|
||||
.pipe(JSONStream.parse('deployr.response.execution.artifacts.*.url'))
|
||||
.pipe(JSONStream.stringify(false))
|
||||
.pipe(process.stdout);
|
|
@ -0,0 +1,116 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/*
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* usage: $ node pipeline.js
|
||||
*
|
||||
* Runs two 'tasks' of DeployR request chains in sequence but asynchronous:
|
||||
* ----------------------------------------------------------------------------
|
||||
* 0. configure request to DeployR server `http://dhost:dport`
|
||||
*
|
||||
* --------------------------------
|
||||
* Batch 1 (runs first)
|
||||
* --------------------------------
|
||||
* 1. /r/user/login
|
||||
* 2. /r/repository/script/execute
|
||||
* 3. /r/project/create
|
||||
* 4. /r/project/execute/script
|
||||
* 5. /r/project/close
|
||||
* --------------------------------
|
||||
* Batch 2 (runs second)
|
||||
* --------------------------------
|
||||
* 1. /r/user/about
|
||||
* 2. /r/user/logout
|
||||
* ----------------------------------------------------------------------------
|
||||
* @NOTE - If error occures somewhere in the call chain it is aborted.
|
||||
*/
|
||||
|
||||
var deployr = require('../../deployr'),
|
||||
config = require('../config'),
|
||||
credentials = config.credentials;
|
||||
|
||||
deployr.configure({ logging: false, host: config.endpoint });
|
||||
|
||||
function firstTask() {
|
||||
|
||||
return deployr.io('/r/user/login')
|
||||
.delay()
|
||||
.data(credentials)
|
||||
.end()
|
||||
.io('/r/repository/script/execute')
|
||||
.delay()
|
||||
.data({ filename: 'DeployR - Hello World', author: 'testuser' })
|
||||
.numeric('input_randomNum', 10)
|
||||
.end()
|
||||
.io('/r/project/create')
|
||||
.delay()
|
||||
.end(function (res, chain) {
|
||||
// attach project from `/r/project/create` on this io() call [2]
|
||||
return { project: res.deployr.response.project.project };
|
||||
})
|
||||
.io('/r/project/execute/script')
|
||||
.delay()
|
||||
.data({ filename: 'DeployR - Hello World', author: 'testuser' })
|
||||
.numeric('input_randomNum', 10)
|
||||
.end(function (res, chain) {
|
||||
// attach project from `/r/project/create` on this io() call [2]
|
||||
return { project: chain[2].deployr.response.project.project };
|
||||
})
|
||||
// ================================================================
|
||||
.io('/r/project/close')
|
||||
.delay()
|
||||
.end();
|
||||
}
|
||||
|
||||
function secondTask() {
|
||||
return deployr.io('/r/user/about')
|
||||
.delay()
|
||||
.end()
|
||||
.io('/r/user/logout')
|
||||
.delay()
|
||||
.end();
|
||||
}
|
||||
|
||||
/*
|
||||
* deployr.pipline()
|
||||
*
|
||||
* Runs an array of `tasks` in sequence, without overlap where a `task` is one
|
||||
* or more chained sequ `.io()` call(s) to DeployR. This examples piplines two
|
||||
* `task` batches.
|
||||
*
|
||||
* @@@ Important @@@
|
||||
*
|
||||
* You must `.delay()` the `.io()` calls otherwise they will run immediately and
|
||||
* in parallel.
|
||||
*/
|
||||
|
||||
console.log('Starting the DeployR request pipeline...');
|
||||
|
||||
deployr.pipeline([firstTask(), secondTask()])
|
||||
.then(function(chain) {
|
||||
console.log('[success]--------------------------------------------------');
|
||||
|
||||
// print results for each request in each task that ran through the pipeline
|
||||
chain.results.forEach(function(task, index) {
|
||||
console.log('---------------------------------');
|
||||
console.log('Task ' + (index + 1) + ' results');
|
||||
console.log('---------------------------------');
|
||||
task.forEach(function(result) { console.log(result); });
|
||||
});
|
||||
|
||||
console.log('-----------------------------------------------------------');
|
||||
}, function(err) {
|
||||
console.log('[error]----------------------------------------------------');
|
||||
console.log(err);
|
||||
console.log('-----------------------------------------------------------');
|
||||
});
|
|
@ -0,0 +1,47 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/*
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* usage: $ node promise.js
|
||||
*
|
||||
* Simple promise chaining using `.promise()` rather than `.end()` to send the
|
||||
* DeployR request. The return value of `.promise()` will be a Promise based on
|
||||
* the Promises/A+ specs.
|
||||
*/
|
||||
|
||||
var config = require('../config'),
|
||||
credentials = config.credentials,
|
||||
deployr = require('../../deployr').configure( { host: config.endpoint });
|
||||
|
||||
var ruser = deployr.auth(credentials.username, credentials.password);
|
||||
|
||||
ruser.io('/r/user/about')
|
||||
.promise() // using `.promise()` instead of `.end()` to send the request
|
||||
.then(function(res) {
|
||||
console.log('then this.');
|
||||
return res; // pass result to the next `.then()`
|
||||
}, function(err) {
|
||||
console.log(err);
|
||||
})
|
||||
.then(function(res) {
|
||||
console.log('after that then this.');
|
||||
return res; // pass result to the next `.then()`
|
||||
})
|
||||
.then(function(res) {
|
||||
console.log('after that then we are done.');
|
||||
console.log(res);
|
||||
})
|
||||
.ensure(function() {
|
||||
console.log('finally cleanup...');
|
||||
ruser.release();
|
||||
});
|
|
@ -0,0 +1,73 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title>Example inspecting response</title>
|
||||
<script src="../../../../browser/deployr.min.js"></script>
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Example inspecting response</h1>
|
||||
<hr>
|
||||
<ol>
|
||||
<li>Populate <strong>/examples/config.json</strong> with the proper values before running.</li>
|
||||
<li>Open the browser's debug window to view print logs for this example.</li>
|
||||
<li>View <a href="http://deployr.revolutionanalytics.com/documents/dev/client-jsdoc/">documentation</a> for more information.</li>
|
||||
</ol>
|
||||
|
||||
<script>
|
||||
/*
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* usage: http://localhost:8080/examples/js-api/response.html
|
||||
*
|
||||
* Example inspecting and printing a DeployR `/r/repository/script/execute`
|
||||
* response using the `.get(key)` helper for easy response property
|
||||
* lookup.
|
||||
* ----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
* Run example.
|
||||
*/
|
||||
function run(config) {
|
||||
/*
|
||||
* stdout print helper for the example.
|
||||
*/
|
||||
var printf = function(key, obj) {
|
||||
console.log('========================');
|
||||
console.log(key);
|
||||
console.log('========================');
|
||||
console.log(obj);
|
||||
console.log('\n\n');
|
||||
};
|
||||
|
||||
deployr.configure({ host: config.endpoint, cors: config.cors })
|
||||
.script('/testuser/root/DeployR - Hello World.R')
|
||||
.numeric('input_randomNum', 10)
|
||||
.end(function(res) {
|
||||
printf('Response', res);
|
||||
printf('call', res.get('call'));
|
||||
printf('success', res.get('success'));
|
||||
printf('console', res.get('console'));
|
||||
});
|
||||
}
|
||||
|
||||
// -- load configuration and run example --
|
||||
$.getJSON('/examples/config.json').done(function(config) { run(config); });
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -0,0 +1,44 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/*
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* usage: $ node response.js
|
||||
*
|
||||
* Example inspecting and printing a DeployR `/r/repository/script/execute`
|
||||
* response using the `.get(key)` helper for easy response property lookup.
|
||||
*/
|
||||
var util = require('util'),
|
||||
deployr = require('../../deployr'),
|
||||
config = require('../config');
|
||||
|
||||
/*
|
||||
* stdout helper to print a string representation of an object for the example.
|
||||
*/
|
||||
var printf = function(key, obj) {
|
||||
console.log('========================');
|
||||
console.log(key);
|
||||
console.log('========================');
|
||||
console.log(util.inspect(obj, false, null, true));
|
||||
console.log('\n\n');
|
||||
};
|
||||
|
||||
deployr.configure({ host: config.endpoint })
|
||||
.script('/testuser/root/DeployR - Hello World.R')
|
||||
.numeric('input_randomNum', 10)
|
||||
.end(function(res) {
|
||||
printf('Response', res);
|
||||
printf('call', res.get('call'));
|
||||
printf('success', res.get('success'));
|
||||
printf('artifacts', res.get('artifacts'));
|
||||
printf('console', res.get('console'));
|
||||
});
|
|
@ -0,0 +1,431 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title>Example using `rinputs`</title>
|
||||
<script src="../../../../browser/deployr.min.js"></script>
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Example using `rinputs`</h1>
|
||||
<hr>
|
||||
<ol>
|
||||
<li>Populate <strong>/examples/config.json</strong> with the proper values before running.</li>
|
||||
<li>Open the browser's debug window to view print logs for this example.</li>
|
||||
<li>View <a href="http://deployr.revolutionanalytics.com/documents/dev/client-jsdoc/">documentation</a> for more information.</li>
|
||||
</ol>
|
||||
|
||||
<script>
|
||||
/*
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* usage: http://localhost:8080/examples/js-api/rinputs.html
|
||||
*
|
||||
* Example using `rinputs`:
|
||||
*
|
||||
* .numeric(name, value)
|
||||
* .logical(name, value)
|
||||
* .date(name, value)
|
||||
* .posixct(name, value)
|
||||
* .numericVector(name, value)
|
||||
* .integerVector(name, value)
|
||||
* .logicalVector(name, value)
|
||||
* .characterVector(name, value)
|
||||
* .dateVector(name, value)
|
||||
* .posixctVector(name, value)
|
||||
* .factor(name, value, ordered, levels, labels)
|
||||
* .numericMatrix(name, value)
|
||||
* .integerMatrix(name, value)
|
||||
* .logicalMatrix(name, value)
|
||||
* .characterMatrix(name, value)
|
||||
* .list(name, value)
|
||||
* .dataframe(name, value)
|
||||
*
|
||||
* ~~~ Examples ~~~
|
||||
*
|
||||
* -------------------------------------------------------------
|
||||
* .character('x_character', 'c')
|
||||
* -------------------------------------------------------------
|
||||
* "x_character": {
|
||||
* "type": "primitive",
|
||||
* "value": "c"
|
||||
* }
|
||||
*
|
||||
* -------------------------------------------------------------
|
||||
* .integer('x_integer', 10)
|
||||
* -------------------------------------------------------------
|
||||
* "x_integer": {
|
||||
* "type": "primitive",
|
||||
* "value": 10
|
||||
* }
|
||||
*
|
||||
* -------------------------------------------------------------
|
||||
* .numeric('x_double', 5.5)
|
||||
* -------------------------------------------------------------
|
||||
* "x_double": {
|
||||
* "type": "primitive",
|
||||
* "value": 5.5
|
||||
* }
|
||||
*
|
||||
* -------------------------------------------------------------
|
||||
* .logical('x_double', 5.5)
|
||||
* -------------------------------------------------------------
|
||||
* "x_logical": {
|
||||
* "type": "primitive",
|
||||
* "value": true
|
||||
* }
|
||||
*
|
||||
* -------------------------------------------------------------
|
||||
* .date('x_date', new Date())
|
||||
* -------------------------------------------------------------
|
||||
* "x_date": {
|
||||
* "type": "date",
|
||||
* "value": "2011-10-04",
|
||||
* "format": "yyyy-MM-dd"
|
||||
* }
|
||||
*
|
||||
* -------------------------------------------------------------
|
||||
* .posixct('x_posixct', new Date())
|
||||
* -------------------------------------------------------------
|
||||
* "x_posixct": {
|
||||
* "type": "date",
|
||||
* "value": "2011-10-05 12:13:14 -0800",
|
||||
* "format": "yyyy-MM-dd HH:mm:ss Z"
|
||||
* }
|
||||
*
|
||||
* -------------------------------------------------------------
|
||||
* .characterVector('x_character_vector', ['a', 'b', 'c'])
|
||||
* -------------------------------------------------------------
|
||||
* "x_character_vector": {
|
||||
* "type": "vector",
|
||||
* "value": [
|
||||
* "a",
|
||||
* "b",
|
||||
* "c"
|
||||
* ]
|
||||
* }
|
||||
*
|
||||
* -------------------------------------------------------------
|
||||
* .integerVector('x_integer_vector', [10, 11, 12])
|
||||
* -------------------------------------------------------------
|
||||
* "x_integer_vector": {
|
||||
* "type": "vector",
|
||||
* "value": [
|
||||
* 10,
|
||||
* 11,
|
||||
* 12
|
||||
* ]
|
||||
* }
|
||||
*
|
||||
* -------------------------------------------------------------
|
||||
* .integerVector('x_numeric_vector', [10.1, 11.1, 12.1])
|
||||
* -------------------------------------------------------------
|
||||
* "x_numeric_vector": {
|
||||
* "type": "vector",
|
||||
* "value": [
|
||||
* 10.1,
|
||||
* 11.1,
|
||||
* 12.1
|
||||
* ]
|
||||
* }
|
||||
*
|
||||
* -------------------------------------------------------------
|
||||
* .matrix('x_matrix', [ [1, 3, 12], [2, 11, 12] ])
|
||||
* -------------------------------------------------------------
|
||||
* "x_matrix": {
|
||||
* "type": "matrix",
|
||||
* "value": [
|
||||
* [
|
||||
* 1,
|
||||
* 3,
|
||||
* 12
|
||||
* ],
|
||||
* [
|
||||
* 2,
|
||||
* 11,
|
||||
* 13
|
||||
* ]
|
||||
* ]
|
||||
* }
|
||||
*
|
||||
* -------------------------------------------------------------
|
||||
* .factor('x_ordered_factor',
|
||||
* true,
|
||||
* [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
|
||||
* ['s', 't', 'a', 't', 'i', 's', 't', 'i', 'c', 's' ],
|
||||
* ['s', 't', 'a', 't', 'i', 's', 't', 'i', 'c', 's' ]
|
||||
* -------------------------------------------------------------
|
||||
* "x_unordered_factor": {
|
||||
* "type": "factor",
|
||||
* "ordered": true,
|
||||
* "value": [
|
||||
* 1,
|
||||
* 2,
|
||||
* 3,
|
||||
* 4,
|
||||
* 5,
|
||||
* 6,
|
||||
* 7,
|
||||
* 8,
|
||||
* 9,
|
||||
* 10
|
||||
* ],
|
||||
* "labels": [
|
||||
* "s",
|
||||
* "t",
|
||||
* "a",
|
||||
* "t",
|
||||
* "i",
|
||||
* "s",
|
||||
* "t",
|
||||
* "i",
|
||||
* "c",
|
||||
* "s"
|
||||
* ],
|
||||
* "levels": [
|
||||
* "s",
|
||||
* "t",
|
||||
* "a",
|
||||
* "t",
|
||||
* "i",
|
||||
* "s",
|
||||
* "t",
|
||||
* "i",
|
||||
* "c",
|
||||
* "s"
|
||||
* ]
|
||||
* }
|
||||
*
|
||||
* -------------------------------------------------------------
|
||||
* .factor('x_unordered_factor',
|
||||
* false,
|
||||
* [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
|
||||
* ['s', 't', 'a', 't', 'i', 's', 't', 'i', 'c', 's' ],
|
||||
* ['s', 't', 'a', 't', 'i', 's', 't', 'i', 'c', 's' ]
|
||||
* -------------------------------------------------------------
|
||||
* "x_unordered_factor": {
|
||||
* "type": "factor",
|
||||
* "ordered": false,
|
||||
* "value": [
|
||||
* 1,
|
||||
* 2,
|
||||
* 3,
|
||||
* 4,
|
||||
* 5,
|
||||
* 6,
|
||||
* 7,
|
||||
* 8,
|
||||
* 9,
|
||||
* 10
|
||||
* ],
|
||||
* "labels": [
|
||||
* "s",
|
||||
* "t",
|
||||
* "a",
|
||||
* "t",
|
||||
* "i",
|
||||
* "s",
|
||||
* "t",
|
||||
* "i",
|
||||
* "c",
|
||||
* "s"
|
||||
* ],
|
||||
* "levels": [
|
||||
* "s",
|
||||
* "t",
|
||||
* "a",
|
||||
* "t",
|
||||
* "i",
|
||||
* "s",
|
||||
* "t",
|
||||
* "i",
|
||||
* "c",
|
||||
* "s"
|
||||
* ]
|
||||
*
|
||||
* -------------------------------------------------------------
|
||||
* .list('x_list', [
|
||||
* deplor.RInput.integerVector('first', [10, 11, 12]),
|
||||
* deplor.RInput.integerVector('second', [40, 41, 42])
|
||||
* ])
|
||||
* -------------------------------------------------------------
|
||||
* "x_list": {
|
||||
* "type": "list",
|
||||
* "value": [
|
||||
* {
|
||||
* "name": "first",
|
||||
* "value": [
|
||||
* 10,
|
||||
* 11,
|
||||
* 12
|
||||
* ],
|
||||
* "type": "vector"
|
||||
* },
|
||||
* {
|
||||
* "name": "second",
|
||||
* "value": [
|
||||
* 40,
|
||||
* 41,
|
||||
* 42
|
||||
* ],
|
||||
* "type": "vector"
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
*
|
||||
* -------------------------------------------------------------
|
||||
* .dataframe('x_dataframe', [
|
||||
* deplor.RInput.integerVector('first', [10, 11, 12]),
|
||||
* deplor.RInput.integerVector('second', [40, 41, 42])
|
||||
* ])
|
||||
* -------------------------------------------------------------
|
||||
* "x_dataframe": {
|
||||
* "type": "dataframe",
|
||||
* "value": [
|
||||
* {
|
||||
* "name": "first",
|
||||
* "value": [
|
||||
* 10,
|
||||
* 11,
|
||||
* 12
|
||||
* ],
|
||||
* "type": "vector"
|
||||
* },
|
||||
* {
|
||||
* "name": "second",
|
||||
* "value": [
|
||||
* 40,
|
||||
* 41,
|
||||
* 42
|
||||
* ],
|
||||
* "type": "vector"
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
*
|
||||
* --------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
* Run example.
|
||||
*/
|
||||
function run(config) {
|
||||
var RIn = deployr.RInput; // alias
|
||||
|
||||
// configure DeployR endpoint, login, attach, and upload a file
|
||||
deployr.configure({
|
||||
logging: true,
|
||||
host: config.endpoint,
|
||||
cors: config.cors
|
||||
});
|
||||
|
||||
deployr.script('/testuser/root/DeployR - Hello World.R')
|
||||
// ====================================================================
|
||||
// Pass [All] possible R Data Types to deployR (JavaScript --to-- R)
|
||||
// ====================================================================
|
||||
.numeric('input_numeric', 5)
|
||||
.integer('input_integer', 1)
|
||||
.logical('input_logical', true)
|
||||
.character('input_character', 'Hello')
|
||||
.date('input_date', new Date())
|
||||
.posixct('input_posixct', new Date())
|
||||
.numericVector('input_numericVector', [1.1, 2.1, 3.1, 4.1, 5.1])
|
||||
.integerVector('input_integerVector', [1, 2, 3, 4, 5])
|
||||
.logicalVector('input_logicalVector', [true, false, true, true])
|
||||
.characterVector('input_characterVector', ['Hello', 'how', 'are', 'you?'])
|
||||
.dateVector('input_dateVector', [new Date(), new Date(), new Date()])
|
||||
.posixctVector('input_posixctVector', [new Date(), new Date(), new Date()])
|
||||
.factor('input_factor', [1, 2, 3], [4, 5, 6], ['a', 'b', 'c'])
|
||||
.ordered('input_orderedfactor', [1, 2, 3], [4, 5, 6], ['a', 'b', 'c'])
|
||||
.numericMatrix('input_numericMatrix', [ [1.1, 2.1, 3.1, 4.1, 5.1] ])
|
||||
.integerMatrix('input_integerMatrix', [ [1, 2, 3, 4, 5] ])
|
||||
.logicalMatrix('input_logicalMatrix', [ [true, false, true, true] ])
|
||||
.characterMatrix('input_characterMatrix', [ ['Hello', 'how', 'are', 'you?'] ])
|
||||
.list('input_list', [
|
||||
RIn.numericVector('first', [10, 11, 12]),
|
||||
RIn.integer('input_l_integer', 1),
|
||||
RIn.logical('input_l_logical', true),
|
||||
RIn.character('input_l_character', 'Hello'),
|
||||
RIn.date('input_l_date', new Date()),
|
||||
RIn.posixct('input_l_posixct', new Date()),
|
||||
RIn.numericVector('input_l_numericVector', [1.1, 2.1, 3.1, 4.1, 5.1]),
|
||||
RIn.integerVector('input_l_integerVector', [1, 2, 3, 4, 5]),
|
||||
RIn.logicalVector('input_l_logicalVector', [true, false, true, true]),
|
||||
RIn.characterVector('input_l_characterVector', ['Hello', 'how', 'are', 'you?']),
|
||||
RIn.dateVector('input_l_dateVector', [new Date(), new Date(), new Date()]),
|
||||
RIn.posixctVector('input_posixctVector', [new Date(), new Date(), new Date()]),
|
||||
RIn.factor('input_l_factor', [1, 2, 3], [4, 5, 6], ['a', 'b', 'c']),
|
||||
RIn.ordered('input_l_orderedfactor', [1, 2, 3], [4, 5, 6], ['a', 'b', 'c']),
|
||||
RIn.numericMatrix('input_l_numericMatrix', [ [1.1, 2.1, 3.1, 4.1, 5.1] ]),
|
||||
RIn.integerMatrix('input_l_integerMatrix', [ [1, 2, 3, 4, 5] ]),
|
||||
RIn.logicalMatrix('input_l_logicalMatrix', [ [true, false, true, true] ]),
|
||||
RIn.characterMatrix('input_characterMatrix', [ ['Hello', 'how', 'are', 'you?'] ])
|
||||
])
|
||||
.dataframe('input_dataframe', [
|
||||
RIn.integer('input_df_integer', 1),
|
||||
RIn.logical('input_df_logical', true),
|
||||
RIn.character('input_df_character', 'Hello'),
|
||||
RIn.date('input_df_date', new Date()),
|
||||
RIn.posixct('input_df_posixct', new Date()),
|
||||
RIn.numericVector('input_df_numericVector', [1.1, 2.1, 3.1, 4.1, 5.1]),
|
||||
RIn.integerVector('input_df_integerVector', [1, 2, 3, 4, 5]),
|
||||
RIn.logicalVector('input_df_logicalVector', [true, false, true, true]),
|
||||
RIn.characterVector('input_df_characterVector', ['Hello', 'how', 'are', 'you?']),
|
||||
RIn.dateVector('input_df_dateVector', [new Date(), new Date(), new Date()]),
|
||||
RIn.posixctVector('input_df_posixctVector', [new Date(), new Date(), new Date()]),
|
||||
RIn.factor('input_df_factor', [1,2,3], [4,5,6], ['a', 'b' , 'c']),
|
||||
RIn.ordered('input_df_orderedfactor', [1,2,3], [4,5,6], ['a', 'b' , 'c']),
|
||||
RIn.numericMatrix('input_df_numericMatrix', [ [1.1, 2.1, 3.1, 4.1, 5.1] ]),
|
||||
RIn.integerMatrix('input_df_integerMatrix', [ [1, 2, 3, 4, 5] ]),
|
||||
RIn.logicalMatrix('input_df_logicalMatrix', [ [true, false, true, true] ]),
|
||||
RIn.characterMatrix('input_df_characterMatrix', [ ['Hello', 'how', 'are', 'you?'] ])
|
||||
])
|
||||
.error(function(err) {
|
||||
console.log(err);
|
||||
})
|
||||
.end(function(res) {
|
||||
console.log(res);
|
||||
});
|
||||
|
||||
/**********************************************************************/
|
||||
/**********************************************************************/
|
||||
/**********************************************************************/
|
||||
|
||||
/*
|
||||
* An alternative is to use `.rinputs([])` and queue them up first.
|
||||
* Both approaches are equivalent.
|
||||
*/
|
||||
var rinputs = [
|
||||
RIn.numeric('input_numeric', 5),
|
||||
RIn.logical('input_logical', true)
|
||||
];
|
||||
|
||||
deployr.script('/testuser/root/DeployR - Hello World.R')
|
||||
.rinputs(rinputs)
|
||||
.error(function(err) {
|
||||
console.log(err);
|
||||
})
|
||||
.end(function(res) {
|
||||
console.log(res);
|
||||
});
|
||||
|
||||
} // end - run
|
||||
|
||||
// -- load configuration and run example --
|
||||
$.getJSON('/examples/config.json').done(function(config) { run(config); });
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -0,0 +1,399 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/*
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* usage: $ node rinputs.js
|
||||
*
|
||||
* DeployR request to run a repository managed rscript passing all possible
|
||||
* `RInput` types.
|
||||
*
|
||||
* Supported RInputs:
|
||||
* ----------------------------------------------------------------------------
|
||||
* .numeric(name, value)
|
||||
* .logical(name, value)
|
||||
* .date(name, value)
|
||||
* .posixct(name, value)
|
||||
* .numericVector(name, value)
|
||||
* .integerVector(name, value)
|
||||
* .logicalVector(name, value)
|
||||
* .characterVector(name, value)
|
||||
* .dateVector(name, value)
|
||||
* .posixctVector(name, value)
|
||||
* .factor(name, value, levels, labels)
|
||||
* .ordered(name, value, levels, labels)
|
||||
* .numericMatrix(name, value)
|
||||
* .integerMatrix(name, value)
|
||||
* .logicalMatrix(name, value)
|
||||
* .characterMatrix(name, value)
|
||||
* .list(name, value)
|
||||
* .dataframe(name, value)
|
||||
*
|
||||
* ~~~ Examples ~~~
|
||||
*
|
||||
* -------------------------------------------------------------
|
||||
* .character('x_character', 'c')
|
||||
* -------------------------------------------------------------
|
||||
* "x_character": {
|
||||
* "type": "primitive",
|
||||
* "value": "c"
|
||||
* }
|
||||
*
|
||||
* -------------------------------------------------------------
|
||||
* .integer('x_integer', 10)
|
||||
* -------------------------------------------------------------
|
||||
* "x_integer": {
|
||||
* "type": "primitive",
|
||||
* "value": 10
|
||||
* }
|
||||
*
|
||||
* -------------------------------------------------------------
|
||||
* .numeric('x_double', 5.5)
|
||||
* -------------------------------------------------------------
|
||||
* "x_double": {
|
||||
* "type": "primitive",
|
||||
* "value": 5.5
|
||||
* }
|
||||
*
|
||||
* -------------------------------------------------------------
|
||||
* .logical('x_double', 5.5)
|
||||
* -------------------------------------------------------------
|
||||
* "x_logical": {
|
||||
* "type": "primitive",
|
||||
* "value": true
|
||||
* }
|
||||
*
|
||||
* -------------------------------------------------------------
|
||||
* .date('x_date', new Date())
|
||||
* -------------------------------------------------------------
|
||||
* "x_date": {
|
||||
* "type": "date",
|
||||
* "value": "2011-10-04",
|
||||
* "format": "yyyy-MM-dd"
|
||||
* }
|
||||
*
|
||||
* -------------------------------------------------------------
|
||||
* .posixct('x_posixct', new Date())
|
||||
* -------------------------------------------------------------
|
||||
* "x_posixct": {
|
||||
* "type": "date",
|
||||
* "value": "2011-10-05 12:13:14 -0800",
|
||||
* "format": "yyyy-MM-dd HH:mm:ss Z"
|
||||
* }
|
||||
*
|
||||
* -------------------------------------------------------------
|
||||
* .characterVector('x_character_vector', ['a', 'b', 'c'])
|
||||
* -------------------------------------------------------------
|
||||
* "x_character_vector": {
|
||||
* "type": "vector",
|
||||
* "value": [
|
||||
* "a",
|
||||
* "b",
|
||||
* "c"
|
||||
* ]
|
||||
* }
|
||||
*
|
||||
* -------------------------------------------------------------
|
||||
* .integerVector('x_integer_vector', [10, 11, 12])
|
||||
* -------------------------------------------------------------
|
||||
* "x_integer_vector": {
|
||||
* "type": "vector",
|
||||
* "value": [
|
||||
* 10,
|
||||
* 11,
|
||||
* 12
|
||||
* ]
|
||||
* }
|
||||
*
|
||||
* -------------------------------------------------------------
|
||||
* .integerVector('x_numeric_vector', [10.1, 11.1, 12.1])
|
||||
* -------------------------------------------------------------
|
||||
* "x_numeric_vector": {
|
||||
* "type": "vector",
|
||||
* "value": [
|
||||
* 10.1,
|
||||
* 11.1,
|
||||
* 12.1
|
||||
* ]
|
||||
* }
|
||||
*
|
||||
* -------------------------------------------------------------
|
||||
* .matrix('x_matrix', [ [1, 3, 12], [2, 11, 12] ])
|
||||
* -------------------------------------------------------------
|
||||
* "x_matrix": {
|
||||
* "type": "matrix",
|
||||
* "value": [
|
||||
* [
|
||||
* 1,
|
||||
* 3,
|
||||
* 12
|
||||
* ],
|
||||
* [
|
||||
* 2,
|
||||
* 11,
|
||||
* 13
|
||||
* ]
|
||||
* ]
|
||||
* }
|
||||
*
|
||||
* -------------------------------------------------------------
|
||||
* .ordered('x_ordered_factor',
|
||||
* [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
|
||||
* ['s', 't', 'a', 't', 'i', 's', 't', 'i', 'c', 's' ],
|
||||
* ['s', 't', 'a', 't', 'i', 's', 't', 'i', 'c', 's' ]
|
||||
* -------------------------------------------------------------
|
||||
* "x_ordered_factor": {
|
||||
* "type": "factor",
|
||||
* "ordered": true,
|
||||
* "value": [
|
||||
* 1,
|
||||
* 2,
|
||||
* 3,
|
||||
* 4,
|
||||
* 5,
|
||||
* 6,
|
||||
* 7,
|
||||
* 8,
|
||||
* 9,
|
||||
* 10
|
||||
* ],
|
||||
* "labels": [
|
||||
* "s",
|
||||
* "t",
|
||||
* "a",
|
||||
* "t",
|
||||
* "i",
|
||||
* "s",
|
||||
* "t",
|
||||
* "i",
|
||||
* "c",
|
||||
* "s"
|
||||
* ],
|
||||
* "levels": [
|
||||
* "s",
|
||||
* "t",
|
||||
* "a",
|
||||
* "t",
|
||||
* "i",
|
||||
* "s",
|
||||
* "t",
|
||||
* "i",
|
||||
* "c",
|
||||
* "s"
|
||||
* ]
|
||||
* }
|
||||
*
|
||||
* -------------------------------------------------------------
|
||||
* .factor('x_unordered_factor',
|
||||
* [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
|
||||
* ['s', 't', 'a', 't', 'i', 's', 't', 'i', 'c', 's' ],
|
||||
* ['s', 't', 'a', 't', 'i', 's', 't', 'i', 'c', 's' ]
|
||||
* -------------------------------------------------------------
|
||||
* "x_unordered_factor": {
|
||||
* "type": "factor",
|
||||
* "ordered": false,
|
||||
* "value": [
|
||||
* 1,
|
||||
* 2,
|
||||
* 3,
|
||||
* 4,
|
||||
* 5,
|
||||
* 6,
|
||||
* 7,
|
||||
* 8,
|
||||
* 9,
|
||||
* 10
|
||||
* ],
|
||||
* "labels": [
|
||||
* "s",
|
||||
* "t",
|
||||
* "a",
|
||||
* "t",
|
||||
* "i",
|
||||
* "s",
|
||||
* "t",
|
||||
* "i",
|
||||
* "c",
|
||||
* "s"
|
||||
* ],
|
||||
* "levels": [
|
||||
* "s",
|
||||
* "t",
|
||||
* "a",
|
||||
* "t",
|
||||
* "i",
|
||||
* "s",
|
||||
* "t",
|
||||
* "i",
|
||||
* "c",
|
||||
* "s"
|
||||
* ]
|
||||
*
|
||||
* -------------------------------------------------------------
|
||||
* .list('x_list', [
|
||||
* deplor.RInput.integerVector('first', [10, 11, 12]),
|
||||
* deplor.RInput.integerVector('second', [40, 41, 42])
|
||||
* ])
|
||||
* -------------------------------------------------------------
|
||||
* "x_list": {
|
||||
* "type": "list",
|
||||
* "value": [
|
||||
* {
|
||||
* "name": "first",
|
||||
* "value": [
|
||||
* 10,
|
||||
* 11,
|
||||
* 12
|
||||
* ],
|
||||
* "type": "vector"
|
||||
* },
|
||||
* {
|
||||
* "name": "second",
|
||||
* "value": [
|
||||
* 40,
|
||||
* 41,
|
||||
* 42
|
||||
* ],
|
||||
* "type": "vector"
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
*
|
||||
* -------------------------------------------------------------
|
||||
* .dataframe('x_dataframe', [
|
||||
* deplor.RInput.integerVector('first', [10, 11, 12]),
|
||||
* deplor.RInput.integerVector('second', [40, 41, 42])
|
||||
* ])
|
||||
* -------------------------------------------------------------
|
||||
* "x_dataframe": {
|
||||
* "type": "dataframe",
|
||||
* "value": [
|
||||
* {
|
||||
* "name": "first",
|
||||
* "value": [
|
||||
* 10,
|
||||
* 11,
|
||||
* 12
|
||||
* ],
|
||||
* "type": "vector"
|
||||
* },
|
||||
* {
|
||||
* "name": "second",
|
||||
* "value": [
|
||||
* 40,
|
||||
* 41,
|
||||
* 42
|
||||
* ],
|
||||
* "type": "vector"
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
*
|
||||
* --------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
var deployr = require('../../deployr'),
|
||||
config = require('../config'),
|
||||
RInput = deployr.RInput; // alias
|
||||
|
||||
deployr.configure( { logging: true, host: config.endpoint })
|
||||
.io('/r/repository/script/execute')
|
||||
.data({ filename : 'DeployR - Hello World.R', author: 'testuser' })
|
||||
// ==========================================================================
|
||||
// Pass [All] possible R Data Types to deployR (JavaScript --to-- R)
|
||||
// ==========================================================================
|
||||
.numeric('input_numeric', 5)
|
||||
.integer('input_integer', 1)
|
||||
.logical('input_logical', true)
|
||||
.character('input_character', 'Hello')
|
||||
.date('input_date', new Date())
|
||||
.posixct('input_posixct', new Date())
|
||||
.numericVector('input_numericVector', [1.1, 2.1, 3.1, 4.1, 5.1])
|
||||
.integerVector('input_integerVector', [1, 2, 3, 4, 5])
|
||||
.logicalVector('input_logicalVector', [true, false, true, true])
|
||||
.characterVector('input_characterVector', ['Hello', 'how', 'are', 'you?'])
|
||||
.dateVector('input_dateVector', [new Date(), new Date(), new Date()])
|
||||
.posixctVector('input_posixctVector', [new Date(), new Date(), new Date()])
|
||||
.factor('input_factor', [1,2,3], [4,5,6], ['a', 'b' , 'c'])
|
||||
.ordered('input_orderedfactor', [1,2,3], [4,5,6], ['a', 'b' , 'c'])
|
||||
.numericMatrix('input_numericMatrix', [ [1.1, 2.1, 3.1, 4.1, 5.1] ])
|
||||
.integerMatrix('input_integerMatrix', [ [1, 2, 3, 4, 5] ])
|
||||
.logicalMatrix('input_logicalMatrix', [ [true, false, true, true] ])
|
||||
.characterMatrix('input_characterMatrix', [ ['Hello', 'how', 'are', 'you?'] ])
|
||||
.list('input_list', [
|
||||
RInput.numericVector('first', [10, 11, 12]),
|
||||
RInput.integer('input_l_integer', 1),
|
||||
RInput.logical('input_l_logical', true),
|
||||
RInput.character('input_l_character', 'Hello'),
|
||||
RInput.date('input_l_date', new Date()),
|
||||
RInput.posixct('input_l_posixct', new Date()),
|
||||
RInput.numericVector('input_l_numericVector', [1.1, 2.1, 3.1, 4.1, 5.1]),
|
||||
RInput.integerVector('input_l_integerVector', [1, 2, 3, 4, 5]),
|
||||
RInput.logicalVector('input_l_logicalVector', [true, false, true, true]),
|
||||
RInput.characterVector('input_l_characterVector', ['Hello', 'how', 'are', 'you?']),
|
||||
RInput.dateVector('input_l_dateVector', [new Date(), new Date(), new Date()]),
|
||||
RInput.posixctVector('input_posixctVector', [new Date(), new Date(), new Date()]),
|
||||
RInput.factor('input_l_factor', [1,2,3], [4,5,6], ['a', 'b' , 'c']),
|
||||
RInput.ordered('input_l_orderedfactor', [1,2,3], [4,5,6], ['a', 'b' , 'c']),
|
||||
RInput.numericMatrix('input_l_numericMatrix', [ [1.1, 2.1, 3.1, 4.1, 5.1] ]),
|
||||
RInput.integerMatrix('input_l_integerMatrix', [ [1, 2, 3, 4, 5] ]),
|
||||
RInput.logicalMatrix('input_l_logicalMatrix', [ [true, false, true, true] ]),
|
||||
RInput.characterMatrix('input_characterMatrix', [ ['Hello', 'how', 'are', 'you?'] ])
|
||||
])
|
||||
.dataframe('input_dataframe', [
|
||||
RInput.integer('input_df_integer', 1),
|
||||
RInput.logical('input_df_logical', true),
|
||||
RInput.character('input_df_character', 'Hello'),
|
||||
RInput.date('input_df_date', new Date()),
|
||||
RInput.posixct('input_df_posixct', new Date()),
|
||||
RInput.numericVector('input_df_numericVector', [1.1, 2.1, 3.1, 4.1, 5.1]),
|
||||
RInput.integerVector('input_df_integerVector', [1, 2, 3, 4, 5]),
|
||||
RInput.logicalVector('input_df_logicalVector', [true, false, true, true]),
|
||||
RInput.characterVector('input_df_characterVector', ['Hello', 'how', 'are', 'you?']),
|
||||
RInput.dateVector('input_df_dateVector', [new Date(), new Date(), new Date()]),
|
||||
RInput.posixctVector('input_df_posixctVector', [new Date(), new Date(), new Date()]),
|
||||
RInput.factor('input_df_factor', [1,2,3], [4,5,6], ['a', 'b' , 'c']),
|
||||
RInput.ordered('input_df_orderedfactor', [1,2,3], [4,5,6], ['a', 'b' , 'c']),
|
||||
RInput.numericMatrix('input_df_numericMatrix', [ [1.1, 2.1, 3.1, 4.1, 5.1] ]),
|
||||
RInput.integerMatrix('input_df_integerMatrix', [ [1, 2, 3, 4, 5] ]),
|
||||
RInput.logicalMatrix('input_df_logicalMatrix', [ [true, false, true, true] ]),
|
||||
RInput.characterMatrix('input_df_characterMatrix', [ ['Hello', 'how', 'are', 'you?'] ])
|
||||
])
|
||||
.error(function(err) {
|
||||
console.log(err);
|
||||
})
|
||||
.end(function(res, chain) {
|
||||
console.log(res);
|
||||
});
|
||||
|
||||
/*****************************************************************************/
|
||||
/*****************************************************************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
/*
|
||||
* An alternative is to use `.rinputs([])` and queue them up first. Both
|
||||
* approaches are equivalent.
|
||||
*/
|
||||
var rinputs = [
|
||||
RInput.numeric('input_numeric', 5),
|
||||
RInput.logical('input_logical', true)
|
||||
];
|
||||
|
||||
deployr.io('/r/repository/script/execute')
|
||||
.data({ filename : 'DeployR - Hello World.R', author: 'testuser' })
|
||||
.rinputs(rinputs)
|
||||
.error(function(err) {
|
||||
console.log(err);
|
||||
})
|
||||
.end(function(res, chain) {
|
||||
console.log(res);
|
||||
});
|
|
@ -0,0 +1,51 @@
|
|||
State,ExpPerPupil,PupilTchrRatio,TchrSalary,PctSAT,VerbalSAT,MathSAT,AveSAT
|
||||
Alabama,4.405,17.2,31.144,8,491,538,1029
|
||||
Alaska,8.963,17.6,47.951,47,445,489,934
|
||||
Arizona,4.778,19.3,32.175,27,448,496,944
|
||||
Arkansas,4.459,17.1,28.934,6,482,523,1005
|
||||
California,4.992,24,41.078,45,417,485,902
|
||||
Colorado,5.443,18.4,34.571,29,462,518,980
|
||||
Connecticut,8.817,14.4,50.045,81,431,477,908
|
||||
Delaware,7.03,16.6,39.076,68,429,468,897
|
||||
Florida,5.718,19.1,32.588,48,420,469,889
|
||||
Georgia,5.193,16.3,32.291,65,406,448,854
|
||||
Hawaii,6.078,17.9,38.518,57,407,482,889
|
||||
Idaho,4.21,19.1,29.783,15,468,511,979
|
||||
Illinois,6.136,17.3,39.431,13,488,560,1048
|
||||
Indiana,5.826,17.5,36.785,58,415,467,882
|
||||
Iowa,5.483,15.8,31.511,5,516,583,1099
|
||||
Kansas,5.817,15.1,34.652,9,503,557,1060
|
||||
Kentucky,5.217,17,32.257,11,477,522,999
|
||||
Louisiana,4.761,16.8,26.461,9,486,535,1021
|
||||
Maine,6.428,13.8,31.972,68,427,469,896
|
||||
Maryland,7.245,17,40.661,64,430,479,909
|
||||
Massachusetts,7.287,14.8,40.795,80,430,477,907
|
||||
Michigan,6.994,20.1,41.895,11,484,549,1033
|
||||
Minnesota,6,17.5,35.948,9,506,579,1085
|
||||
Mississippi,4.08,17.5,26.818,4,496,540,1036
|
||||
Missouri,5.383,15.5,31.189,9,495,550,1045
|
||||
Montana,5.692,16.3,28.785,21,473,536,1009
|
||||
Nebraska,5.935,14.5,30.922,9,494,556,1050
|
||||
Nevada,5.16,18.7,34.836,30,434,483,917
|
||||
New Hampshire,5.859,15.6,34.72,70,444,491,935
|
||||
New Jersey,9.774,13.8,46.087,70,420,478,898
|
||||
New Mexico,4.586,17.2,28.493,11,485,530,1015
|
||||
New York,9.623,15.2,47.612,74,419,473,892
|
||||
North Carolina,5.077,16.2,30.793,60,411,454,865
|
||||
North Dakota,4.775,15.3,26.327,5,515,592,1107
|
||||
Ohio,6.162,16.6,36.802,23,460,515,975
|
||||
Oklahoma,4.845,15.5,28.172,9,491,536,1027
|
||||
Oregon,6.436,19.9,38.555,51,448,499,947
|
||||
Pennsylvania,7.109,17.1,44.51,70,419,461,880
|
||||
Rhode Island,7.469,14.7,40.729,70,425,463,888
|
||||
South Carolina,4.797,16.4,30.279,58,401,443,844
|
||||
South Dakota,4.775,14.4,25.994,5,505,563,1068
|
||||
Tennessee,4.388,18.6,32.477,12,497,543,1040
|
||||
Texas,5.222,15.7,31.223,47,419,474,893
|
||||
Utah,3.656,24.3,29.082,4,513,563,1076
|
||||
Vermont,6.75,13.8,35.406,68,429,472,901
|
||||
Virginia,5.327,14.6,33.987,65,428,468,896
|
||||
Washington,5.906,20.2,36.151,48,443,494,937
|
||||
West Virginia,6.107,14.8,31.944,17,448,484,932
|
||||
Wisconsin,6.93,15.9,37.746,9,501,572,1073
|
||||
Wyoming,6.16,14.9,31.285,10,476,525,1001
|
|
|
@ -0,0 +1,82 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/*
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* usage: $ node sugar.js
|
||||
*
|
||||
* Make DeployR "sweeter" for human use using the `script` and `auth` sugar
|
||||
* methods.
|
||||
*/
|
||||
|
||||
var util = require('util'),
|
||||
deployr = require('../../deployr'),
|
||||
config = require('../config'),
|
||||
credentials = config.credentials;
|
||||
|
||||
/*
|
||||
* stdout helper to print a string representation of object for the example.
|
||||
*/
|
||||
var printf = function(property, obj) {
|
||||
console.log('========================');
|
||||
console.log(property);
|
||||
console.log('========================');
|
||||
console.log(util.inspect(obj, false, null, true));
|
||||
console.log('\n\n');
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Set the DeployR server endpoint URL
|
||||
// ============================================================================
|
||||
|
||||
deployr.configure({ host: config.endpoint, logging: false });
|
||||
|
||||
// ============================================================================
|
||||
// Executes repository-managed scripts on an Anonymous Project.
|
||||
// ============================================================================
|
||||
|
||||
deployr.script('/testuser/root/DeployR - Hello World.R')
|
||||
.numeric('input_randomNum', 10)
|
||||
.end(function(res) {
|
||||
printf('console', res.get('console')); // stdout
|
||||
});
|
||||
|
||||
// ============================================================================
|
||||
// Executes repository-managed scripts on the R session.
|
||||
// @NOTE:
|
||||
//
|
||||
// `.script( { project: true } ...)` will implicitly create a temporary project
|
||||
// and use it for the script execution
|
||||
// ============================================================================
|
||||
|
||||
var project = null; // project-id used to close project at the end
|
||||
|
||||
// If you had a valid ProjectID here you could use it. Since we do not we can
|
||||
// pass in `true` and a temp project will be created as a convenience.
|
||||
var isProject = true;
|
||||
|
||||
// login
|
||||
var ruser = deployr.auth(credentials.username, credentials.password);
|
||||
|
||||
// Executes repository-managed scripts on the R session.
|
||||
ruser.script('/testuser/root/DeployR - Hello World.R', isProject)
|
||||
.numeric('input_randomNum', 10)
|
||||
.end(function(res) {
|
||||
project = res.get('project').project; // save project so we can close later
|
||||
|
||||
// stdout
|
||||
printf('console', res.get('console'));
|
||||
printf('artifacts', res.get('artifacts'));
|
||||
})
|
||||
.ensure(function() {
|
||||
ruser.release(project);
|
||||
});
|
|
@ -0,0 +1,91 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<META name="copyright" content="Copyright (C) 2010-2014 by Revolution Analytics Inc.">
|
||||
<title>Example File Upload</title>
|
||||
<script src="../../../../browser/deployr.min.js"></script>
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Example File Upload</h1>
|
||||
<hr>
|
||||
<ol>
|
||||
<li>Populate <strong>/examples/config.json</strong> with the proper values before running.</li>
|
||||
<li>Choose a file to upload.</li>
|
||||
<li>Click the `upload` button.</li>
|
||||
<li>Open the browser's debug window to view print logs for this example.</li>
|
||||
<li>View <a href="http://deployr.revolutionanalytics.com/documents/dev/client-jsdoc/">documentation</a> for more information.</li>
|
||||
</ol>
|
||||
|
||||
<form>
|
||||
<input id="the-file" name="file" type="file">
|
||||
</form>
|
||||
<p>
|
||||
<button onclick="upload()">Upload</button>
|
||||
</p>
|
||||
|
||||
<script>
|
||||
/*
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* usage: http://localhost:8080/examples/js-api/response.html
|
||||
*
|
||||
* Example inspecting and printing a DeployR `/r/repository/script/execute`
|
||||
* response using the `.get(key)` helper for easy response property
|
||||
* lookup.
|
||||
* ----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
* Run example.
|
||||
*/
|
||||
var config = {};
|
||||
|
||||
function upload() {
|
||||
// HTML5 File Object
|
||||
var file = document.getElementById('the-file').files[0];
|
||||
|
||||
// configure DeployR endpoint, login, attach, and upload a file
|
||||
deployr.configure({
|
||||
logging: true,
|
||||
host: config.endpoint,
|
||||
cors: config.cors
|
||||
})
|
||||
.io('/r/user/login')
|
||||
.data(config.credentials)
|
||||
.end(function(res) {
|
||||
// do something with the response
|
||||
})
|
||||
.io('/r/repository/file/upload')
|
||||
.data({ filename: 'SampleFileName', descr: 'Sample file upload.' })
|
||||
.attach(file)
|
||||
.error(function(err) {
|
||||
// do something with the error
|
||||
})
|
||||
.end(function(res, chain) {
|
||||
// do something with the response
|
||||
console.log(res);
|
||||
});
|
||||
}
|
||||
|
||||
// -- load configuration and run example --
|
||||
$.getJSON('/examples/config.json').done(function(c) {
|
||||
config = c;
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -0,0 +1,38 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/*
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* usage: $ node upload.js
|
||||
*
|
||||
* Simple file upload using `.attach(/path/to/file)`
|
||||
*
|
||||
*/
|
||||
var path = require('path'),
|
||||
config = require('../config'),
|
||||
credentials = config.credentials,
|
||||
deployr = require('../../deployr').configure( { host: config.endpoint });
|
||||
|
||||
var ruser = deployr.auth(credentials.username, credentials.password);
|
||||
|
||||
ruser.io('/r/repository/file/upload')
|
||||
.data({ filename: 'nodejs-satscores.csv', descr: 'Sample file upload.' })
|
||||
.attach(path.join(__dirname, 'satscores.csv'))
|
||||
.error(function(err) {
|
||||
console.log(err);
|
||||
})
|
||||
.end(function(res, chain) {
|
||||
console.log(res);
|
||||
})
|
||||
.ensure(function() {
|
||||
ruser.release();
|
||||
});
|
|
@ -0,0 +1,80 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title>Authenticate</title>
|
||||
<script src="../../../browser/deployr.js"></script>
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Authentication</h1>
|
||||
<hr>
|
||||
<ol>
|
||||
<li>Populate <strong>/examples/config.json</strong> with the proper values before running.</li>
|
||||
<li>Open the browser's debug window to view print logs for this example.</li>
|
||||
<li>View <a href="http://deployr.revolutionanalytics.com/documents/dev/client-jsdoc/">documentation</a> for more information.</li>
|
||||
</ol>
|
||||
|
||||
<script>
|
||||
|
||||
/*
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/* --------------------------------------------------------------------
|
||||
* usage: http://localhost:8080/examples/tutorial/authentication/authenticate.html
|
||||
* see: http://deployr.revolutionanalytics.com/documents/dev/api-doc/guide/workingusers.html
|
||||
*
|
||||
* 1. Determine DeployR server endpoint.
|
||||
* 2. Establish an authenticated handle with the DeployR server.
|
||||
* 3. Release connection before application exits.
|
||||
* --------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
* Run example.
|
||||
*/
|
||||
function run(config) {
|
||||
deployr.configure( {
|
||||
logging: false,
|
||||
host: config.endpoint,
|
||||
cors: config.cors
|
||||
});
|
||||
|
||||
/*
|
||||
* Run example.
|
||||
* @NOTE - Remember the`.end()` will send the request for `/r/user/login`
|
||||
* If `.end()` is never called the request will not be sent.
|
||||
*/
|
||||
var ruser = deployr.io('/r/user/login');
|
||||
|
||||
ruser.data(config.credentials)
|
||||
.error(function(err) {
|
||||
console.warn('Authenticate: ex=' + err.get('error'));
|
||||
})
|
||||
.end(function(res) {
|
||||
console.log('Authenticate: established authenticated connection, rUser='
|
||||
+ res.get('user').username);
|
||||
})
|
||||
.ensure(function() {
|
||||
/*
|
||||
* Release connection before application exits.
|
||||
*/
|
||||
ruser.release();
|
||||
});
|
||||
}
|
||||
|
||||
// -- load configuration and run example --
|
||||
$.getJSON('/examples/config.json').done(function(config) { run(config); });
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,52 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/*
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* usage: $ node authenticate.js
|
||||
* see: http://deployr.revolutionanalytics.com/documents/dev/api-doc/guide/workingusers.html
|
||||
*
|
||||
* 1. Determine DeployR server endpoint.
|
||||
* 2. Establish an authenticated handle with the DeployR server.
|
||||
* 3. Release connection before application exits.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
var deployr = require('../../../deployr'),
|
||||
config = require('../../config'),
|
||||
ruser = null; // The user resquest session
|
||||
|
||||
deployr.configure( { logging: false, host: config.endpoint });
|
||||
|
||||
/*
|
||||
* Run example.
|
||||
* @NOTE - Remember the`.end()` will send the request for `/ruser/login`
|
||||
* If `.end()` is never called the request will not be sent.
|
||||
*/
|
||||
|
||||
ruser = deployr.io('/r/user/login');
|
||||
|
||||
ruser.data(config.credentials)
|
||||
.error(function(err) {
|
||||
console.warn('Authenticate: ex=' + err.get('error'));
|
||||
})
|
||||
.end(function(res) {
|
||||
console.log('Authenticate: established authenticated connection, rUser='
|
||||
+ res.get('user').username);
|
||||
})
|
||||
.ensure(function() {
|
||||
/*
|
||||
* Release connection and logout before application exits.
|
||||
*/
|
||||
ruser.release();
|
||||
});
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title>Connection</title>
|
||||
<script src="../../../browser/deployr.js"></script>
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Connection</h1>
|
||||
<hr>
|
||||
<ol>
|
||||
<li>Populate <strong>/examples/config.json</strong> with the proper values before running.</li>
|
||||
<li>Open the browser's debug window to view print logs for this example.</li>
|
||||
<li>View <a href="http://deployr.revolutionanalytics.com/documents/dev/client-jsdoc/">documentation</a> for more information.</li>
|
||||
</ol>
|
||||
|
||||
<script>
|
||||
|
||||
/*
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/* --------------------------------------------------------------------
|
||||
* usage: http://localhost:8080/examples/tutorial/connection/connection.html
|
||||
*
|
||||
* 1. Determine DeployR server endpoint.
|
||||
* --------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
* Run example.
|
||||
*/
|
||||
function run(config) {
|
||||
console.log('Connect: using endpoint=' + config.endpoint);
|
||||
deployr.configure( { host: config.endpoint } );
|
||||
}
|
||||
|
||||
// -- load configuration and run example --
|
||||
$.getJSON('/examples/config.json').done(function(config) { run(config); });
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,28 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/*
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* usage: $ node connection.js
|
||||
*
|
||||
* 1. Determine DeployR server endpoint.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
var deployr = require('../../../deployr'),
|
||||
config = require('../../config');
|
||||
|
||||
/*
|
||||
* Run example.
|
||||
*/
|
||||
console.log('Connect: using endpoint=' + config.endpoint);
|
||||
deployr.configure( { host: config.endpoint } );
|
|
@ -0,0 +1,127 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title>Background Job (code)</title>
|
||||
<script src="../../../../browser/deployr.js"></script>
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Background Job (code)</h1>
|
||||
<hr>
|
||||
<ol>
|
||||
<li>Populate <strong>/examples/config.json</strong> with the proper values before running.</li>
|
||||
<li>Open the browser's debug window to view print logs for this example.</li>
|
||||
<li>View <a href="http://deployr.revolutionanalytics.com/documents/dev/client-jsdoc/">documentation</a> for more information.</li>
|
||||
</ol>
|
||||
|
||||
<script>
|
||||
/*
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* usage: http://localhost:8080/examples/tutorial/services/background/auth-job-execute-code.html
|
||||
* see: http://deployr.revolutionanalytics.com/documents/dev/api-doc/guide/workingjobs.html#jobsubmit
|
||||
*
|
||||
* 1. Determine DeployR server endpoint.
|
||||
* 2. Establish an authenticated handle with the DeployR server.
|
||||
* 3. Submit a background job to execute an arbitrary block of R code.
|
||||
* 4. Query for the job status every 2 seconds for `Completed` status.
|
||||
* 5. On status `Completed` retrieve results of the background job execution.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
var jobPending = true, // R job status
|
||||
intervalId = null, // ID value of the timer that will be set
|
||||
ruser = null; // The user resquest session
|
||||
|
||||
/*
|
||||
* This helper queries the job status for a `Completed` state.
|
||||
*/
|
||||
function query(job) {
|
||||
ruser.io('/r/job/query')
|
||||
.data({ job: job })
|
||||
.end(function(res) {
|
||||
console.log('Job Status=' + res.get('status') + ' rJob=' + job);
|
||||
|
||||
jobPending = res.get('status') !== 'Completed';
|
||||
|
||||
if (!jobPending) {
|
||||
console.log('AuthJobExecuteCode: retrieved background ' +
|
||||
'job result on project, rJob=' + res.get('job').job);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* Run example.
|
||||
*/
|
||||
function run(config) {
|
||||
|
||||
/*
|
||||
* Configure the DeployR server endpoint and subscribe to all errors
|
||||
* at a global level.
|
||||
*/
|
||||
deployr.configure({
|
||||
logging: false,
|
||||
host: config.endpoint,
|
||||
cors: config.cors,
|
||||
events: {
|
||||
error: function(api, err) {
|
||||
jobPending = false;
|
||||
console.warn('AuthJobExecuteCode: ex=' + err.get('error'));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* Run example.
|
||||
*/
|
||||
ruser = deployr.io('/r/user/login')
|
||||
.data(config.credentials)
|
||||
.end(function(res) {
|
||||
console.log('Authenticate: established authenticated connection, rUser=' +
|
||||
res.get('user').username);
|
||||
})
|
||||
.io('/r/job/submit')
|
||||
.data({
|
||||
priority: 'medium',
|
||||
name: 'Background Code Execution',
|
||||
descr: 'Background code execution.',
|
||||
code: 'demo(graphics)'
|
||||
})
|
||||
.end(function(res) {
|
||||
var job = res.get('job').job;
|
||||
console.log('AuthJobExecuteCode: submitted background job ' +
|
||||
'for execution, rJob=' + job);
|
||||
|
||||
// query job status every 2 seconds
|
||||
intervalId = setInterval(function() {
|
||||
if (jobPending) {
|
||||
query(job);
|
||||
} else {
|
||||
clearInterval(intervalId);
|
||||
ruser.release();
|
||||
}
|
||||
}, 2000);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
// -- load configuration and run example --
|
||||
$.getJSON('/examples/config.json').done(function(config) { run(config); });
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -0,0 +1,95 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/*
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* usage: $ node auth-job-execute-code.js
|
||||
* see: http://deployr.revolutionanalytics.com/documents/dev/api-doc/guide/workingjobs.html#jobsubmit
|
||||
*
|
||||
* 1. Determine DeployR server endpoint.
|
||||
* 2. Establish an authenticated handle with the DeployR server.
|
||||
* 3. Submit a background job to execute an arbitrary block of R code.
|
||||
* 4. Query for the job status every 2 seconds for `Completed` status.
|
||||
* 5. On status `Completed` retrieve results of the background job execution.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
var deployr = require('../../../../deployr'),
|
||||
config = require('../../../config'),
|
||||
jobPending = true, // R job status
|
||||
intervalId = null, // ID value of the timer that will be set
|
||||
ruser = null; // The user resquest session
|
||||
|
||||
/*
|
||||
* This helper queries the job status for a `Completed` state.
|
||||
*/
|
||||
function query(job) {
|
||||
ruser.io('/r/job/query')
|
||||
.data({ job: job })
|
||||
.end(function(res) {
|
||||
console.log('Job Status=' + res.get('status') + ' rJob=' + job);
|
||||
|
||||
jobPending = res.get('status') !== 'Completed';
|
||||
|
||||
if (!jobPending) {
|
||||
console.log('AuthJobExecuteCode: retrieved background ' +
|
||||
'job result on project, rJob=' + res.get('job').job);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* Configure the DeployR server endpoint and subscribe to all errors at a global
|
||||
* level.
|
||||
*/
|
||||
deployr.configure( {
|
||||
logging: false,
|
||||
host: config.endpoint,
|
||||
events: {
|
||||
error: function(api, err) {
|
||||
jobPending = false;
|
||||
console.warn('AuthJobExecuteCode: ex=' + err.get('error'));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* Run example.
|
||||
*/
|
||||
ruser = deployr.io('/r/user/login')
|
||||
.data(config.credentials)
|
||||
.end(function(res) {
|
||||
console.log('Authenticate: established authenticated connection, rUser='
|
||||
+ res.get('user').username);
|
||||
})
|
||||
.io('/r/job/submit')
|
||||
.data({
|
||||
priority: 'medium',
|
||||
name: 'Background Code Execution',
|
||||
descr: 'Background code execution.',
|
||||
code: 'demo(graphics)'
|
||||
})
|
||||
.end(function(res) {
|
||||
var job = res.get('job').job;
|
||||
console.log('AuthJobExecuteCode: submitted background job ' +
|
||||
'for execution, rJob=' + job);
|
||||
|
||||
// query job status every 2 seconds
|
||||
intervalId = setInterval(function() {
|
||||
if (jobPending) {
|
||||
query(job);
|
||||
} else {
|
||||
clearInterval(intervalId);
|
||||
ruser.release();
|
||||
}
|
||||
}, 2000);
|
||||
});
|
|
@ -0,0 +1,128 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title>Background Job (script)</title>
|
||||
<script src="../../../../browser/deployr.js"></script>
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Background Job (script)</h1>
|
||||
<hr>
|
||||
<ol>
|
||||
<li>Populate <strong>/examples/config.json</strong> with the proper values before running.</li>
|
||||
<li>Open the browser's debug window to view print logs for this example.</li>
|
||||
<li>View <a href="http://deployr.revolutionanalytics.com/documents/dev/client-jsdoc/">documentation</a> for more information.</li>
|
||||
</ol>
|
||||
|
||||
<script>
|
||||
/*
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* usage: http://localhost:8080/examples/tutorial/services/background/auth-job-execute-script.html
|
||||
* see: http://deployr.revolutionanalytics.com/documents/dev/api-doc/guide/workingjobs.html#jobsubmit
|
||||
*
|
||||
* 1. Determine DeployR server endpoint.
|
||||
* 2. Establish an authenticated handle with the DeployR server.
|
||||
* 3. Submit a background job to execute a repository-managed script:
|
||||
* `/testuser/root/Histogram of Auto Sales.R`
|
||||
* 4. Query for the job status every 2 seconds for `Completed` status.
|
||||
* 5. On status `Completed` retrieve results of the background job execution.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
var jobPending = true, // R job status
|
||||
intervalId = null, // ID value of the timer that will be set
|
||||
ruser = null; // The user resquest session
|
||||
|
||||
/*
|
||||
* This helper queries the job status for a `Completed` state.
|
||||
*/
|
||||
function query(job) {
|
||||
ruser.io('/r/job/query')
|
||||
.data({ job: job })
|
||||
.end(function(res) {
|
||||
console.log('Job Status=' + res.get('status') + ' rJob=' + job);
|
||||
|
||||
jobPending = res.get('status') !== 'Completed';
|
||||
|
||||
if (!jobPending) {
|
||||
console.log('AuthJobExecuteScript: retrieved background ' +
|
||||
'job result on project, rJob=' + res.get('job').job);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* Run example.
|
||||
*/
|
||||
function run(config) {
|
||||
|
||||
/*
|
||||
* Configure the DeployR server endpoint and subscribe to all errors at a global
|
||||
* level.
|
||||
*/
|
||||
deployr.configure({
|
||||
logging: false,
|
||||
host: config.endpoint,
|
||||
cors: config.cors,
|
||||
events: {
|
||||
error: function(api, err) {
|
||||
jobPending = false;
|
||||
console.warn('AuthJobExecuteScript: ex=' + err.get('error'));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* Run example.
|
||||
*/
|
||||
ruser = deployr.io('/r/user/login')
|
||||
.data(config.credentials)
|
||||
.end(function(res) {
|
||||
console.log('Authenticate: established authenticated connection, rUser='
|
||||
+ res.get('user').username);
|
||||
})
|
||||
.io('/r/job/submit')
|
||||
.data({
|
||||
name: 'Background Script Execution',
|
||||
descr: 'Background script execution.',
|
||||
rscriptname: 'Histogram of Auto Sales',
|
||||
rscriptdirectory: 'root',
|
||||
rscriptauthor: 'testuser',
|
||||
priority: 'high'
|
||||
})
|
||||
.end(function(res) {
|
||||
var job = res.get('job').job;
|
||||
console.log('AuthJobExecuteScript: submitted background job ' +
|
||||
'for execution, rJob=' + job);
|
||||
|
||||
// query job status every 2 seconds
|
||||
intervalId = setInterval(function() {
|
||||
if (jobPending) {
|
||||
query(job);
|
||||
} else {
|
||||
clearInterval(intervalId);
|
||||
ruser.release();
|
||||
}
|
||||
}, 2000);
|
||||
});
|
||||
}
|
||||
|
||||
// -- load configuration and run example --
|
||||
$.getJSON('/examples/config.json').done(function(config) { run(config); });
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -0,0 +1,98 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/*
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* usage: $ node auth-job-execute-script.js
|
||||
* see: http://deployr.revolutionanalytics.com/documents/dev/api-doc/guide/workingjobs.html#jobsubmit
|
||||
*
|
||||
* 1. Determine DeployR server endpoint.
|
||||
* 2. Establish an authenticated handle with the DeployR server.
|
||||
* 3. Submit a background job to execute a repository-managed script:
|
||||
* `/testuser/root/Histogram of Auto Sales.R`
|
||||
* 4. Query for the job status every 2 seconds for `Completed` status.
|
||||
* 5. On status `Completed` retrieve results of the background job execution.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
var deployr = require('../../../../deployr'),
|
||||
config = require('../../../config'),
|
||||
jobPending = true, // R job status
|
||||
intervalId = null, // ID value of the timer that will be set
|
||||
ruser = null; // The user resquest session
|
||||
|
||||
/*
|
||||
* This helper queries the job status for a `Completed` state.
|
||||
*/
|
||||
function query(job) {
|
||||
ruser.io('/r/job/query')
|
||||
.data({ job: job })
|
||||
.end(function(res) {
|
||||
console.log('Job Status=' + res.get('status') + ' rJob=' + job);
|
||||
|
||||
jobPending = res.get('status') !== 'Completed';
|
||||
|
||||
if (!jobPending) {
|
||||
console.log('AuthJobExecuteScript: retrieved background ' +
|
||||
'job result on project, rJob=' + res.get('job').job);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* Configure the DeployR server endpoint and subscribe to all errors at a global
|
||||
* level.
|
||||
*/
|
||||
deployr.configure( {
|
||||
logging: false,
|
||||
host: config.endpoint,
|
||||
events: {
|
||||
error: function(api, err) {
|
||||
jobPending = false;
|
||||
console.warn('AuthJobExecuteScript: ex=' + err.get('error'));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* Run example.
|
||||
*/
|
||||
ruser = deployr.io('/r/user/login')
|
||||
.data(config.credentials)
|
||||
.end(function(res) {
|
||||
console.log('Authenticate: established authenticated connection, rUser='
|
||||
+ res.get('user').username);
|
||||
})
|
||||
.io('/r/job/submit')
|
||||
.data({
|
||||
name: 'Background Script Execution',
|
||||
descr: 'Background script execution.',
|
||||
rscriptname: 'Histogram of Auto Sales',
|
||||
rscriptdirectory: 'root',
|
||||
rscriptauthor: 'testuser',
|
||||
priority: 'high'
|
||||
})
|
||||
.end(function(res) {
|
||||
var job = res.get('job').job;
|
||||
console.log('AuthJobExecuteScript: submitted background job ' +
|
||||
'for execution, rJob=' + job);
|
||||
|
||||
// query job status every 2 seconds
|
||||
intervalId = setInterval(function() {
|
||||
if (jobPending) {
|
||||
query(job);
|
||||
} else {
|
||||
clearInterval(intervalId);
|
||||
ruser.release();
|
||||
}
|
||||
}, 2000);
|
||||
});
|
|
@ -0,0 +1,108 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title>Anonymous Project Execute (script)</title>
|
||||
<script src="../../../../browser/deployr.js"></script>
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Anonymous Project Execute (script)</h1>
|
||||
<hr>
|
||||
<ol>
|
||||
<li>Populate <strong>/examples/config.json</strong> with the proper values before running.</li>
|
||||
<li>Open the browser's debug window to view print logs for this example.</li>
|
||||
<li>View <a href="http://deployr.revolutionanalytics.com/documents/dev/client-jsdoc/">documentation</a> for more information.</li>
|
||||
</ol>
|
||||
|
||||
<script>
|
||||
/*
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* usage: http://localhost:8080/examples/tutorial/services/project/anon-project-execute-script.html
|
||||
* see: http://deployr.revolutionanalytics.com/documents/dev/api-doc/guide/workingrepository.html
|
||||
*
|
||||
* 1. Determine DeployR server endpoint.
|
||||
* 2. Establish an authenticated handle with the DeployR server.
|
||||
* 3. Execute a public analytics Web service as an anonymous user based on a
|
||||
* repository-managed R script: `/testuser/root/Histogram of Auto Sales.R`
|
||||
* 4. Retrieve script execution results.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
* Run example.
|
||||
*/
|
||||
function run(config) {
|
||||
var ruser = null; // The user resquest session
|
||||
|
||||
/*
|
||||
* Configure the DeployR server endpoint and subscribe to all errors at a global
|
||||
* level.
|
||||
*/
|
||||
deployr.configure({
|
||||
logging: false,
|
||||
host: config.endpoint,
|
||||
cors: config.cors,
|
||||
events: {
|
||||
error: function(api, err) {
|
||||
console.warn('AnonProjectExecuteScript: ex=' + err.get('error'));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* Run example.
|
||||
* @NOTE - Remember the`.end()` will send the request for `/r/user/login`
|
||||
* If `.end()` is never called the request will not be sent.
|
||||
*/
|
||||
ruser = deployr.io('/r/user/login');
|
||||
|
||||
ruser.data(config.credentials)
|
||||
.end(function(res) {
|
||||
console.log('AnonProjectExecuteScript: established authenticated ' +
|
||||
'connection, rUser=' + res.get('user').username);
|
||||
})
|
||||
// =========================================================================
|
||||
.script('/testuser/root/Histogram of Auto Sales.R')
|
||||
.end(function(res) {
|
||||
var exec = res.get('execution').execution;
|
||||
console.log('AnonProjectExecuteScript: public repository-managed ' +
|
||||
'script execution completed, rScriptExecution=' + exec);
|
||||
|
||||
/*
|
||||
* Retrieve script execution results.
|
||||
*/
|
||||
var rconsole = res.get('console');
|
||||
var plots = res.get('results');
|
||||
var files = res.get('artifacts');
|
||||
var objects = res.workspace(); // --or-- res.get('workspace').objects;
|
||||
})
|
||||
// =========================================================================
|
||||
.ensure(function() {
|
||||
/*
|
||||
* Release connection before application exits.
|
||||
*/
|
||||
ruser.release();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// -- load configuration and run example --
|
||||
$.getJSON('/examples/config.json').done(function(config) { run(config); });
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -0,0 +1,77 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/*
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* usage: $ node anon-project-execute-script.js
|
||||
* see: http://deployr.revolutionanalytics.com/documents/dev/api-doc/guide/workingrepository.html
|
||||
*
|
||||
* 1. Determine DeployR server endpoint.
|
||||
* 2. Establish an authenticated handle with the DeployR server.
|
||||
* 3. Execute a public analytics Web service as an anonymous user based on a
|
||||
* repository-managed R script: `/testuser/root/Histogram of Auto Sales.R`
|
||||
* 4. Retrieve script execution results.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
var deployr = require('../../../../deployr'),
|
||||
config = require('../../../config'),
|
||||
ruser = null; // The user resquest session
|
||||
|
||||
/*
|
||||
* Configure the DeployR server endpoint and subscribe to all errors at a global
|
||||
* level.
|
||||
*/
|
||||
deployr.configure( {
|
||||
logging: false,
|
||||
host: config.endpoint,
|
||||
events: {
|
||||
error: function(api, err) {
|
||||
console.warn('AnonProjectExecuteScript: ex=' + err.get('error'));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* Run example.
|
||||
* @NOTE - Remember the`.end()` will send the request for `/r/user/login`
|
||||
* If `.end()` is never called the request will not be sent.
|
||||
*/
|
||||
ruser = deployr.io('/r/user/login');
|
||||
|
||||
ruser.data(config.credentials)
|
||||
.end(function(res) {
|
||||
console.log('AnonProjectExecuteScript: established authenticated ' +
|
||||
'connection, rUser=' + res.get('user').username);
|
||||
})
|
||||
// =========================================================================
|
||||
.script('/testuser/root/Histogram of Auto Sales.R')
|
||||
.end(function(res) {
|
||||
var exec = res.get('execution').execution;
|
||||
console.log('AnonProjectExecuteScript: public repository-managed ' +
|
||||
'script execution completed, rScriptExecution=' + exec);
|
||||
|
||||
/*
|
||||
* Retrieve script execution results.
|
||||
*/
|
||||
var rconsole = res.get('console');
|
||||
var plots = res.get('results');
|
||||
var files = res.get('artifacts');
|
||||
var objects = res.workspace(); // --or-- res.get('workspace').objects;
|
||||
})
|
||||
// =========================================================================
|
||||
.ensure(function() {
|
||||
/*
|
||||
* Release connection before application exits.
|
||||
*/
|
||||
ruser.release();
|
||||
});
|
|
@ -0,0 +1,99 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title>Project Create</title>
|
||||
<script src="../../../../browser/deployr.js"></script>
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Project Create</h1>
|
||||
<hr>
|
||||
<ol>
|
||||
<li>Populate <strong>/examples/config.json</strong> with the proper values before running.</li>
|
||||
<li>Open the browser's debug window to view print logs for this example.</li>
|
||||
<li>View <a href="http://deployr.revolutionanalytics.com/documents/dev/client-jsdoc/">documentation</a> for more information.</li>
|
||||
</ol>
|
||||
|
||||
<script>
|
||||
/*
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* usage: http://localhost:8080/examples/tutorial/services/project/auth-project-create.html
|
||||
* see: http://deployr.revolutionanalytics.com/documents/dev/api-doc/guide/workingprojects.html#projectcreate
|
||||
*
|
||||
* 1. Determine DeployR server endpoint.
|
||||
* 2. Establish an authenticated handle with the DeployR server.
|
||||
* 3. Create a temporary project (R session).
|
||||
* 4. Release connection, close project and logout.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
* Run example.
|
||||
*/
|
||||
function run(config) {
|
||||
var ruser = null, // The user resquest session
|
||||
project = null;
|
||||
|
||||
/*
|
||||
* Configure the DeployR server endpoint and subscribe to all errors at a global
|
||||
* level.
|
||||
*/
|
||||
deployr.configure({
|
||||
logging: false,
|
||||
host: config.endpoint,
|
||||
cors: config.cors,
|
||||
events: {
|
||||
error: function(api, err) {
|
||||
console.warn('AuthProjectCreate: ex=' + err.get('error'));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* Run example.
|
||||
* @NOTE - Remember the`.end()` will send the request for `/r/user/login`
|
||||
* If `.end()` is never called the request will not be sent.
|
||||
*/
|
||||
ruser = deployr.io('/r/user/login');
|
||||
|
||||
ruser.data(config.credentials)
|
||||
.end(function(res) {
|
||||
console.log('AuthProjectCreate: established authenticated ' +
|
||||
'connection, rUser=' + res.get('user').username);
|
||||
})
|
||||
// =========================================================================
|
||||
.io('/r/project/create')
|
||||
.end(function(res) {
|
||||
project = res.get('project').project;
|
||||
|
||||
console.log('AuthProjectCreate: created temporary R session, ' +
|
||||
'rProject=' + project);
|
||||
})
|
||||
// =========================================================================
|
||||
.ensure(function() {
|
||||
/*
|
||||
* Release connection before application exits.
|
||||
*/
|
||||
ruser.release([ project ]);
|
||||
});
|
||||
}
|
||||
|
||||
// -- load configuration and run example --
|
||||
$.getJSON('/examples/config.json').done(function(config) { run(config); });
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -0,0 +1,70 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/*
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* usage: $ node auth-project-create.js
|
||||
* see: http://deployr.revolutionanalytics.com/documents/dev/api-doc/guide/workingprojects.html#projectcreate
|
||||
*
|
||||
* 1. Determine DeployR server endpoint.
|
||||
* 2. Establish an authenticated handle with the DeployR server.
|
||||
* 3. Create a temporary project (R session).
|
||||
* 4. Release connection, close project and logout.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
var deployr = require('../../../../deployr'),
|
||||
config = require('../../../config'),
|
||||
project = null,
|
||||
ruser = null; // The user resquest session
|
||||
|
||||
/*
|
||||
* Configure the DeployR server endpoint and subscribe to all errors at a global
|
||||
* level.
|
||||
*/
|
||||
deployr.configure( {
|
||||
logging: false,
|
||||
host: config.endpoint,
|
||||
events: {
|
||||
error: function(api, err) {
|
||||
console.warn('AuthProjectCreate: ex=' + err.get('error'));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* Run example.
|
||||
* @NOTE - Remember the`.end()` will send the request for `/r/user/login`
|
||||
* If `.end()` is never called the request will not be sent.
|
||||
*/
|
||||
ruser = deployr.io('/r/user/login');
|
||||
|
||||
ruser.data(config.credentials)
|
||||
.end(function(res) {
|
||||
console.log('AuthProjectCreate: established authenticated ' +
|
||||
'connection, rUser=' + res.get('user').username);
|
||||
})
|
||||
// =========================================================================
|
||||
.io('/r/project/create')
|
||||
.end(function(res) {
|
||||
project = res.get('project').project;
|
||||
|
||||
console.log('AuthProjectCreate: created temporary R session, ' +
|
||||
'rProject=' + project);
|
||||
})
|
||||
// =========================================================================
|
||||
.ensure(function() {
|
||||
/*
|
||||
* Release connection before application exits.
|
||||
*/
|
||||
ruser.release([ project ]);
|
||||
});
|
|
@ -0,0 +1,144 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title>Project Directory</title>
|
||||
<script src="../../../../browser/deployr.js"></script>
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Project Directory</h1>
|
||||
<hr>
|
||||
<ol>
|
||||
<li>Populate <strong>/examples/config.json</strong> with the proper values before running.</li>
|
||||
<li>Open the browser's debug window to view print logs for this example.</li>
|
||||
<li>View <a href="http://deployr.revolutionanalytics.com/documents/dev/client-jsdoc/">documentation</a> for more information.</li>
|
||||
</ol>
|
||||
|
||||
<script>
|
||||
/*
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* usage: http://localhost:8080/examples/tutorial/services/project/auth-project-directory.html
|
||||
* see: http://deployr.revolutionanalytics.com/documents/dev/api-doc/guide/workingprojects.html#projectdirectory
|
||||
*
|
||||
* 1. Determine DeployR server endpoint.
|
||||
* 2. Establish an authenticated handle with the DeployR server.
|
||||
* 3. Create a temporary project (R session).
|
||||
* 4. Create a file in the R session's working directory by writing text to a
|
||||
* named file.
|
||||
* 5. Retrieve a list of files in the R session's working directory.
|
||||
* 6. Delete all files in the R session's working directory.
|
||||
* 7. Release connection, close project and logout.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
* Run example.
|
||||
*/
|
||||
function run(config) {
|
||||
var ruser = null, // The user resquest session
|
||||
project = null;
|
||||
|
||||
/*
|
||||
* Configure the DeployR server endpoint and subscribe to all errors at a global
|
||||
* level.
|
||||
*/
|
||||
deployr.configure({
|
||||
logging: false,
|
||||
host: config.endpoint,
|
||||
cors: config.cors,
|
||||
events: {
|
||||
error: function(api, err) {
|
||||
console.warn('AuthProjectDirectory: ex=' + err.get('error'));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* Run example.
|
||||
* @NOTE - Remember the`.end()` will send the request for `/r/user/login`
|
||||
* If `.end()` is never called the request will not be sent.
|
||||
*/
|
||||
ruser = deployr.io('/r/user/login');
|
||||
|
||||
ruser.data(config.credentials)
|
||||
.end(function(res) {
|
||||
console.log('AuthProjectDirectory: established authenticated ' +
|
||||
'connection, rUser=' + res.get('user').username);
|
||||
})
|
||||
// =========================================================================
|
||||
.io('/r/project/create')
|
||||
.end(function(res) {
|
||||
project = res.get('project').project;
|
||||
|
||||
console.log('AuthProjectDirectory: created temporary R session, ' +
|
||||
'rProject=' + project);
|
||||
|
||||
// pass `project` to next async call in io queue
|
||||
return { project: project };
|
||||
})
|
||||
// =========================================================================
|
||||
.io('/r/project/directory/write')
|
||||
.data({ filename: 'hello.txt', text: 'Hello World!' })
|
||||
.end(function(res) {
|
||||
var fileURL = res.get('url');
|
||||
console.log(fileURL);
|
||||
|
||||
// pass `project` to next async call in io queue
|
||||
return { project: project };
|
||||
})
|
||||
// =========================================================================
|
||||
.io('/r/project/directory/list')
|
||||
.end(function(res) {
|
||||
var files = res.get('files'),
|
||||
filename = [];
|
||||
|
||||
files.forEach(function(file) {
|
||||
console.log('AuthProjectDirectory: working directory, ' +
|
||||
'found file name=' + file.filename +
|
||||
', type=' + file.type +
|
||||
', size=' + file.length);
|
||||
|
||||
// delete filename list
|
||||
filename.push(file.filename);
|
||||
|
||||
console.log('AuthProjectDirectory: working directory, ' +
|
||||
'deleted file name=' + file.filename +
|
||||
', type=' + file.type +
|
||||
', size=' + file.length);
|
||||
});
|
||||
|
||||
// pass `project` and `filename` to next async call in io queue
|
||||
return { project: project, filename: filename.join(',') };
|
||||
})
|
||||
// =========================================================================
|
||||
.io('/r/project/directory/delete')
|
||||
.end()
|
||||
// =========================================================================
|
||||
.ensure(function() {
|
||||
/*
|
||||
* Release connection before application exits.
|
||||
*/
|
||||
ruser.release([project]);
|
||||
});
|
||||
}
|
||||
|
||||
// -- load configuration and run example --
|
||||
$.getJSON('/examples/config.json').done(function(config) { run(config); });
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -0,0 +1,114 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/*
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* usage: $ node auth-project-directory.js
|
||||
* see: http://deployr.revolutionanalytics.com/documents/dev/api-doc/guide/workingprojects.html#projectdirectory
|
||||
*
|
||||
* 1. Determine DeployR server endpoint.
|
||||
* 2. Establish an authenticated handle with the DeployR server.
|
||||
* 3. Create a temporary project (R session).
|
||||
* 4. Create a file in the R session's working directory by writing text to a
|
||||
* named file.
|
||||
* 5. Retrieve a list of files in the R session's working directory.
|
||||
* 6. Delete all files in the R session's working directory.
|
||||
* 7. Release connection, close project and logout.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
var deployr = require('../../../../deployr'),
|
||||
config = require('../../../config'),
|
||||
project = null,
|
||||
ruser = null; // The user resquest session
|
||||
|
||||
/*
|
||||
* Configure the DeployR server endpoint and subscribe to all errors at a global
|
||||
* level.
|
||||
*/
|
||||
deployr.configure( {
|
||||
logging: false,
|
||||
host: config.endpoint,
|
||||
events: {
|
||||
error: function(api, err) {
|
||||
console.warn('AuthProjectDirectory: ex=' + err.get('error'));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* Run example.
|
||||
* @NOTE - Remember the`.end()` will send the request for `/r/user/login`
|
||||
* If `.end()` is never called the request will not be sent.
|
||||
*/
|
||||
ruser = deployr.io('/r/user/login');
|
||||
|
||||
ruser.data(config.credentials)
|
||||
.end(function(res) {
|
||||
console.log('AuthProjectDirectory: established authenticated ' +
|
||||
'connection, rUser=' + res.get('user').username);
|
||||
})
|
||||
// =========================================================================
|
||||
.io('/r/project/create')
|
||||
.end(function(res) {
|
||||
project = res.get('project').project;
|
||||
|
||||
console.log('AuthProjectDirectory: created temporary R session, ' +
|
||||
'rProject=' + project);
|
||||
|
||||
// pass `project` to next async call in io queue
|
||||
return { project: project };
|
||||
})
|
||||
// =========================================================================
|
||||
.io('/r/project/directory/write')
|
||||
.data({ filename: 'hello.txt', text: 'Hello World!' })
|
||||
.end(function(res) {
|
||||
var fileURL = res.get('url');
|
||||
console.log(fileURL);
|
||||
|
||||
// pass `project` to next async call in io queue
|
||||
return { project: project };
|
||||
})
|
||||
// =========================================================================
|
||||
.io('/r/project/directory/list')
|
||||
.end(function(res) {
|
||||
var files = res.get('files'),
|
||||
filename = [];
|
||||
|
||||
files.forEach(function(file) {
|
||||
console.log('AuthProjectDirectory: working directory, ' +
|
||||
'found file name=' + file.filename +
|
||||
', type=' + file.type +
|
||||
', size=' + file.length);
|
||||
|
||||
// delete filename list
|
||||
filename.push(file.filename);
|
||||
|
||||
console.info('AuthProjectDirectory: working directory, ' +
|
||||
'deleted file name=' + file.filename +
|
||||
', type=' + file.type +
|
||||
', size=' + file.length);
|
||||
});
|
||||
|
||||
// pass `project` `filename` to next async call in io queue
|
||||
return { project: project, filename: filename.join(',') };
|
||||
})
|
||||
// =========================================================================
|
||||
.io('/r/project/directory/delete')
|
||||
.end()
|
||||
// =========================================================================
|
||||
.ensure(function() {
|
||||
/*
|
||||
* Release connection before application exits.
|
||||
*/
|
||||
ruser.release([ project ]);
|
||||
});
|
|
@ -0,0 +1,121 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title>Project Execute (code)</title>
|
||||
<script src="../../../../browser/deployr.js"></script>
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Project Execute (code)</h1>
|
||||
<hr>
|
||||
<ol>
|
||||
<li>Populate <strong>/examples/config.json</strong> with the proper values before running.</li>
|
||||
<li>Open the browser's debug window to view print logs for this example.</li>
|
||||
<li>View <a href="http://deployr.revolutionanalytics.com/documents/dev/client-jsdoc/">documentation</a> for more information.</li>
|
||||
</ol>
|
||||
|
||||
<script>
|
||||
/*
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* usage: http://localhost:8080/examples/tutorial/services/project/auth-project-execute-code.html
|
||||
* see: http://deployr.revolutionanalytics.com/documents/dev/api-doc/guide/workingprojects.html#projectexecutecode
|
||||
*
|
||||
* 1. Determine DeployR server endpoint.
|
||||
* 2. Establish an authenticated handle with the DeployR server.
|
||||
* 3. Create a temporary project (R session).
|
||||
* 4. Execute an analytics Web service based on an arbitrary block of R code.
|
||||
* 5. Retrieve script execution results.
|
||||
* 6. Release connection, close project and logout.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
* Run example.
|
||||
*/
|
||||
function run(config) {
|
||||
var ruser = null, // The user resquest session
|
||||
project = null;
|
||||
|
||||
/*
|
||||
* Configure the DeployR server endpoint and subscribe to all errors at a global
|
||||
* level.
|
||||
*/
|
||||
deployr.configure({
|
||||
logging: false,
|
||||
host: config.endpoint,
|
||||
cors: config.cors,
|
||||
events: {
|
||||
error: function(api, err) {
|
||||
console.warn('AuthProjectExecuteCode: ex=' + err.get('error'));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* Run example.
|
||||
* @NOTE - Remember the`.end()` will send the request for `/r/user/login`
|
||||
* If `.end()` is never called the request will not be sent.
|
||||
*/
|
||||
ruser = deployr.io('/r/user/login');
|
||||
|
||||
ruser.data(config.credentials)
|
||||
.end(function(res) {
|
||||
console.log('AuthProjectExecuteCode: established authenticated ' +
|
||||
'connection, rUser=' + res.get('user').username);
|
||||
})
|
||||
// =========================================================================
|
||||
.io('/r/project/create')
|
||||
.end(function(res) {
|
||||
project = res.get('project').project;
|
||||
|
||||
console.log('AuthProjectExecuteCode: created temporary R session, ' +
|
||||
'rProject=' + project);
|
||||
|
||||
// pass `project` to next async call in io queue
|
||||
return { project: project };
|
||||
})
|
||||
// =========================================================================
|
||||
.io('/r/project/execute/code')
|
||||
.data({ code: 'demo(graphics)' })
|
||||
.end(function(res) {
|
||||
var exec = res.get('execution').execution;
|
||||
console.log('AuthProjectExecuteCode: R code execution completed, ' +
|
||||
'rProjectExecution=' + exec);
|
||||
|
||||
/*
|
||||
* Retrieve script execution results.
|
||||
*/
|
||||
var rconsole = res.get('console');
|
||||
var plots = res.get('results');
|
||||
var files = res.get('artifacts');
|
||||
var objects = res.workspace(); // --or-- res.get('workspace').objects;
|
||||
})
|
||||
// =========================================================================
|
||||
.ensure(function() {
|
||||
/*
|
||||
* Release connection before application exits.
|
||||
*/
|
||||
ruser.release([project]);
|
||||
});
|
||||
}
|
||||
|
||||
// -- load configuration and run example --
|
||||
$.getJSON('/examples/config.json').done(function(config) { run(config); });
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -0,0 +1,91 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/*
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* usage: $ node auth-project-execute-code.js
|
||||
* see: http://deployr.revolutionanalytics.com/documents/dev/api-doc/guide/workingprojects.html#projectexecutecode
|
||||
*
|
||||
* 1. Determine DeployR server endpoint.
|
||||
* 2. Establish an authenticated handle with the DeployR server.
|
||||
* 3. Create a temporary project (R session).
|
||||
* 4. Execute an analytics Web service based on an arbitrary block of R code.
|
||||
* 5. Retrieve script execution results.
|
||||
* 6. Release connection, close project and logout.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
var deployr = require('../../../../deployr'),
|
||||
config = require('../../../config'),
|
||||
project = null,
|
||||
ruser = null; // The user resquest session
|
||||
|
||||
/*
|
||||
* Configure the DeployR server endpoint and subscribe to all errors at a global
|
||||
* level.
|
||||
*/
|
||||
deployr.configure( {
|
||||
logging: false,
|
||||
host: config.endpoint,
|
||||
events: {
|
||||
error: function(api, err) {
|
||||
console.warn('AuthProjectExecuteCode: ex=' + err.get('error'));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* Run example.
|
||||
* @NOTE - Remember the`.end()` will send the request for `/r/user/login`
|
||||
* If `.end()` is never called the request will not be sent.
|
||||
*/
|
||||
ruser = deployr.io('/r/user/login');
|
||||
|
||||
ruser.data(config.credentials)
|
||||
.end(function(res) {
|
||||
console.log('AuthProjectExecuteCode: established authenticated ' +
|
||||
'connection, rUser=' + res.get('user').username);
|
||||
})
|
||||
// =========================================================================
|
||||
.io('/r/project/create')
|
||||
.end(function(res) {
|
||||
project = res.get('project').project;
|
||||
|
||||
console.log('AuthProjectExecuteCode: created temporary R session, ' +
|
||||
'rProject=' + project);
|
||||
|
||||
// pass `project` to next async call in io queue
|
||||
return { project: project };
|
||||
})
|
||||
// =========================================================================
|
||||
.io('/r/project/execute/code')
|
||||
.data({ code: 'demo(graphics)' })
|
||||
.end(function(res) {
|
||||
var exec = res.get('execution').execution;
|
||||
console.log('AuthProjectExecuteCode: R code execution completed, ' +
|
||||
'rProjectExecution=' + exec);
|
||||
|
||||
/*
|
||||
* Retrieve script execution results.
|
||||
*/
|
||||
var rconsole = res.get('console');
|
||||
var plots = res.get('results');
|
||||
var files = res.get('artifacts');
|
||||
var objects = res.workspace(); // --or-- res.get('workspace').objects;
|
||||
})
|
||||
// =========================================================================
|
||||
.ensure(function() {
|
||||
/*
|
||||
* Release connection before application exits.
|
||||
*/
|
||||
ruser.release([ project ]);
|
||||
});
|
|
@ -0,0 +1,126 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title>Project Execute (script)</title>
|
||||
<script src="../../../../browser/deployr.js"></script>
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Project Execute (script)</h1>
|
||||
<hr>
|
||||
<ol>
|
||||
<li>Populate <strong>/examples/config.json</strong> with the proper values before running.</li>
|
||||
<li>Open the browser's debug window to view print logs for this example.</li>
|
||||
<li>View <a href="http://deployr.revolutionanalytics.com/documents/dev/client-jsdoc/">documentation</a> for more information.</li>
|
||||
</ol>
|
||||
|
||||
<script>
|
||||
/*
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* usage: http://localhost:8080/examples/tutorial/services/project/auth-project-execute-script.html
|
||||
* see: http://deployr.revolutionanalytics.com/documents/dev/api-doc/guide/workingprojects.html#projectexecutescript
|
||||
*
|
||||
* 1. Determine DeployR server endpoint.
|
||||
* 2. Establish an authenticated handle with the DeployR server.
|
||||
* 3. Create a temporary project (R session).
|
||||
* 4. Execute an analytics Web service based on a repository-managed R script:
|
||||
`/testuser/root/Histogram of Auto Sales.R`
|
||||
* 5. Retrieve script execution results.
|
||||
* 6. Release connection, close project and logout.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
* Run example.
|
||||
*/
|
||||
function run(config) {
|
||||
var ruser = null, // The user resquest session
|
||||
project = null;
|
||||
|
||||
/*
|
||||
* Configure the DeployR server endpoint and subscribe to all errors at a global
|
||||
* level.
|
||||
*/
|
||||
deployr.configure({
|
||||
logging: false,
|
||||
host: config.endpoint,
|
||||
cors: config.cors,
|
||||
events: {
|
||||
error: function(api, err) {
|
||||
console.warn('AuthProjectExecuteScript: ex=' + err.get('error'));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* Run example.
|
||||
* @NOTE - Remember the`.end()` will send the request for `/r/user/login`
|
||||
* If `.end()` is never called the request will not be sent.
|
||||
*/
|
||||
ruser = deployr.io('/r/user/login');
|
||||
|
||||
ruser.data(config.credentials)
|
||||
.end(function(res) {
|
||||
console.log('AuthProjectExecuteScript: established authenticated ' +
|
||||
'connection, rUser=' + res.get('user').username);
|
||||
})
|
||||
// =========================================================================
|
||||
.io('/r/project/create')
|
||||
.end(function(res) {
|
||||
project = res.get('project').project;
|
||||
|
||||
console.log('AuthProjectExecuteScript: created temporary R session, ' +
|
||||
'rProject=' + project);
|
||||
|
||||
// pass `project` to next async call in io queue
|
||||
return { project: project };
|
||||
})
|
||||
// =========================================================================
|
||||
.io('/r/project/execute/script')
|
||||
.data({
|
||||
filename: 'Histogram of Auto Sales.R',
|
||||
author: 'testuser',
|
||||
directory: 'root'
|
||||
})
|
||||
.end(function(res) {
|
||||
var exec = res.get('execution').execution;
|
||||
console.log('AuthProjectExecuteScript: R code execution completed, ' +
|
||||
'rProjectExecution=' + exec);
|
||||
|
||||
/*
|
||||
* Retrieve script execution results.
|
||||
*/
|
||||
var rconsole = res.get('console');
|
||||
var plots = res.get('results');
|
||||
var files = res.get('artifacts');
|
||||
var objects = res.workspace(); // --or-- res.get('workspace').objects;
|
||||
})
|
||||
// =========================================================================
|
||||
.ensure(function() {
|
||||
/*
|
||||
* Release connection before application exits.
|
||||
*/
|
||||
ruser.release([project]);
|
||||
});
|
||||
}
|
||||
|
||||
// -- load configuration and run example --
|
||||
$.getJSON('/examples/config.json').done(function(config) { run(config); });
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -0,0 +1,92 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/*
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* usage: $ node auth-project-execute-script.js
|
||||
* see: http://deployr.revolutionanalytics.com/documents/dev/api-doc/guide/workingprojects.html#projectexecutescript
|
||||
*
|
||||
* 1. Determine DeployR server endpoint.
|
||||
* 2. Establish an authenticated handle with the DeployR server.
|
||||
* 3. Create a temporary project (R session).
|
||||
* 4. Execute an analytics Web service based on a repository-managed R script:
|
||||
`/testuser/root/Histogram of Auto Sales.R`
|
||||
* 5. Retrieve script execution results.
|
||||
* 6. Release connection, close project and logout.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
var deployr = require('../../../../deployr'),
|
||||
config = require('../../../config'),
|
||||
project = null,
|
||||
ruser = null; // The user resquest session
|
||||
|
||||
/*
|
||||
* Configure the DeployR server endpoint and subscribe to all errors at a global
|
||||
* level.
|
||||
*/
|
||||
deployr.configure( {
|
||||
logging: false,
|
||||
host: config.endpoint,
|
||||
events: {
|
||||
error: function(api, err) {
|
||||
console.warn('AuthProjectExecuteScript: ex=' + err.get('error'));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* Run example.
|
||||
* @NOTE - Remember the`.end()` will send the request for `/r/user/login`
|
||||
* If `.end()` is never called the request will not be sent.
|
||||
*/
|
||||
ruser = deployr.io('/r/user/login');
|
||||
|
||||
ruser.data(config.credentials)
|
||||
.end(function(res) {
|
||||
console.log('AuthProjectExecuteScript: established authenticated ' +
|
||||
'connection, rUser=' + res.get('user').username);
|
||||
})
|
||||
// =========================================================================
|
||||
.io('/r/project/create')
|
||||
.end(function(res) {
|
||||
project = res.get('project').project;
|
||||
|
||||
console.log('AuthProjectExecuteScript: created temporary R session, ' +
|
||||
'rProject=' + project);
|
||||
|
||||
// pass `project` to next async call in io queue
|
||||
return { project: project };
|
||||
})
|
||||
// =========================================================================
|
||||
.io('/r/project/execute/script')
|
||||
.data({ filename: 'Histogram of Auto Sales.R', author: 'testuser', directory: 'root' })
|
||||
.end(function(res) {
|
||||
var exec = res.get('execution').execution;
|
||||
console.log('AuthProjectExecuteScript: R code execution completed, ' +
|
||||
'rProjectExecution=' + exec);
|
||||
|
||||
/*
|
||||
* Retrieve script execution results.
|
||||
*/
|
||||
var rconsole = res.get('console');
|
||||
var plots = res.get('results');
|
||||
var files = res.get('artifacts');
|
||||
var objects = res.workspace(); // --or-- res.get('workspace').objects;
|
||||
})
|
||||
// =========================================================================
|
||||
.ensure(function() {
|
||||
/*
|
||||
* Release connection before application exits.
|
||||
*/
|
||||
ruser.release([ project ]);
|
||||
});
|
|
@ -0,0 +1,115 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title>Project Packages</title>
|
||||
<script src="../../../../browser/deployr.js"></script>
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Project Packages</h1>
|
||||
<hr>
|
||||
<ol>
|
||||
<li>Populate <strong>/examples/config.json</strong> with the proper values before running.</li>
|
||||
<li>Open the browser's debug window to view print logs for this example.</li>
|
||||
<li>View <a href="http://deployr.revolutionanalytics.com/documents/dev/client-jsdoc/">documentation</a> for more information.</li>
|
||||
</ol>
|
||||
|
||||
<script>
|
||||
/*
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* usage: http://localhost:8080/examples/tutorial/services/project/auth-project-packages.html
|
||||
* see: http://deployr.revolutionanalytics.com/documents/dev/api-doc/guide/workingprojects.html#projectpackagelist
|
||||
*
|
||||
* 1. Determine DeployR server endpoint.
|
||||
* 2. Establish an authenticated handle with the DeployR server.
|
||||
* 3. Create a temporary project (R session).
|
||||
* 4. Retrieve a list of R packages that are current attached on the R session.
|
||||
* 5. Release connection, close project and logout.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
* Run example.
|
||||
*/
|
||||
function run(config) {
|
||||
var ruser = null, // The user resquest session
|
||||
project = null;
|
||||
|
||||
/*
|
||||
* Configure the DeployR server endpoint and subscribe to all errors at a global
|
||||
* level.
|
||||
*/
|
||||
deployr.configure({
|
||||
logging: false,
|
||||
host: config.endpoint,
|
||||
cors: config.cors,
|
||||
events: {
|
||||
error: function(api, err) {
|
||||
console.warn('AuthProjectPackages: ex=' + err.get('error'));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* Run example.
|
||||
* @NOTE - Remember the`.end()` will send the request for `/r/user/login`
|
||||
* If `.end()` is never called the request will not be sent.
|
||||
*/
|
||||
ruser = deployr.io('/r/user/login');
|
||||
|
||||
ruser.data(config.credentials)
|
||||
.end(function(res) {
|
||||
console.log('AuthProjectPackages: established authenticated ' +
|
||||
'connection, rUser=' + res.get('user').username);
|
||||
})
|
||||
// =========================================================================
|
||||
.io('/r/project/create')
|
||||
.end(function(res) {
|
||||
project = res.get('project').project;
|
||||
|
||||
console.log('AuthProjectPackages: created temporary R session, ' +
|
||||
'rProject=' + project);
|
||||
|
||||
// pass `project` to next async call in io queue
|
||||
return { project: project };
|
||||
})
|
||||
// =========================================================================
|
||||
.io('/r/project/package/list')
|
||||
.end(function(res) {
|
||||
var packages = res.get('packages');
|
||||
packages.forEach(function(pkg) {
|
||||
console.log('AuthProjectPackages: R session, found attached R package ' +
|
||||
'name=' + pkg.name +
|
||||
', repo=' + pkg.repo +
|
||||
', version=' + pkg.version);
|
||||
});
|
||||
})
|
||||
// =========================================================================
|
||||
.ensure(function() {
|
||||
/*
|
||||
* Release connection before application exits.
|
||||
*/
|
||||
ruser.release([project]);
|
||||
});
|
||||
}
|
||||
|
||||
// -- load configuration and run example --
|
||||
$.getJSON('/examples/config.json').done(function(config) { run(config); });
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -0,0 +1,85 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/*
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* usage: $ node auth-project-packages.js
|
||||
* see: http://deployr.revolutionanalytics.com/documents/dev/api-doc/guide/workingprojects.html#projectpackagelist
|
||||
*
|
||||
* 1. Determine DeployR server endpoint.
|
||||
* 2. Establish an authenticated handle with the DeployR server.
|
||||
* 3. Create a temporary project (R session).
|
||||
* 4. Retrieve a list of R packages that are current attached on the R session.
|
||||
* 5. Release connection, close project and logout.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
var deployr = require('../../../../deployr'),
|
||||
config = require('../../../config'),
|
||||
project = null,
|
||||
ruser = null; // The user resquest session
|
||||
|
||||
/*
|
||||
* Configure the DeployR server endpoint and subscribe to all errors at a global
|
||||
* level.
|
||||
*/
|
||||
deployr.configure( {
|
||||
logging: false,
|
||||
host: config.endpoint,
|
||||
events: {
|
||||
error: function(api, err) {
|
||||
console.warn('AuthProjectPackages: ex=' + err.get('error'));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* Run example.
|
||||
* @NOTE - Remember the`.end()` will send the request for `/r/user/login`
|
||||
* If `.end()` is never called the request will not be sent.
|
||||
*/
|
||||
ruser = deployr.io('/r/user/login');
|
||||
|
||||
ruser.data(config.credentials)
|
||||
.end(function(res) {
|
||||
console.log('AuthProjectPackages: established authenticated ' +
|
||||
'connection, rUser=' + res.get('user').username);
|
||||
})
|
||||
// =========================================================================
|
||||
.io('/r/project/create')
|
||||
.end(function(res) {
|
||||
project = res.get('project').project;
|
||||
|
||||
console.log('AuthProjectPackages: created temporary R session, ' +
|
||||
'rProject=' + project);
|
||||
|
||||
// pass `project` to next async call in io queue
|
||||
return { project: project };
|
||||
})
|
||||
// =========================================================================
|
||||
.io('/r/project/package/list')
|
||||
.end(function(res) {
|
||||
var packages = res.get('packages');
|
||||
packages.forEach(function(pkg) {
|
||||
console.log('AuthProjectPackages: R session, found attached R package ' +
|
||||
'name=' + pkg.name +
|
||||
', repo=' + pkg.repo +
|
||||
', version=' + pkg.version);
|
||||
});
|
||||
})
|
||||
// =========================================================================
|
||||
.ensure(function() {
|
||||
/*
|
||||
* Release connection before application exits.
|
||||
*/
|
||||
ruser.release([ project ]);
|
||||
});
|
|
@ -0,0 +1,106 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title>Project Pool Create</title>
|
||||
<script src="../../../../browser/deployr.js"></script>
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Project Pool Create</h1>
|
||||
<hr>
|
||||
<ol>
|
||||
<li>Populate <strong>/examples/config.json</strong> with the proper values before running.</li>
|
||||
<li>Open the browser's debug window to view print logs for this example.</li>
|
||||
<li>View <a href="http://deployr.revolutionanalytics.com/documents/dev/client-jsdoc/">documentation</a> for more information.</li>
|
||||
</ol>
|
||||
|
||||
<script>
|
||||
/*
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* usage: http://localhost:8080/examples/tutorial/services/project/auth-project-pool-create.html
|
||||
* see: http://deployr.revolutionanalytics.com/documents/dev/api-doc/guide/workingprojects.html#projectpool
|
||||
*
|
||||
* 1. Determine DeployR server endpoint.
|
||||
* 2. Establish an authenticated handle with the DeployR server.
|
||||
* 3. Create a pool of temporary projects (R sessions).
|
||||
* 4. Release connection, close all projects and logout.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
* Run example.
|
||||
*/
|
||||
function run(config) {
|
||||
var ruser = null, // The user resquest session
|
||||
projects = [];
|
||||
/*
|
||||
* Configure the DeployR server endpoint and subscribe to all errors at a global
|
||||
* level.
|
||||
*/
|
||||
deployr.configure({
|
||||
logging: false,
|
||||
host: config.endpoint,
|
||||
cors: config.cors,
|
||||
events: {
|
||||
error: function(api, err) {
|
||||
console.warn('AuthProjectPoolCreate: ex=' + err.get('error'));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* Run example.
|
||||
* @NOTE - Remember the`.end()` will send the request for `/r/user/login`
|
||||
* If `.end()` is never called the request will not be sent.
|
||||
*/
|
||||
ruser = deployr.io('/r/user/login');
|
||||
|
||||
ruser.data(config.credentials)
|
||||
.end(function(res) {
|
||||
console.log('AuthProjectPoolCreate: established authenticated ' +
|
||||
'connection, rUser=' + res.get('user').username);
|
||||
})
|
||||
// =========================================================================
|
||||
.io('/r/project/pool')
|
||||
.data({
|
||||
poolsize: 4
|
||||
})
|
||||
.end(function(res) {
|
||||
var pool = res.get('projects');
|
||||
|
||||
pool.forEach(function(project) {
|
||||
projects.push(project.project);
|
||||
});
|
||||
|
||||
console.log('AuthProjectPoolCreate: created pool of ' +
|
||||
pool.length + ' temporary R sessions, pool=' + projects);
|
||||
})
|
||||
// =========================================================================
|
||||
.ensure(function() {
|
||||
/*
|
||||
* Release connection before application exits.
|
||||
*/
|
||||
ruser.release(projects);
|
||||
});
|
||||
}
|
||||
|
||||
// -- load configuration and run example --
|
||||
$.getJSON('/examples/config.json').done(function(config) { run(config); });
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -0,0 +1,74 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/*
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* usage: $ node auth-project-pool-create.js
|
||||
* see: http://deployr.revolutionanalytics.com/documents/dev/api-doc/guide/workingprojects.html#projectpool
|
||||
*
|
||||
* 1. Determine DeployR server endpoint.
|
||||
* 2. Establish an authenticated handle with the DeployR server.
|
||||
* 3. Create a pool of temporary projects (R sessions).
|
||||
* 4. Release connection, close all projects and logout.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
var deployr = require('../../../../deployr'),
|
||||
config = require('../../../config'),
|
||||
projects = [],
|
||||
ruser = null; // The user resquest session
|
||||
|
||||
/*
|
||||
* Configure the DeployR server endpoint and subscribe to all errors at a global
|
||||
* level.
|
||||
*/
|
||||
deployr.configure( {
|
||||
logging: false,
|
||||
host: config.endpoint,
|
||||
events: {
|
||||
error: function(api, err) {
|
||||
console.warn('AuthProjectPoolCreate: ex=' + err.get('error'));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* Run example.
|
||||
* @NOTE - Remember the`.end()` will send the request for `/r/user/login`
|
||||
* If `.end()` is never called the request will not be sent.
|
||||
*/
|
||||
ruser = deployr.io('/r/user/login');
|
||||
|
||||
ruser.data(config.credentials)
|
||||
.data(config.credentials)
|
||||
.end(function(res) {
|
||||
console.log('AuthProjectPoolCreate: established authenticated ' +
|
||||
'connection, rUser=' + res.get('user').username);
|
||||
})
|
||||
// =========================================================================
|
||||
.io('/r/project/pool')
|
||||
.data({ poolsize: 4 })
|
||||
.end(function(res) {
|
||||
var pool = res.get('projects');
|
||||
|
||||
pool.forEach(function(project) { projects.push(project.project); });
|
||||
|
||||
console.log('AuthProjectPoolCreate: created pool of ' +
|
||||
pool.length + ' temporary R sessions, pool=' + projects);
|
||||
})
|
||||
// =========================================================================
|
||||
.ensure(function() {
|
||||
/*
|
||||
* Release connection before application exits.
|
||||
*/
|
||||
ruser.release(projects);
|
||||
});
|
|
@ -0,0 +1,163 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title>Project Workspace</title>
|
||||
<script src="../../../../browser/deployr.js"></script>
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Project Workspace</h1>
|
||||
<hr>
|
||||
<ol>
|
||||
<li>Populate <strong>/examples/config.json</strong> with the proper values before running.</li>
|
||||
<li>Open the browser's debug window to view print logs for this example.</li>
|
||||
<li>View <a href="http://deployr.revolutionanalytics.com/documents/dev/client-jsdoc/">documentation</a> for more information.</li>
|
||||
</ol>
|
||||
|
||||
<script>
|
||||
/*
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* usage: http://localhost:8080/examples/tutorial/services/project/auth-project-workspace.html
|
||||
* see: http://deployr.revolutionanalytics.com/documents/dev/api-doc/guide/workingprojects.html#projectworkspace
|
||||
*
|
||||
* 1. Determine DeployR server endpoint.
|
||||
* 2. Establish an authenticated handle with the DeployR server.
|
||||
* 3. Create a temporary project (R session).
|
||||
* 4. Execute a block of R code to create an object in the R session's workspace.
|
||||
* 5. Retrieve the object "x" from the R session's workspace.
|
||||
* 6. Create R object data in the R sesssion's workspace by pushing
|
||||
* DeployR-encoded data from the client application:
|
||||
* - Prepare sample R object vector data.
|
||||
* - Use RDataFactory to encode the sample R object vector data.
|
||||
* - Push encoded R object into the workspace.
|
||||
* 7. Retrieve the object "y" from the R session's workspace.
|
||||
* 8. Retrieve a list of R objects in the R session's workspace.
|
||||
* 9. Release connection, close project and logout.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
* Run example.
|
||||
*/
|
||||
function run(config) {
|
||||
var ruser = null, // The user resquest session
|
||||
project = null;
|
||||
|
||||
/*
|
||||
* Configure the DeployR server endpoint and subscribe to all errors at a global
|
||||
* level.
|
||||
*/
|
||||
deployr.configure({
|
||||
logging: false,
|
||||
host: config.endpoint,
|
||||
cors: config.cors,
|
||||
events: {
|
||||
error: function(api, err) {
|
||||
console.warn('AuthProjectWorkspace: ex=' + err.get('error'));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* Run example.
|
||||
* @NOTE - Remember the`.end()` will send the request for `/r/user/login`
|
||||
* If `.end()` is never called the request will not be sent.
|
||||
*/
|
||||
ruser = deployr.io('/r/user/login');
|
||||
|
||||
ruser.data(config.credentials)
|
||||
.end(function(res) {
|
||||
console.log('AuthProjectWorkspace: established authenticated ' +
|
||||
'connection, rUser=' + res.get('user').username);
|
||||
})
|
||||
// =========================================================================
|
||||
.io('/r/project/create')
|
||||
.end(function(res) {
|
||||
project = res.get('project').project;
|
||||
|
||||
console.log('AuthProjectWorkspace: created temporary R session, ' +
|
||||
'rProject=' + project);
|
||||
|
||||
// pass `project` to next async call in io queue
|
||||
return { project: project };
|
||||
})
|
||||
// =========================================================================
|
||||
.io('/r/project/execute/code')
|
||||
.data({ code: 'x <- T' })
|
||||
.end(function(res) {
|
||||
// pass `project` to next async call in io queue
|
||||
return { project: project };
|
||||
})
|
||||
// =========================================================================
|
||||
.io('/r/project/workspace/get')
|
||||
.data({ name: 'x' })
|
||||
.end(function(res) {
|
||||
/*
|
||||
* Retrieve the object "x" from the R session's workspace.
|
||||
*/
|
||||
var encodedX = res.workspace();
|
||||
|
||||
console.log('AuthProjectWorkspace: retrieved object x ' +
|
||||
'from workspace, encodedX=' + encodedX.value);
|
||||
|
||||
// pass `project` to next async call in io queue
|
||||
return { project: project };
|
||||
})
|
||||
// =========================================================================
|
||||
.io('/r/project/workspace/push')
|
||||
.numericVector('y', [10.0, 11.1, 12.2, 13.3, 14.4])
|
||||
.end(function(res) {
|
||||
// pass `project` to next async call in io queue
|
||||
return { project: project };
|
||||
})
|
||||
// =========================================================================
|
||||
.io('/r/project/workspace/get')
|
||||
.data({
|
||||
name: 'y'
|
||||
})
|
||||
.end(function(res) {
|
||||
/*
|
||||
* Retrieve the object "y" from the R session's workspace.
|
||||
*/
|
||||
var encodedY = res.workspace();
|
||||
|
||||
console.log('AuthProjectWorkspace: retrieved object y ' +
|
||||
'from workspace, encodedY=' + encodedY.value);
|
||||
|
||||
// pass `project` to next async call in io queue
|
||||
return { project: project };
|
||||
})
|
||||
// =========================================================================
|
||||
.io('/r/project/workspace/list')
|
||||
.end(function(res) {
|
||||
var objects = res.workspace();
|
||||
})
|
||||
// =========================================================================
|
||||
.ensure(function() {
|
||||
/*
|
||||
* Release connection before application exits.
|
||||
*/
|
||||
ruser.release([project]);
|
||||
});
|
||||
}
|
||||
|
||||
// -- load configuration and run example --
|
||||
$.getJSON('/examples/config.json').done(function(config) { run(config); });
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -0,0 +1,131 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/*
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* usage: $ node auth-project-workspace.js
|
||||
* see: http://deployr.revolutionanalytics.com/documents/dev/api-doc/guide/workingprojects.html#projectworkspace
|
||||
*
|
||||
* 1. Determine DeployR server endpoint.
|
||||
* 2. Establish an authenticated handle with the DeployR server.
|
||||
* 3. Create a temporary project (R session).
|
||||
* 4. Execute a block of R code to create an object in the R session's workspace.
|
||||
* 5. Retrieve the object "x" from the R session's workspace.
|
||||
* 6. Create R object data in the R sesssion's workspace by pushing
|
||||
* DeployR-encoded data from the client application:
|
||||
* - Prepare sample R object vector data.
|
||||
* - Use RDataFactory to encode the sample R object vector data.
|
||||
* - Push encoded R object into the workspace.
|
||||
* 7. Retrieve the object "y" from the R session's workspace.
|
||||
* 8. Retrieve a list of R objects in the R session's workspace.
|
||||
* 9. Release connection, close project and logout.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
var deployr = require('../../../../deployr'),
|
||||
config = require('../../../config'),
|
||||
project = null,
|
||||
ruser = null; // The user resquest session
|
||||
|
||||
/*
|
||||
* Configure the DeployR server endpoint and subscribe to all errors at a global
|
||||
* level.
|
||||
*/
|
||||
deployr.configure( {
|
||||
logging: false,
|
||||
host: config.endpoint,
|
||||
events: {
|
||||
error: function(api, err) {
|
||||
console.warn('AuthProjectWorkspace: ex=' + err.get('error'));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* Run example.
|
||||
* @NOTE - Remember the`.end()` will send the request for `/r/user/login`
|
||||
* If `.end()` is never called the request will not be sent.
|
||||
*/
|
||||
ruser = deployr.io('/r/user/login');
|
||||
|
||||
ruser.data(config.credentials)
|
||||
.end(function(res) {
|
||||
console.log('AuthProjectWorkspace: established authenticated ' +
|
||||
'connection, rUser=' + res.get('user').username);
|
||||
})
|
||||
// =========================================================================
|
||||
.io('/r/project/create')
|
||||
.end(function(res) {
|
||||
project = res.get('project').project;
|
||||
|
||||
console.log('AuthProjectWorkspace: created temporary R session, ' +
|
||||
'rProject=' + project);
|
||||
|
||||
// pass `project` to next async call in io queue
|
||||
return { project: project };
|
||||
})
|
||||
// =========================================================================
|
||||
.io('/r/project/execute/code')
|
||||
.data({ code: 'x <- T' })
|
||||
.end(function(res) {
|
||||
// pass `project` to next async call in io queue
|
||||
return { project: project };
|
||||
})
|
||||
// =========================================================================
|
||||
.io('/r/project/workspace/get')
|
||||
.data({ name: 'x' })
|
||||
.end(function(res) {
|
||||
/*
|
||||
* Retrieve the object "x" from the R session's workspace.
|
||||
*/
|
||||
var encodedX = res.workspace();
|
||||
|
||||
console.log('AuthProjectWorkspace: retrieved object x ' +
|
||||
'from workspace, encodedX=' + encodedX.value);
|
||||
|
||||
// pass `project` to next async call in io queue
|
||||
return { project: project };
|
||||
})
|
||||
// =========================================================================
|
||||
.io('/r/project/workspace/push')
|
||||
.numericVector('y', [10.0, 11.1, 12.2, 13.3, 14.4])
|
||||
.end(function(res) {
|
||||
// pass `project` to next async call in io queue
|
||||
return { project: project };
|
||||
})
|
||||
// =========================================================================
|
||||
.io('/r/project/workspace/get')
|
||||
.data({ name: 'y' })
|
||||
.end(function(res) {
|
||||
/*
|
||||
* Retrieve the object "y" from the R session's workspace.
|
||||
*/
|
||||
var encodedY = res.workspace();
|
||||
|
||||
console.log('AuthProjectWorkspace: retrieved object y ' +
|
||||
'from workspace, encodedY=' + encodedY.value);
|
||||
|
||||
// pass `project` to next async call in io queue
|
||||
return { project: project };
|
||||
})
|
||||
// =========================================================================
|
||||
.io('/r/project/workspace/list')
|
||||
.end(function(res) {
|
||||
var objects = res.workspace();
|
||||
})
|
||||
// =========================================================================
|
||||
.ensure(function() {
|
||||
/*
|
||||
* Release connection before application exits.
|
||||
*/
|
||||
ruser.release([ project ]);
|
||||
});
|
|
@ -0,0 +1,110 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title>Repository</title>
|
||||
<script src="../../../../browser/deployr.js"></script>
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Repository</h1>
|
||||
<hr>
|
||||
<ol>
|
||||
<li>Populate <strong>/examples/config.json</strong> with the proper values before running.</li>
|
||||
<li>Open the browser's debug window to view print logs for this example.</li>
|
||||
<li>View <a href="http://deployr.revolutionanalytics.com/documents/dev/client-jsdoc/">documentation</a> for more information.</li>
|
||||
</ol>
|
||||
|
||||
<script>
|
||||
|
||||
/*
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/* --------------------------------------------------------------------
|
||||
* usage: $ node auth-repository-management.js
|
||||
* see: http://deployr.revolutionanalytics.com/documents/dev/api-doc/guide/workingrepository.html
|
||||
*
|
||||
* 1. Determine DeployR server endpoint.
|
||||
* 2. Establish an authenticated handle with the DeployR server.
|
||||
* 3. Create a file in the authenticated user's private repository and set
|
||||
* shared access on the file so other authenticated users can access the file.
|
||||
* 4. Retrieve a list of files in the authenticated user's private repository.
|
||||
* --------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
* Run example.
|
||||
*/
|
||||
function run(config) {
|
||||
var ruser = null; // The user resquest session
|
||||
|
||||
/*
|
||||
* Configure the DeployR server endpoint and subscribe to all errors
|
||||
* at a global level.
|
||||
*/
|
||||
deployr.configure( {
|
||||
logging: false,
|
||||
host: config.endpoint,
|
||||
cors: config.cors,
|
||||
events: {
|
||||
error: function(api, err) {
|
||||
console.warn('AuthRepositoryManagement: ex=' + err.get('error'));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* Run example.
|
||||
* @NOTE - Remember the`.end()` will send the request for `.io()`
|
||||
* If `.end()` is never called the requests will not be sent.
|
||||
*/
|
||||
ruser = deployr.io('/r/user/login');
|
||||
|
||||
ruser.data(config.credentials)
|
||||
.end(function(res) {
|
||||
console.log('AuthRepositoryManagement: established authenticated ' +
|
||||
'connection, rUser=' + res.get('user').username);
|
||||
})
|
||||
// ===============================================================
|
||||
.io('/r/repository/file/write')
|
||||
.data({ filename: 'hello.txt', shared: true, text: 'Hello World!' })
|
||||
.end(function(res) {
|
||||
var fileURL = res.get('url');
|
||||
console.log(fileURL);
|
||||
})
|
||||
// ===============================================================
|
||||
.io('/r/repository/file/list')
|
||||
.end(function(res) {
|
||||
var files = res.get('files');
|
||||
files.forEach(function(file) {
|
||||
console.log('AuthRepositoryManagement: private repository, ' +
|
||||
'found file name=' +
|
||||
file.filename + ", directory=" +
|
||||
file.directory + ", access=" +
|
||||
file.access);
|
||||
});
|
||||
})
|
||||
// ================================================================
|
||||
.ensure(function() {
|
||||
/*
|
||||
* Release connection before application exits.
|
||||
*/
|
||||
ruser.release();
|
||||
});
|
||||
}
|
||||
|
||||
// -- load configuration and run example --
|
||||
$.getJSON('/examples/config.json').done(function(config) { run(config); });
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,81 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/*
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* usage: $ node auth-repository-management.js
|
||||
* see: http://deployr.revolutionanalytics.com/documents/dev/api-doc/guide/workingrepository.html
|
||||
*
|
||||
* 1. Determine DeployR server endpoint.
|
||||
* 2. Establish an authenticated handle with the DeployR server.
|
||||
* 3. Create a file in the authenticated user's private repository and set
|
||||
* shared access on the file so other authenticated users can access the file.
|
||||
* 4. Retrieve a list of files in the authenticated user's private repository.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
var deployr = require('../../../../deployr'),
|
||||
config = require('../../../config'),
|
||||
ruser = null; // The user resquest session
|
||||
|
||||
/*
|
||||
* Configure the DeployR server endpoint and subscribe to all errors at a global
|
||||
* level.
|
||||
*/
|
||||
deployr.configure( {
|
||||
logging: false,
|
||||
host: config.endpoint,
|
||||
events: {
|
||||
error: function(api, err) {
|
||||
console.warn('AuthRepositoryManagement: ex=' + err.get('error'));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* Run example.
|
||||
* @NOTE - Remember the`.end()` will send the request for `.io()`
|
||||
* If `.end()` is never called the requests will not be sent.
|
||||
*/
|
||||
ruser = deployr.io('/r/user/login');
|
||||
|
||||
ruser.data(config.credentials)
|
||||
.end(function(res) {
|
||||
console.log('AuthRepositoryManagement: established authenticated ' +
|
||||
'connection, rUser=' + res.get('user').username);
|
||||
})
|
||||
// =========================================================================
|
||||
.io('/r/repository/file/write')
|
||||
.data({ filename: 'hello.txt', shared: true, text: 'Hello World!' })
|
||||
.end(function(res) {
|
||||
var fileURL = res.get('url');
|
||||
console.log(fileURL);
|
||||
})
|
||||
// =========================================================================
|
||||
.io('/r/repository/file/list')
|
||||
.end(function(res) {
|
||||
var files = res.get('files');
|
||||
files.forEach(function(file) {
|
||||
console.log('AuthRepositoryManagement: private repository, ' +
|
||||
'found file name=' +
|
||||
file.filename + ", directory=" +
|
||||
file.directory + ", access=" +
|
||||
file.access);
|
||||
});
|
||||
})
|
||||
// =========================================================================
|
||||
.ensure(function() {
|
||||
/*
|
||||
* Release connection before application exits.
|
||||
*/
|
||||
ruser.release();
|
||||
});
|
|
@ -0,0 +1,21 @@
|
|||
/*!
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
var path = require('path'),
|
||||
pkg = require('../package.json');
|
||||
|
||||
module.exports = {
|
||||
port: '3000',
|
||||
root: path.resolve('./'),
|
||||
dist: './browser',
|
||||
name: pkg.name,
|
||||
pkg: pkg
|
||||
};
|
|
@ -0,0 +1,18 @@
|
|||
/*!
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
var fs = require('fs'),
|
||||
whitelist = require('./util/scriptFilter'),
|
||||
tasks = fs.readdirSync('./gulp/tasks/').filter(whitelist);
|
||||
|
||||
tasks.forEach(function(task) {
|
||||
require('./tasks/' + task);
|
||||
});
|
|
@ -0,0 +1,31 @@
|
|||
/*!
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
var browserify = require('browserify'),
|
||||
gulp = require('gulp'),
|
||||
source = require('vinyl-source-stream'),
|
||||
plumber = require('gulp-plumber'),
|
||||
onError = require('../util/handleErrors'),
|
||||
config = require('../config');
|
||||
|
||||
/*
|
||||
* Task: browserify
|
||||
*
|
||||
* Runs `browserify` on the `deployr` source.
|
||||
*/
|
||||
gulp.task('browserify', function() {
|
||||
return browserify({ entries: ['./' + config.name + '.js'] })
|
||||
.ignore('http')
|
||||
.bundle({debug: true, standalone: config.name })
|
||||
.pipe(plumber({ errorHandler: onError}))
|
||||
.pipe(source(config.name + '.js'))
|
||||
.pipe(gulp.dest(config.dist));
|
||||
});
|
|
@ -0,0 +1,19 @@
|
|||
/*!
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
var gulp = require('gulp');
|
||||
|
||||
/*
|
||||
* Task: build
|
||||
*
|
||||
* The main build task to prepare the deployr source for browser environments.
|
||||
*/
|
||||
gulp.task('build', ['jshint', 'header']);
|
|
@ -0,0 +1,37 @@
|
|||
/*!
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
var connect = require('connect'),
|
||||
gulp = require('gulp'),
|
||||
gutil = require('gulp-util'),
|
||||
http = require('http'),
|
||||
config = require('../config');
|
||||
|
||||
/*
|
||||
* Task: connect
|
||||
*
|
||||
* Start the `Connect` HTTP server for viewing ./examples HTML samples.
|
||||
*/
|
||||
gulp.task('connect', ['examples-watch'], function(){
|
||||
var SEP = '\n============================================================\n',
|
||||
app = connect()
|
||||
.use(connect.logger('dev'))
|
||||
.use(connect.static(config.root));
|
||||
|
||||
http.createServer(app).listen(config.port);
|
||||
|
||||
setTimeout(function() {
|
||||
gutil.log('\n' + SEP + 'The "examples" webserver is listening on port: ' +
|
||||
gutil.colors.green(config.port) + '\n\n' +
|
||||
'http://localhost:' + config.port + '/examples/PATH_TO_EXAMPLE.html' +
|
||||
SEP);
|
||||
}, 1000);
|
||||
});
|
|
@ -0,0 +1,19 @@
|
|||
/*!
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
var gulp = require('gulp');
|
||||
|
||||
/*
|
||||
* Task: default
|
||||
*
|
||||
* The default gulp task for deployr.
|
||||
*/
|
||||
gulp.task('default', ['build']);
|
|
@ -0,0 +1,55 @@
|
|||
/*!
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
var gulp = require('gulp'),
|
||||
header = require('gulp-header'),
|
||||
config = require('../config.js'),
|
||||
pkg = config.pkg,
|
||||
banner = [
|
||||
'/*!',
|
||||
' * `<%= pkg.name %>` JavaScript Client Library v<%= pkg.version %>',
|
||||
' * <%= pkg.homepage %>',
|
||||
' *',
|
||||
' * Includes:',
|
||||
' * - superagent: https://github.com/visionmedia/superagent',
|
||||
' * - ws: https://github.com/einaros/ws',
|
||||
' * - D.js: http://malko.github.io/D.js',
|
||||
' *',
|
||||
' * Copyright (C) 2010-2014 by Revolution Analytics Inc.',
|
||||
' * Released under the Apache License 2.0',
|
||||
' * http://www.apache.org/licenses/LICENSE-2.0',
|
||||
' * Date: <%= date.today %>',
|
||||
'*/',
|
||||
''].join('\n');
|
||||
|
||||
|
||||
function today() {
|
||||
var today = new Date(),
|
||||
dd = today.getDate(),
|
||||
mm = today.getMonth() + 1, // January is 0
|
||||
yyyy = today.getFullYear();
|
||||
|
||||
if(dd < 10) { dd = '0' + dd; }
|
||||
if(mm < 10) { mm = '0' + mm; }
|
||||
|
||||
return yyyy + '-' + mm + '-' + dd;
|
||||
}
|
||||
|
||||
/*
|
||||
* Task: header
|
||||
*
|
||||
* Prefix the copyright information at the top.
|
||||
*/
|
||||
gulp.task('header', ['uglifyjs'], function() {
|
||||
return gulp.src(config.dist + '/*.js')
|
||||
.pipe(header(banner, { pkg : config.pkg, date: { today: today() } } ))
|
||||
.pipe(gulp.dest(config.dist));
|
||||
});
|
|
@ -0,0 +1,25 @@
|
|||
/*!
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
var gulp = require('gulp'),
|
||||
jshint = require("gulp-jshint"),
|
||||
config = require('../config');
|
||||
|
||||
/*
|
||||
* Task: jshist
|
||||
*
|
||||
* Lint's the entire `deployr` source.
|
||||
*/
|
||||
gulp.task('jshint', function () {
|
||||
return gulp.src([config.name + '.js', './lib*.js'])
|
||||
.pipe(jshint({lookup: true}))
|
||||
.pipe(jshint.reporter('default'));
|
||||
});
|
|
@ -0,0 +1,20 @@
|
|||
/*!
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
var gulp = require('gulp');
|
||||
|
||||
/*
|
||||
* Task: start
|
||||
*
|
||||
* Runs the build and starts the `Connect` HTTP server for viewing all the
|
||||
* ./examples HTML samples.
|
||||
*/
|
||||
gulp.task('start', ['connect']);
|
|
@ -0,0 +1,26 @@
|
|||
/*!
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
var gulp = require('gulp'),
|
||||
uglify = require('gulp-uglifyjs'),
|
||||
plumber = require('gulp-plumber'),
|
||||
onError = require('../util/handleErrors'),
|
||||
config = require('../config');
|
||||
|
||||
/*
|
||||
* Task: uglifyjs
|
||||
*/
|
||||
gulp.task('uglifyjs', ['browserify'], function() {
|
||||
return gulp.src(['./browser/deployr.js'])
|
||||
.pipe(plumber({ errorHandler: onError }))
|
||||
.pipe(uglify('deployr.min.js', { compress: false }))
|
||||
.pipe(gulp.dest('./browser/'));
|
||||
});
|
|
@ -0,0 +1,35 @@
|
|||
/*!
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
var gulp = require('gulp'),
|
||||
livereload = require('gulp-livereload'),
|
||||
config = require('../config');
|
||||
|
||||
/*
|
||||
* Task: examples-watch
|
||||
*
|
||||
* Primary task to watch other tasks for the ./examples samples.
|
||||
*/
|
||||
gulp.task('examples-watch', ['build'], function() {
|
||||
// LiveReload
|
||||
livereload.listen();
|
||||
|
||||
// Watch JS
|
||||
gulp.watch([config.name + '.js', './lib/*.js'], ['build']);
|
||||
|
||||
// Watch Examples that use HTML and livereload
|
||||
gulp.watch('./examples/**/*.html', ['html']);
|
||||
});
|
||||
|
||||
gulp.task('html', function() {
|
||||
return gulp.src(['./examples/**/*.html'])
|
||||
.pipe(livereload());
|
||||
});
|
|
@ -0,0 +1,16 @@
|
|||
/*!
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
var notify = require("gulp-util");
|
||||
|
||||
module.exports = function(err) {
|
||||
gutil.log(gutil.colors.green(err));
|
||||
};
|
|
@ -0,0 +1,16 @@
|
|||
/*!
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
var path = require("path");
|
||||
|
||||
module.exports = function(name) {
|
||||
return /(\.(js|coffee)$)/i.test(path.extname(name));
|
||||
};
|
|
@ -0,0 +1,12 @@
|
|||
/*!
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
require('./gulp');
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,116 @@
|
|||
/*!
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
var Base = require('./selfish').Base;
|
||||
|
||||
function debug(msg) { }
|
||||
|
||||
module.exports = Base.extend({
|
||||
|
||||
initialize: function() {
|
||||
this.events = {};
|
||||
this.scope = null;
|
||||
},
|
||||
|
||||
/**
|
||||
* Adds a listener. Multiple can be added per name. Aliased as `on`.
|
||||
*
|
||||
* @param {String} name The name of the event
|
||||
* @param {Function} handler A callback
|
||||
* @return {Emitter} `this` for chaining
|
||||
*/
|
||||
on: function(name, handler) {
|
||||
if (name in this.events === false) { this.events[name] = []; }
|
||||
|
||||
this.events[name].push(handler);
|
||||
debug('Emitter.on("' + name + '")');
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Triggers all matching listeners.
|
||||
*
|
||||
* @param {String} name The name of the event
|
||||
* @return {Emitter} `this` for chaining
|
||||
*/
|
||||
emit: function(name) {
|
||||
if (name in this.events === false) { return this; }
|
||||
|
||||
for (var i = 0; i < this.events[name].length; i++) {
|
||||
debug('Fired event: "' + name + '"');
|
||||
this.events[name][i].apply(this.scope || this, Array.prototype.slice.call(arguments, 1));
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Removes all matching listeners.
|
||||
*
|
||||
* @param {String} name The name of the event
|
||||
* @return {Emitter} `this` for chaining
|
||||
*/
|
||||
offAll: function(name) {
|
||||
if (!name) {
|
||||
for (var e in this.events) {
|
||||
delete this.events[e];
|
||||
}
|
||||
} else {
|
||||
if (name in this.events === false) { return this; }
|
||||
delete this.events[name];
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Removes a listener based on an index.
|
||||
*
|
||||
* @private
|
||||
* @param {String} name The name of the event
|
||||
* @param {Number} index The index of the event
|
||||
*/
|
||||
offAt: function(name, index) {
|
||||
var array = this.events[name],
|
||||
rest = array.slice(index + 1);
|
||||
|
||||
array.length = index;
|
||||
array.push.apply(array, rest);
|
||||
this.events[name] = array;
|
||||
},
|
||||
|
||||
/**
|
||||
* Removes a listener based on the handler function.
|
||||
*
|
||||
* @param {String} name The name of the event
|
||||
* @param {Function} handler The handler function to remove
|
||||
* @return {Emitter} `this` for chaining
|
||||
*/
|
||||
off: function(name, handler) {
|
||||
if (name in this.events === false) { return this; }
|
||||
|
||||
// remove all events handlers by this name
|
||||
if (!handler) {
|
||||
return this.offAll(name);
|
||||
} else { // remove all events handlers == 'handler' by this name
|
||||
for (var i = 0; i < this.events[name].length; i++) {
|
||||
if (this.events[name][i] == handler) {
|
||||
this.offAt(name, i);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
});
|
|
@ -0,0 +1,316 @@
|
|||
/*!
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
var Lang = require('./lang'),
|
||||
RTypes = require('./rtypes'),
|
||||
R = RTypes.r,
|
||||
DeployR = RTypes.deployr;
|
||||
|
||||
function formatDates(dates, type) {
|
||||
var formats = [];
|
||||
|
||||
for (var i = 0; i < dates.length; i++) {
|
||||
formats.push(formatDate(dates[i], type));
|
||||
}
|
||||
|
||||
return formats;
|
||||
}
|
||||
|
||||
function formatDate(date, type) {
|
||||
var year = date.getFullYear(),
|
||||
month = (date.getMonth() + 1),
|
||||
day = date.getDate(),
|
||||
hour = date.getHours(),
|
||||
min = date.getMinutes(),
|
||||
sec = date.getSeconds(),
|
||||
zone = date.getTimezoneOffset(),
|
||||
format = '';
|
||||
|
||||
month = (month < 10 ? '0' + month : month);
|
||||
hour = (hour < 10 ? '0' + hour : hour);
|
||||
min = (min < 10 ? '0' + min : min);
|
||||
sec = (sec < 10 ? '0' + sec : sec);
|
||||
format = year + '-' + month + '-' + day;
|
||||
|
||||
function leftZeroFill(number, targetLength, forceSign) {
|
||||
var output = '' + Math.abs(number),
|
||||
sign = number >= 0;
|
||||
|
||||
while (output.length < targetLength) {
|
||||
output = '0' + output;
|
||||
}
|
||||
return (sign ? (forceSign ? '+' : '') : '-') + output;
|
||||
}
|
||||
|
||||
if (type === DeployR.RPOSIX_DATE || type === DeployR.RPOSIX_DATE_VECTOR) {
|
||||
var time = hour + ':' + min + ':' + sec,
|
||||
a = -zone,
|
||||
b = "+";
|
||||
|
||||
if (a < 0) {
|
||||
a = -a;
|
||||
b = "-";
|
||||
}
|
||||
|
||||
zone = b + leftZeroFill((a / 60), 2) + '' + leftZeroFill(a % 60, 2);
|
||||
format += (' ' + time + ' ' + zone);
|
||||
}
|
||||
|
||||
return format;
|
||||
}
|
||||
|
||||
function encodeEmbeddedDataframe(obj, rdf) {
|
||||
var dfValue = obj.value;
|
||||
for (var index = 0; index < dfValue.length; index++) {
|
||||
var dfObj = dfValue[index];
|
||||
if (dfObj.type === DeployR.RDATAFRAME) {
|
||||
rdf = encodeEmbeddedDataframe(dfObj, rdf);
|
||||
} else {
|
||||
// format dates
|
||||
if (RTypes.isDate(dfObj.type)) {
|
||||
if (Lang.isArray(dfObj.value)) {
|
||||
dfObj.value = formatDates(dfObj.value, dfObj.type);
|
||||
} else {
|
||||
dfObj.value = formatDate(dfObj.value, dfObj.type);
|
||||
}
|
||||
}
|
||||
|
||||
dfObj.type = RTypes.deployrToR(dfObj.type);
|
||||
rdf.value.push(dfObj);
|
||||
}
|
||||
|
||||
}
|
||||
return rdf;
|
||||
};
|
||||
|
||||
function encodeDataframe(obj) {
|
||||
var rdf = {
|
||||
type: R.DATAFRAME,
|
||||
value: [],
|
||||
name: obj.name
|
||||
},
|
||||
dfValue = obj.value;
|
||||
|
||||
for (var index = 0; index < dfValue.length; index++) {
|
||||
var dfObj = dfValue[index];
|
||||
|
||||
if (dfObj.type === DeployR.RDATAFRAME) {
|
||||
rdf = encodeEmbeddedDataframe(dfObj, rdf);
|
||||
} else {
|
||||
// format dates
|
||||
if (RTypes.isDate(dfObj.type)) {
|
||||
if (Lang.isArray(dfObj.value)) {
|
||||
dfObj.value = formatDates(dfObj.value, dfObj.type);
|
||||
} else {
|
||||
dfObj.value = formatDate(dfObj.value, dfObj.type);
|
||||
}
|
||||
}
|
||||
|
||||
dfObj.type = RTypes.deployrToR(dfObj.type);
|
||||
rdf.value.push(dfObj);
|
||||
}
|
||||
|
||||
}
|
||||
return rdf;
|
||||
};
|
||||
|
||||
function encodeList(obj) {
|
||||
var rlist = {
|
||||
type: R.LIST,
|
||||
value: [],
|
||||
name: obj.name
|
||||
},
|
||||
dfValue = obj.value,
|
||||
r;
|
||||
|
||||
for (var index = 0; index < dfValue.length; index++) {
|
||||
var dfObj = dfValue[index];
|
||||
|
||||
switch (dfObj.type) {
|
||||
case DeployR.RDATAFRAME:
|
||||
r = encodeDataframe(dfObj);
|
||||
break;
|
||||
|
||||
case DeployR.RLIST:
|
||||
r = encodeList(dfObj);
|
||||
break;
|
||||
|
||||
case DeployR.RNUMERIC_MATRIX:
|
||||
case DeployR.RINTEGER_MATRIX:
|
||||
case DeployR.RBOOLEAN_MATRIX:
|
||||
case DeployR.RSTRING_MATRIX:
|
||||
r = {
|
||||
name: dfObj.name,
|
||||
type: R.MATRIX,
|
||||
value: dfObj.value
|
||||
};
|
||||
break;
|
||||
|
||||
case DeployR.RDATE:
|
||||
case DeployR.RPOSIX_DATE:
|
||||
r = {
|
||||
name: dfObj.name,
|
||||
type: R.DATE,
|
||||
format: dfObj.format,
|
||||
value: formatDate(dfObj.value, dfObj.type)
|
||||
};
|
||||
break;
|
||||
|
||||
case DeployR.RFACTOR:
|
||||
case DeployR.RORDERED:
|
||||
r = {
|
||||
name: dfObj.name,
|
||||
type: R.FACTOR,
|
||||
ordered: dfObj.ordered,
|
||||
labels: dfObj.labels,
|
||||
levels: dfObj.levels,
|
||||
value: dfObj.value
|
||||
};
|
||||
break;
|
||||
|
||||
case DeployR.RSTRING:
|
||||
case DeployR.RBOOLEAN:
|
||||
case DeployR.RNUMERIC:
|
||||
case DeployR.RINTEGER:
|
||||
r = {
|
||||
name: dfObj.name,
|
||||
type: R.PRIMITIVE,
|
||||
value: dfObj.value
|
||||
};
|
||||
break;
|
||||
|
||||
case DeployR.RNUMERIC_VECTOR:
|
||||
case DeployR.RINTEGER_VECTOR:
|
||||
case DeployR.RBOOLEAN_VECTOR:
|
||||
case DeployR.RSTRING_VECTOR:
|
||||
r = {
|
||||
name: dfObj.name,
|
||||
type: R.VECTOR,
|
||||
value: dfObj.value
|
||||
};
|
||||
break;
|
||||
|
||||
case DeployR.RDATE_VECTOR:
|
||||
case DeployR.RPOSIX_DATE_VECTOR:
|
||||
r = {
|
||||
name: dfObj.name,
|
||||
type: R.VECTOR,
|
||||
value: formatDates(dfObj.value, dfObj.type),
|
||||
format: dfObj.format
|
||||
};
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Error('No RDataType found for "' + dfObj.type + '"');
|
||||
break;
|
||||
}
|
||||
|
||||
rlist.value.push(r);
|
||||
}
|
||||
return rlist;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
|
||||
/**
|
||||
* Flattens a given <code>Revolution.RData</code> type into a JSON string
|
||||
* representing the
|
||||
* expected DeployR input format.
|
||||
*
|
||||
* @method parseInputs
|
||||
* @public
|
||||
* @param {Array} rdata An Array of RData Objects to be flattened.
|
||||
* @return {String} The flattend RData JSON string representing the DeployR
|
||||
* input format.
|
||||
*/
|
||||
encode: function(rdata) {
|
||||
var r = {};
|
||||
|
||||
for (var index = 0; index < rdata.length; index++) {
|
||||
var obj = rdata[index];
|
||||
|
||||
switch (obj.type) { // -- DeployR Type -- //
|
||||
|
||||
case DeployR.RDATAFRAME:
|
||||
r[obj.name] = encodeDataframe(obj);
|
||||
break;
|
||||
|
||||
case DeployR.RLIST:
|
||||
r[obj.name] = encodeList(obj);
|
||||
break;
|
||||
|
||||
case DeployR.RNUMERIC_MATRIX:
|
||||
case DeployR.RINTEGER_MATRIX:
|
||||
case DeployR.RBOOLEAN_MATRIX:
|
||||
case DeployR.RSTRING_MATRIX:
|
||||
r[obj.name] = {
|
||||
type: R.MATRIX,
|
||||
value: obj.value
|
||||
};
|
||||
break;
|
||||
|
||||
case DeployR.RDATE:
|
||||
case DeployR.RPOSIX_DATE:
|
||||
r[obj.name] = {
|
||||
type: R.DATE,
|
||||
format: obj.format,
|
||||
value: formatDate(obj.value, obj.type)
|
||||
};
|
||||
break;
|
||||
|
||||
case DeployR.RFACTOR:
|
||||
case DeployR.RORDERED:
|
||||
r[obj.name] = {
|
||||
type: R.FACTOR,
|
||||
ordered: obj.ordered,
|
||||
labels: obj.labels,
|
||||
levels: obj.levels,
|
||||
value: obj.value
|
||||
};
|
||||
break;
|
||||
|
||||
case DeployR.RSTRING:
|
||||
case DeployR.RBOOLEAN:
|
||||
case DeployR.RNUMERIC:
|
||||
case DeployR.RINTEGER:
|
||||
r[obj.name] = {
|
||||
type: R.PRIMITIVE,
|
||||
value: obj.value
|
||||
};
|
||||
break;
|
||||
|
||||
case DeployR.RNUMERIC_VECTOR:
|
||||
case DeployR.RINTEGER_VECTOR:
|
||||
case DeployR.RBOOLEAN_VECTOR:
|
||||
case DeployR.RSTRING_VECTOR:
|
||||
r[obj.name] = {
|
||||
type: R.VECTOR,
|
||||
value: obj.value
|
||||
};
|
||||
break;
|
||||
|
||||
case DeployR.RDATE_VECTOR:
|
||||
case DeployR.RPOSIX_DATE_VECTOR:
|
||||
r[obj.name] = {
|
||||
type: R.VECTOR,
|
||||
value: formatDates(obj.value, obj.type),
|
||||
format: obj.format
|
||||
};
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Error('No RDataType found for "' + obj.type + '"');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return (JSON.stringify(r));
|
||||
}
|
||||
};
|
|
@ -0,0 +1,157 @@
|
|||
var optional = require('./optional'),
|
||||
WS = optional('ws'),
|
||||
Queue = require('./queue'),
|
||||
Emitter = require('./emitter'),
|
||||
Base = require('./selfish').Base,
|
||||
merge = require('./utils').merge;
|
||||
|
||||
/**
|
||||
* Initialize a new `EventStream` with the given set of `options`.
|
||||
*
|
||||
* @param {Object} options
|
||||
* @api private
|
||||
*/
|
||||
var EventStream = Base.extend(Emitter, {
|
||||
|
||||
initialize: function initialize(host, options) {
|
||||
Emitter.initialize.call(this, {});
|
||||
|
||||
this.host = host;
|
||||
this.options = options || {};
|
||||
this.options.log = this.options.log || this.LOG.error;
|
||||
this.ws = null;
|
||||
this.q = new Queue();
|
||||
this.channel = {};
|
||||
},
|
||||
|
||||
LOG: {
|
||||
info: 'info',
|
||||
debug: 'debug',
|
||||
error: 'error'
|
||||
},
|
||||
|
||||
open: function(options) {
|
||||
var self = this,
|
||||
uri = (this.host || '') + '/deployr/r/event/stream?',
|
||||
params = [];
|
||||
|
||||
options = options || {};
|
||||
options.headers = options.headers || {};
|
||||
options = this.options = merge(options, this.channel);
|
||||
|
||||
this.cookies = !this.cookies ? options.headers.Cookie : this.cookies;
|
||||
|
||||
// -- append option parameters --
|
||||
if (options.project) {
|
||||
params.push('project=' + options.project);
|
||||
} else {
|
||||
if (options.job) {
|
||||
params.push('job=' + options.job);
|
||||
}
|
||||
}
|
||||
|
||||
if (options.management) {
|
||||
params.push('managementEventOnly=true');
|
||||
} else {
|
||||
if (options.httponly) {
|
||||
params.push('httpEventOnly=true');
|
||||
} else {
|
||||
if (options.revoonly) {
|
||||
params.push('revoEventOnly=true');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uri += params.join('&').substr(0);
|
||||
uri = uri.replace(/^http/,'ws');
|
||||
|
||||
this.q.yield(true);
|
||||
this.q.add(function() {
|
||||
|
||||
var headers = this.cookies ? { 'Cookie': this.cookies } : {};
|
||||
this.emit('es:connecting', { uri: uri, headers: headers });
|
||||
|
||||
var ws = new WS(uri, 'http', { headers: headers });
|
||||
|
||||
ws.onopen = function (message) {
|
||||
self.emit('es:open', message);
|
||||
};
|
||||
|
||||
var _message = '';
|
||||
ws.onmessage = function (message) {
|
||||
try {
|
||||
if (message.data.split('!|!')[1]) {
|
||||
_message = _message + message.data.split('!|!')[1];
|
||||
message = JSON.parse(_message);
|
||||
_message = '';
|
||||
var type = message.deployr.response.event.type;
|
||||
self.emit('es:' + type.replace('Event', ''), message);
|
||||
}
|
||||
} catch (e) {}
|
||||
};
|
||||
|
||||
ws.onerror = function (err) { self.emit('es:error', err); };
|
||||
ws.onclose = function (message) { self.emit('es:disconnect', message); };
|
||||
|
||||
this.ws = ws;
|
||||
}, this);
|
||||
|
||||
if (options.force) { this.flush(); }
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
close: function() {
|
||||
if (this.ws) { this.ws.close(); }
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
error: function(fn) {
|
||||
this.on('es:error', fn);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
all: function() {
|
||||
this.channel = { revoonly: true }; // revoEventOnly=true
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
session: function() {
|
||||
this.channel = { httponly: true }; //httpEventOnly=true
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
project: function(project) {
|
||||
this.channel = { project: project }; // project=12345
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
job: function(job) {
|
||||
this.channel = { job: job }; //job=12345
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
management: function() {
|
||||
this.channel = { management: true }; //managementEventOnly=true
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
flush: function() {
|
||||
this.q.yield(false);
|
||||
this.q.flush();
|
||||
},
|
||||
|
||||
share: function(cookies) {
|
||||
this.cookies = cookies;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
module.exports = EventStream;
|
|
@ -0,0 +1,143 @@
|
|||
/*!
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Provides core language utilites and extensions used throughout DeployR.
|
||||
*
|
||||
* @class Lang
|
||||
* @static
|
||||
*/
|
||||
var L = {},
|
||||
TOSTRING = Object.prototype.toString,
|
||||
TYPES = {
|
||||
'undefined' : 'undefined',
|
||||
'number' : 'number',
|
||||
'boolean' : 'boolean',
|
||||
'string' : 'string',
|
||||
'[object Function]' : 'function',
|
||||
'[object RegExp]' : 'regexp',
|
||||
'[object Array]' : 'array',
|
||||
'[object Date]' : 'date',
|
||||
'[object Error]' : 'error'
|
||||
}, unsafeNatives = false;
|
||||
|
||||
/**
|
||||
* Determines whether or not the provided item is null.
|
||||
* @method isNull
|
||||
* @static
|
||||
* @param o The object to test.
|
||||
* @return {boolean} true if o is null.
|
||||
*/
|
||||
L.isNull = function(o) {
|
||||
return o === null;
|
||||
};
|
||||
/**
|
||||
* Determines whether or not the provided item is undefined.
|
||||
* @method isUndefined
|
||||
* @static
|
||||
* @param o The object to test.
|
||||
* @return {boolean} true if o is undefined.
|
||||
*/
|
||||
L.isUndefined = function(o) {
|
||||
return typeof o === 'undefined';
|
||||
};
|
||||
/**
|
||||
* Determines whether or not the provided item is of type object
|
||||
* or function. Note that arrays are also objects, so
|
||||
* <code>Y.Lang.isObject([]) === true</code>.
|
||||
* @method isObject
|
||||
* @static
|
||||
* @param o The object to test.
|
||||
* @param failfn {boolean} fail if the input is a function.
|
||||
* @return {boolean} true if o is an object.
|
||||
* @see isPlainObject
|
||||
*/
|
||||
L.isObject = function(o, failfn) {
|
||||
var t = typeof o;
|
||||
return (o && (t === 'object' || (!failfn && (t === 'function' || L.isFunction(o))))) || false;
|
||||
};
|
||||
/**
|
||||
* Determines whether or not the provided item is an array.
|
||||
*
|
||||
* Returns `false` for array-like collections such as the function `arguments`
|
||||
* collection or `HTMLElement` collections.
|
||||
*
|
||||
* @method isArray
|
||||
* @param o The object to test.
|
||||
* @return {boolean} true if o is an array.
|
||||
* @static
|
||||
*/
|
||||
L.isArray = (!unsafeNatives && Array.isArray) ||
|
||||
function(o) {
|
||||
return L.type(o) === 'array';
|
||||
};
|
||||
|
||||
L.isFunction = function isFunctionA(o) {
|
||||
return (typeof(o) === "function");
|
||||
};
|
||||
|
||||
/**
|
||||
* Determines whether or not the provided item is a boolean.
|
||||
* @method isBoolean
|
||||
* @static
|
||||
* @param o The object to test.
|
||||
* @return {boolean} true if o is a boolean.
|
||||
*/
|
||||
L.isBoolean = function(o) {
|
||||
return typeof o === 'boolean';
|
||||
};
|
||||
|
||||
/**
|
||||
* Determines whether or not the supplied item is a date instance.
|
||||
* @method isDate
|
||||
* @static
|
||||
* @param o The object to test.
|
||||
* @return {boolean} true if o is a date.
|
||||
*/
|
||||
L.isDate = function(o) {
|
||||
return L.type(o) === 'date' && o.toString() !== 'Invalid Date' && !isNaN(o);
|
||||
};
|
||||
|
||||
/**
|
||||
* Determines whether or not the provided item is a legal number.
|
||||
* @method isNumber
|
||||
* @static
|
||||
* @param o The object to test.
|
||||
* @return {boolean} true if o is a number.
|
||||
*/
|
||||
L.isNumber = function(o) {
|
||||
return typeof o === 'number' && isFinite(o);
|
||||
};
|
||||
|
||||
/**
|
||||
* Determines whether or not the provided item is a string.
|
||||
* @method isString
|
||||
* @static
|
||||
* @param o The object to test.
|
||||
* @return {boolean} true if o is a string.
|
||||
*/
|
||||
L.isString = function(o) {
|
||||
return typeof o === 'string';
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a string representing the type of the item passed in.
|
||||
*
|
||||
* @method type
|
||||
* @param o the item to test.
|
||||
* @return {string} the detected type.
|
||||
* @static
|
||||
*/
|
||||
L.type = function(o) {
|
||||
return TYPES[ typeof o] || TYPES[TOSTRING.call(o)] || ( o ? 'object' : 'null');
|
||||
};
|
||||
|
||||
module.exports = L;
|
|
@ -0,0 +1,137 @@
|
|||
/*!
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
var Logger = {},
|
||||
loggerMap = {},
|
||||
globalLogger;
|
||||
|
||||
/**
|
||||
* Universal stdout|stderr printer
|
||||
*/
|
||||
function log(messages, context) {
|
||||
if (!console) { return; }
|
||||
|
||||
function sep(level) {
|
||||
var sep = '=========================================================' +
|
||||
'=========================================================\n',
|
||||
offset = 0;
|
||||
|
||||
if (level === Logger.DEBUG || level === Logger.ERROR) offset = 8;
|
||||
else if (level === Logger.INFO || level === Logger.WARN) offset = 8;
|
||||
else offset = 7;
|
||||
|
||||
return { start: sep.substring(offset), end: sep };
|
||||
}
|
||||
|
||||
var hdlr,
|
||||
args = Array.prototype.slice.call(messages, 0),
|
||||
name = context.name,
|
||||
error = context.level === Logger.ERROR,
|
||||
delim = sep(context.level);
|
||||
|
||||
if (context.level === Logger.WARN && console.warn) {
|
||||
hdlr = 'warn';
|
||||
} else if (context.level === Logger.ERROR && console.error) {
|
||||
hdlr = 'error';
|
||||
} else if (context.level === Logger.INFO && console.info) {
|
||||
hdlr = 'info';
|
||||
} else {
|
||||
hdlr = 'log';
|
||||
}
|
||||
|
||||
// -- custom format logging statement for deployr request/response/error --
|
||||
args.unshift('[' + (error ? Logger.ERROR.name : name) + '] ' + delim.start);
|
||||
args.push(delim.end);
|
||||
|
||||
console[hdlr](args[0], [args[1] + ' ---> ' + args[2]['call']]);
|
||||
|
||||
for (var i = 2; i < args.length; i++) { console.log(args[i]); }
|
||||
}
|
||||
|
||||
/**
|
||||
* Logging category by id.
|
||||
*/
|
||||
function Category(id, level, fn) {
|
||||
this.id = id;
|
||||
this.context = level || Logger.DEBUG;
|
||||
}
|
||||
|
||||
Category.prototype = {
|
||||
log: function(level, msgArgs) {
|
||||
if (level.value >= this.context.value) {
|
||||
log(msgArgs, {
|
||||
level: level,
|
||||
name: this.context.name,
|
||||
value: this.context.value
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
debug: function () {
|
||||
this.log(Logger.DEBUG, arguments);
|
||||
},
|
||||
|
||||
error: function () {
|
||||
this.log(Logger.ERROR, arguments);
|
||||
},
|
||||
|
||||
info: function () {
|
||||
this.log(Logger.INFO, arguments);
|
||||
},
|
||||
|
||||
warn: function () {
|
||||
this.log(Logger.WARN, arguments);
|
||||
},
|
||||
|
||||
setLevel: function(level) {
|
||||
if (level && 'value' in level) {
|
||||
this.context = level;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Logger.DEBUG = { value: 1, name: 'DEBUG' };
|
||||
Logger.INFO = { value: 2, name: 'INFO' };
|
||||
Logger.WARN = { value: 4, name: 'WARN' };
|
||||
Logger.ERROR = { value: 8, name: 'ERROR' };
|
||||
Logger.OFF = { value: 99, name: 'OFF' };
|
||||
|
||||
Logger.setLevel = function(newLevel) {
|
||||
globalLogger.setLevel(newLevel);
|
||||
};
|
||||
|
||||
Logger.debug = function () {
|
||||
globalLogger.debug.apply(globalLogger, arguments);
|
||||
};
|
||||
|
||||
Logger.info = function () {
|
||||
globalLogger.info.apply(globalLogger, arguments);
|
||||
};
|
||||
|
||||
Logger.warn = function () {
|
||||
globalLogger.warn.apply(globalLogger, arguments);
|
||||
};
|
||||
|
||||
Logger.error = function () {
|
||||
globalLogger.error.apply(globalLogger, arguments);
|
||||
};
|
||||
|
||||
Logger.get = function (id, level, fn) {
|
||||
return (loggerMap[id] || (function() {
|
||||
loggerMap[id] = new Category(id, level, fn);
|
||||
return loggerMap[id];
|
||||
})());
|
||||
};
|
||||
|
||||
// --- setup the global logger ---
|
||||
globalLogger = Logger.get('global');
|
||||
|
||||
module.exports = Logger;
|
|
@ -0,0 +1,21 @@
|
|||
/*!
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
function merge(to, from) {
|
||||
if (typeof(to) !== 'object') { to = {}; }
|
||||
if (typeof(from) !== 'object') { from = {}; }
|
||||
|
||||
for (var k in from) { to[k] = from[k]; }
|
||||
|
||||
return to;
|
||||
}
|
||||
|
||||
module.exports = merge;
|
|
@ -0,0 +1,16 @@
|
|||
/*!
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
module.exports = function(module) {
|
||||
try {
|
||||
return require(module);
|
||||
} catch (e) {}
|
||||
};
|
|
@ -0,0 +1,87 @@
|
|||
/*!
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
function Queue() {
|
||||
this.emptyCallback = null;
|
||||
this.callbacks = [];
|
||||
this.yielded = false;
|
||||
this.response = null;
|
||||
this.responseChain = [];
|
||||
}
|
||||
|
||||
Queue.prototype = {
|
||||
|
||||
add: function(fn, ctx, defer) {
|
||||
// currently not waiting and there is no defer delay just make call
|
||||
if (!this.yielded && !defer) {
|
||||
fn.apply(ctx || this, [this.response]);
|
||||
} else { // add to queue
|
||||
this.callbacks.push({ fn: fn, ctx: ctx });
|
||||
}
|
||||
},
|
||||
|
||||
size: function() {
|
||||
return this.callbacks.length;
|
||||
},
|
||||
|
||||
isEmpty: function() {
|
||||
return this.callbacks.length === 0;
|
||||
},
|
||||
|
||||
empty: function(fn, ctx) {
|
||||
this.emptyCallback = { fn: fn, ctx: ctx };
|
||||
},
|
||||
|
||||
yield: function(yield) {
|
||||
this.yielded = yield;
|
||||
},
|
||||
|
||||
take: function(response, error, args) {
|
||||
var cb;
|
||||
|
||||
if (response) {
|
||||
this.response = response;
|
||||
this.responseChain.push(response);
|
||||
}
|
||||
|
||||
|
||||
if (!this.yielded && this.callbacks[0]) {
|
||||
cb = this.callbacks.shift();
|
||||
cb.fn.apply(cb.ctx || this, [this.responseChain, error, args]);
|
||||
|
||||
// notify that the queue is now empty
|
||||
if (this.callbacks[0] && this.emptyCallback) {
|
||||
this.emptyCallback.fn.call(this.emptyCallback.ctx || this);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
flush: function(response, error, args) {
|
||||
if (response) {
|
||||
this.response = response;
|
||||
this.responseChain.push(response);
|
||||
}
|
||||
|
||||
// pop and call next inline
|
||||
while (this.callbacks[0]) {
|
||||
if (this.yielded) { break; }
|
||||
var cb = this.callbacks.shift();
|
||||
cb.fn.apply(cb.ctx || this, [this.responseChain, error, args]);
|
||||
|
||||
// notify that the queue is now empty
|
||||
if (this.callbacks[0] && this.emptyCallback) {
|
||||
this.emptyCallback.fn.call(this.emptyCallback.ctx || this);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = Queue;
|
|
@ -0,0 +1,226 @@
|
|||
/*!
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
var Base = require('./selfish').Base,
|
||||
RTypes = require('./rtypes');
|
||||
|
||||
module.exports = Base.extend(RTypes, {
|
||||
initialize: function initialize(name, value, options) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
this.options = options || {};
|
||||
},
|
||||
|
||||
numeric: function () {
|
||||
return this.assert({
|
||||
type: this.deployr.RNUMERIC,
|
||||
name: this.name,
|
||||
value: this.value,
|
||||
toString: this.toString
|
||||
});
|
||||
},
|
||||
|
||||
integer: function () {
|
||||
return this.assert({
|
||||
type: this.deployr.RINTEGER,
|
||||
name: this.name,
|
||||
value: this.value,
|
||||
toString: this.toString
|
||||
});
|
||||
},
|
||||
|
||||
logical: function () {
|
||||
return this.assert({
|
||||
type: this.deployr.RBOOLEAN,
|
||||
name: this.name,
|
||||
value: this.value,
|
||||
toString: this.toString
|
||||
});
|
||||
},
|
||||
|
||||
character: function () {
|
||||
return this.assert({
|
||||
type: this.deployr.RSTRING,
|
||||
name: this.name,
|
||||
value: this.value,
|
||||
toString: this.toString
|
||||
});
|
||||
},
|
||||
|
||||
date: function () {
|
||||
return this.assert({
|
||||
type: this.deployr.RDATE,
|
||||
name: this.name,
|
||||
value: this.value,
|
||||
format: 'yyyy-MM-dd',
|
||||
toString: this.toString
|
||||
});
|
||||
},
|
||||
|
||||
posixct: function () {
|
||||
return this.assert({
|
||||
type: this.deployr.RPOSIX_DATE,
|
||||
name: this.name,
|
||||
value: this.value,
|
||||
format: 'yyyy-MM-dd HH:mm:ss Z',
|
||||
toString: this.toString
|
||||
});
|
||||
},
|
||||
|
||||
numericVector: function () {
|
||||
return this.assert({
|
||||
type: this.deployr.RNUMERIC_VECTOR,
|
||||
name: this.name,
|
||||
value: this.value,
|
||||
toString: this.toString
|
||||
});
|
||||
},
|
||||
|
||||
integerVector: function () {
|
||||
return this.assert({
|
||||
type: this.deployr.RINTEGER_VECTOR,
|
||||
name: this.name,
|
||||
value: this.value,
|
||||
toString: this.toString
|
||||
});
|
||||
},
|
||||
|
||||
logicalVector: function () {
|
||||
return this.assert({
|
||||
type: this.deployr.RBOOLEAN_VECTOR,
|
||||
name: this.name,
|
||||
value: this.value,
|
||||
toString: this.toString
|
||||
});
|
||||
},
|
||||
|
||||
characterVector: function () {
|
||||
return this.assert({
|
||||
type: this.deployr.RSTRING_VECTOR,
|
||||
name: this.name,
|
||||
value: this.value,
|
||||
toString: this.toString
|
||||
});
|
||||
},
|
||||
|
||||
dateVector: function () {
|
||||
return this.assert({
|
||||
type: this.deployr.RDATE_VECTOR,
|
||||
name: this.name,
|
||||
value: this.value,
|
||||
format: 'yyyy-MM-dd',
|
||||
toString: this.toString
|
||||
});
|
||||
},
|
||||
|
||||
posixctVector: function () {
|
||||
return this.assert({
|
||||
type: this.deployr.RPOSIX_DATE_VECTOR,
|
||||
name: this.name,
|
||||
value: this.value,
|
||||
format: 'yyyy-MM-dd HH:mm:ss Z',
|
||||
toString: this.toString
|
||||
});
|
||||
},
|
||||
|
||||
list: function () {
|
||||
return this.assert({
|
||||
type: this.deployr.RLIST,
|
||||
name: this.name,
|
||||
value: this.value,
|
||||
toString: this.toString
|
||||
});
|
||||
},
|
||||
|
||||
dataframe: function () {
|
||||
return this.assert({
|
||||
type: this.deployr.RDATAFRAME,
|
||||
name: this.name,
|
||||
value: this.value,
|
||||
toString: this.toString
|
||||
});
|
||||
},
|
||||
|
||||
factor: function () {
|
||||
var opts = this.options;
|
||||
|
||||
return this.assert( {
|
||||
type: this.deployr.RFACTOR,
|
||||
name: this.name,
|
||||
value: this.value,
|
||||
ordered: false,
|
||||
levels: opts.levels,
|
||||
labels: opts.labels,
|
||||
toString: this.toString
|
||||
});
|
||||
},
|
||||
|
||||
ordered: function () {
|
||||
var opts = this.options;
|
||||
|
||||
return this.assert( {
|
||||
type: this.deployr.RORDERED,
|
||||
name: this.name,
|
||||
value: this.value,
|
||||
ordered: true,
|
||||
levels: opts.levels,
|
||||
labels: opts.labels,
|
||||
toString: this.toString
|
||||
});
|
||||
},
|
||||
|
||||
numericMatrix: function () {
|
||||
return this.assert({
|
||||
type: this.deployr.RNUMERIC_MATRIX,
|
||||
name: this.name,
|
||||
value: this.value,
|
||||
toString: this.toString
|
||||
});
|
||||
},
|
||||
|
||||
integerMatrix: function () {
|
||||
return this.assert({
|
||||
type: this.deployr.RINTEGER_MATRIX,
|
||||
name: this.name,
|
||||
value: this.value,
|
||||
toString: this.toString
|
||||
});
|
||||
},
|
||||
|
||||
logicalMatrix: function () {
|
||||
return this.assert({
|
||||
type: this.deployr.RBOOLEAN_MATRIX,
|
||||
name: this.name,
|
||||
value: this.value,
|
||||
toString: this.toString
|
||||
});
|
||||
},
|
||||
|
||||
characterMatrix: function () {
|
||||
return this.assert({
|
||||
type: this.deployr.RSTRING_MATRIX,
|
||||
name: this.name,
|
||||
value: this.value,
|
||||
toString: this.toString
|
||||
});
|
||||
},
|
||||
|
||||
toString: function() {
|
||||
var opts = this.options || {},
|
||||
levels = opts.levels ? '[ levels = ' + opts.levels + ']' : '',
|
||||
labels = opts.labels ? '[ labels = ' + opts.labels + ']' : '';
|
||||
|
||||
return '[ name = ' + this.name + ' ] ' +
|
||||
'[ value = ' + this.value + ' ] ' +
|
||||
'[ type = ' + this.type + ' ] ' +
|
||||
levels + labels;
|
||||
}
|
||||
});
|
|
@ -0,0 +1,135 @@
|
|||
/*!
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
var Base = require('./selfish').Base,
|
||||
RTypes = require('./rtypes'),
|
||||
Lang = require('./lang'),
|
||||
RInput = require('./rinput');
|
||||
|
||||
function create(type, name, value, options) {
|
||||
var rinput;
|
||||
|
||||
if (Lang.isObject(name)) {
|
||||
rinput = name;
|
||||
if (!rinput.type !== type) {
|
||||
throw new Error('IllegalArgumentError:' +
|
||||
'Expecting "' + type + '" but found "' + rinput.type + '"');
|
||||
}
|
||||
} else {
|
||||
rinput = RInput.new(name, value, options)[type]();
|
||||
}
|
||||
|
||||
return rinput;
|
||||
}
|
||||
|
||||
module.exports = Base.extend(RTypes, {
|
||||
numeric: function (name, value) {
|
||||
this.inputs.push(create(this.deployr.RNUMERIC, name, value));
|
||||
return this;
|
||||
},
|
||||
|
||||
integer: function (name, value) {
|
||||
this.inputs.push(create(this.deployr.RINTEGER, name, value));
|
||||
return this;
|
||||
},
|
||||
|
||||
logical: function (name, value) {
|
||||
this.inputs.push(create(this.deployr.RBOOLEAN, name, value));
|
||||
return this;
|
||||
},
|
||||
|
||||
character: function (name, value) {
|
||||
this.inputs.push(create(this.deployr.RSTRING, name, value));
|
||||
return this;
|
||||
},
|
||||
|
||||
date: function (name, value) {
|
||||
this.inputs.push(create(this.deployr.RDATE, name, value));
|
||||
return this;
|
||||
},
|
||||
|
||||
posixct: function (name, value) {
|
||||
this.inputs.push(create(this.deployr.RPOSIX_DATE, name, value));
|
||||
return this;
|
||||
},
|
||||
|
||||
numericVector: function (name, value) {
|
||||
this.inputs.push(create(this.deployr.RNUMERIC_VECTOR, name, value));
|
||||
return this;
|
||||
},
|
||||
|
||||
integerVector: function (name, value) {
|
||||
this.inputs.push(create(this.deployr.RINTEGER_VECTOR, name, value));
|
||||
return this;
|
||||
},
|
||||
|
||||
logicalVector: function (name, value) {
|
||||
this.inputs.push(create(this.deployr.RBOOLEAN_VECTOR, name, value));
|
||||
return this;
|
||||
},
|
||||
|
||||
characterVector: function (name, value) {
|
||||
this.inputs.push(create(this.deployr.RSTRING_VECTOR, name, value));
|
||||
return this;
|
||||
},
|
||||
|
||||
dateVector: function (name, value) {
|
||||
this.inputs.push(create(this.deployr.RDATE_VECTOR, name, value));
|
||||
return this;
|
||||
},
|
||||
|
||||
posixctVector: function (name, value) {
|
||||
this.inputs.push(create(this.deployr.RPOSIX_DATE_VECTOR, name, value));
|
||||
return this;
|
||||
},
|
||||
|
||||
list: function (name, value) {
|
||||
this.inputs.push(create(this.deployr.RLIST, name, value));
|
||||
return this;
|
||||
},
|
||||
|
||||
dataframe: function (name, value) {
|
||||
this.inputs.push(create(this.deployr.RDATAFRAME, name, value));
|
||||
return this;
|
||||
},
|
||||
|
||||
factor: function (name, value, levels, labels) {
|
||||
var opts = { levels: levels, labels: labels };
|
||||
this.inputs.push(create(this.deployr.RFACTOR, name, value, opts));
|
||||
return this;
|
||||
},
|
||||
|
||||
ordered: function (name, value, levels, labels) {
|
||||
var opts = { levels: levels, labels: labels };
|
||||
this.inputs.push(create(this.deployr.RORDERED, name, value, opts));
|
||||
return this;
|
||||
},
|
||||
|
||||
numericMatrix: function (name, value) {
|
||||
this.inputs.push(create(this.deployr.RNUMERIC_MATRIX, name, value));
|
||||
return this;
|
||||
},
|
||||
|
||||
integerMatrix: function (name, value) {
|
||||
this.inputs.push(create(this.deployr.RINTEGER_MATRIX, name, value));
|
||||
return this;
|
||||
},
|
||||
|
||||
logicalMatrix: function (name, value) {
|
||||
this.inputs.push(create(this.deployr.RBOOLEAN_MATRIX, name, value));
|
||||
return this;
|
||||
},
|
||||
|
||||
characterMatrix: function (name, value) {
|
||||
this.inputs.push(create(this.deployr.RSTRING_MATRIX, name, value));
|
||||
return this;
|
||||
}
|
||||
});
|
|
@ -0,0 +1,155 @@
|
|||
/*!
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
var Base = require('./selfish').Base,
|
||||
Lang = require('./lang'),
|
||||
map = {}; // deployr->To->R catalog
|
||||
|
||||
module.exports = Base.extend({
|
||||
r: {
|
||||
PRIMITIVE: 'primitive',
|
||||
DATAFRAME: 'dataframe',
|
||||
LIST: 'list',
|
||||
MATRIX: 'matrix',
|
||||
DATE: 'date',
|
||||
FACTOR: 'factor',
|
||||
VECTOR: 'vector'
|
||||
},
|
||||
|
||||
deployr: {
|
||||
RBOOLEAN: 'logical',
|
||||
RNUMERIC: 'numeric',
|
||||
RINTEGER: 'integer',
|
||||
RSTRING: 'character',
|
||||
RDATE: 'date',
|
||||
RPOSIX_DATE: 'posixct',
|
||||
RBOOLEAN_VECTOR: 'logicalVector',
|
||||
RNUMERIC_VECTOR:'numericVector',
|
||||
RINTEGER_VECTOR: 'integerVector',
|
||||
RSTRING_VECTOR: 'characterVector',
|
||||
RDATE_VECTOR: 'dateVector',
|
||||
RPOSIX_DATE_VECTOR: 'posixctVector',
|
||||
RLIST: 'list',
|
||||
RDATAFRAME: 'dataframe',
|
||||
RFACTOR: 'factor',
|
||||
RORDERED: 'ordered',
|
||||
RBOOLEAN_MATRIX: 'logicalMatrix',
|
||||
RNUMERIC_MATRIX: 'numericMatrix',
|
||||
RINTEGER_MATRIX: 'integerMatrix',
|
||||
RSTRING_MATRIX: 'characterMatrix'
|
||||
},
|
||||
|
||||
isDate: function(type) {
|
||||
return (type === this.deployr.RDATE ||
|
||||
type === this.deployr.RPOSIX_DATE ||
|
||||
type === this.deployr.RDATE_VECTOR ||
|
||||
type === this.deployr.RPOSIX_DATE_VECTOR ||
|
||||
type === this.r.DATE);
|
||||
},
|
||||
|
||||
deployrToR: function(type) {
|
||||
var deployr = this.deployr,
|
||||
r = this.r;
|
||||
|
||||
if (!map[type]) { // build catalog only once
|
||||
map[deployr.RBOOLEAN] = r.PRIMITIVE;
|
||||
map[deployr.RNUMERIC] = r.PRIMITIVE;
|
||||
map[deployr.RINTEGER] = r.PRIMITIVE;
|
||||
map[deployr.RSTRING] = r.PRIMITIVE;
|
||||
map[deployr.RDATE] = r.DATE;
|
||||
map[deployr.RPOSIX_DATE] = r.DATE;
|
||||
map[deployr.RBOOLEAN_VECTOR] = r.VECTOR;
|
||||
map[deployr.RNUMERIC_VECTOR] = r.VECTOR;
|
||||
map[deployr.RINTEGER_VECTOR] = r.VECTOR;
|
||||
map[deployr.RSTRING_VECTOR] = r.VECTOR;
|
||||
map[deployr.RDATE_VECTOR] = r.VECTOR;
|
||||
map[deployr.RPOSIX_DATE_VECTOR] = r.VECTOR;
|
||||
map[deployr.RLIST] = r.LIST;
|
||||
map[deployr.RDATAFRAME] = r.DATAFRAME;
|
||||
map[deployr.RFACTOR] = r.FACTOR;
|
||||
map[deployr.RORDERED] = r.FACTOR;
|
||||
map[deployr.RBOOLEAN_MATRIX] = r.MATRIX;
|
||||
map[deployr.RNUMERIC_MATRIX] = r.MATRIX;
|
||||
map[deployr.RINTEGER_MATRIX] = r.MATRIX;
|
||||
map[deployr.RSTRING_MATRIX] = r.MATRIX;
|
||||
}
|
||||
|
||||
return map[type];
|
||||
},
|
||||
|
||||
/**
|
||||
* Assert that the `rinput` value is the correct JavaScript Data Type.
|
||||
*/
|
||||
assert: function (rinput) {
|
||||
var deployr = this.deployr,
|
||||
NOOP = null,
|
||||
values = rinput.value,
|
||||
fn;
|
||||
|
||||
values = !Lang.isArray(values) ? [values] : values;
|
||||
|
||||
for (var i = 0; i < values.length; i++) {
|
||||
var value = values[i];
|
||||
|
||||
switch (rinput.type) {
|
||||
case deployr.RNUMERIC :
|
||||
case deployr.RNUMERIC_VECTOR :
|
||||
case deployr.RNUMERIC_VECTOR :
|
||||
fn = Lang.isNumber;
|
||||
// support string numbers
|
||||
var val = parseFloat(value);
|
||||
value = isNaN(val) ? value : val;
|
||||
break;
|
||||
|
||||
case deployr.RINTEGER :
|
||||
case deployr.RINTEGER_VECTOR :
|
||||
fn = Lang.isNumber;
|
||||
// support string numbers
|
||||
var val = parseFloat(value);
|
||||
value = isNaN(val) ? value : val;
|
||||
break;
|
||||
|
||||
case deployr.RBOOLEAN :
|
||||
case deployr.RBOOLEAN_VECTOR :
|
||||
fn = Lang.isBoolean;
|
||||
break;
|
||||
|
||||
case deployr.RSTRING :
|
||||
case deployr.RSTRING_VECTOR :
|
||||
fn = Lang.isString;
|
||||
break;
|
||||
|
||||
case deployr.RDATE :
|
||||
case deployr.RPOSIX_DATE :
|
||||
case deployr.RDATE_VECTOR :
|
||||
case deployr.RPOSIX_DATE_VECTOR :
|
||||
fn = Lang.isDate;
|
||||
break;
|
||||
|
||||
case deployr.RFACTOR :
|
||||
case deployr.RORDERED :
|
||||
case deployr.RDATAFRAME :
|
||||
case deployr.RINTEGER_MATRIX :
|
||||
case deployr.RBOOLEAN_MATRIX :
|
||||
case deployr.RSTRING_MATRIX :
|
||||
fn = NOOP;
|
||||
break
|
||||
}
|
||||
|
||||
if (fn && !fn(value)) {
|
||||
throw new Error('RInputFormatError: ' + '"' + value +
|
||||
'" is not a valid "' + rinput.type + '" type.');
|
||||
}
|
||||
}
|
||||
|
||||
return rinput;
|
||||
}
|
||||
});
|
|
@ -0,0 +1,160 @@
|
|||
/*!
|
||||
* https://github.com/Gozala/selfish
|
||||
*/
|
||||
|
||||
/* vim:set ts=2 sw=2 sts=2 expandtab */
|
||||
/*jshint undef: true es5: true node: true devel: true evil: true
|
||||
forin: true latedef: false supernew: true */
|
||||
/*global define: true */
|
||||
|
||||
!(typeof define !== "function" ? function($){ $(null, typeof exports !== 'undefined' ? exports : window); } : define)(function(require, exports) {
|
||||
|
||||
"use strict";
|
||||
|
||||
exports.Base = Object.freeze(Object.create(Object.prototype, {
|
||||
/**
|
||||
* Creates an object that inherits from `this` object (Analog of
|
||||
* `new Object()`).
|
||||
* @examples
|
||||
*
|
||||
* var Dog = Base.extend({
|
||||
* bark: function bark() {
|
||||
* return 'Ruff! Ruff!'
|
||||
* }
|
||||
* });
|
||||
* var dog = Dog.new();
|
||||
*/
|
||||
'new': { value: function create() {
|
||||
var object = Object.create(this);
|
||||
object.initialize.apply(object, arguments);
|
||||
return object;
|
||||
}},
|
||||
/**
|
||||
* When new instance of the this prototype is created it's `initialize`
|
||||
* method is called with all the arguments passed to the `new`. You can
|
||||
* override `initialize` to set up an instance.
|
||||
*/
|
||||
initialize: { value: function initialize() {
|
||||
}},
|
||||
/**
|
||||
* Merges all the properties of the passed objects into `this` instance (This
|
||||
* method can be used on instances only as prototype objects are frozen).
|
||||
*
|
||||
* If two or more argument objects have own properties with the same name,
|
||||
* the property is overridden, with precedence from right to left, implying,
|
||||
* that properties of the object on the left are overridden by a same named
|
||||
* property of the object on the right.
|
||||
*
|
||||
* @examples
|
||||
*
|
||||
* var Pet = Dog.extend({
|
||||
* initialize: function initialize(options) {
|
||||
* // this.name = options.name -> would have thrown (frozen prototype)
|
||||
* this.merge(options) // will override all properties.
|
||||
* },
|
||||
* call: function(name) {
|
||||
* return this.name === name ? this.bark() : ''
|
||||
* },
|
||||
* name: null
|
||||
* })
|
||||
* var pet = Pet.new({ name: 'Benzy', breed: 'Labrador' })
|
||||
* pet.call('Benzy') // 'Ruff! Ruff!'
|
||||
*/
|
||||
merge: { value: function merge() {
|
||||
var descriptor = {};
|
||||
Array.prototype.forEach.call(arguments, function (properties) {
|
||||
Object.getOwnPropertyNames(properties).forEach(function(name) {
|
||||
descriptor[name] = Object.getOwnPropertyDescriptor(properties, name);
|
||||
});
|
||||
});
|
||||
Object.defineProperties(this, descriptor);
|
||||
return this;
|
||||
}},
|
||||
/**
|
||||
* Takes any number of argument objects and returns frozen, composite object
|
||||
* that inherits from `this` object and combines all of the own properties of
|
||||
* the argument objects. (Objects returned by this function are frozen as
|
||||
* they are intended to be used as types).
|
||||
*
|
||||
* If two or more argument objects have own properties with the same name,
|
||||
* the property is overridden, with precedence from right to left, implying,
|
||||
* that properties of the object on the left are overridden by a same named
|
||||
* property of the object on the right.
|
||||
* @examples
|
||||
*
|
||||
* // ## Object composition ##
|
||||
*
|
||||
* var HEX = Base.extend({
|
||||
* hex: function hex() {
|
||||
* return '#' + this.color;
|
||||
* }
|
||||
* })
|
||||
*
|
||||
* var RGB = Base.extend({
|
||||
* red: function red() {
|
||||
* return parseInt(this.color.substr(0, 2), 16);
|
||||
* },
|
||||
* green: function green() {
|
||||
* return parseInt(this.color.substr(2, 2), 16);
|
||||
* },
|
||||
* blue: function blue() {
|
||||
* return parseInt(this.color.substr(4, 2), 16);
|
||||
* }
|
||||
* })
|
||||
*
|
||||
* var CMYK = Base.extend(RGB, {
|
||||
* black: function black() {
|
||||
* var color = Math.max(Math.max(this.red(), this.green()), this.blue());
|
||||
* return (1 - color / 255).toFixed(4);
|
||||
* },
|
||||
* cyan: function cyan() {
|
||||
* var K = this.black();
|
||||
* return (((1 - this.red() / 255).toFixed(4) - K) / (1 - K)).toFixed(4);
|
||||
* },
|
||||
* magenta: function magenta() {
|
||||
* var K = this.black();
|
||||
* return (((1 - this.green() / 255).toFixed(4) - K) / (1 - K)).toFixed(4);
|
||||
* },
|
||||
* yellow: function yellow() {
|
||||
* var K = this.black();
|
||||
* return (((1 - this.blue() / 255).toFixed(4) - K) / (1 - K)).toFixed(4);
|
||||
* }
|
||||
* })
|
||||
*
|
||||
* var Color = Base.extend(HEX, RGB, CMYK, {
|
||||
* initialize: function Color(color) {
|
||||
* this.color = color;
|
||||
* }
|
||||
* });
|
||||
*
|
||||
* // ## Prototypal inheritance ##
|
||||
*
|
||||
* var Pixel = Color.extend({
|
||||
* initialize: function Pixel(x, y, hex) {
|
||||
* Color.initialize.call(this, hex);
|
||||
* this.x = x;
|
||||
* this.y = y;
|
||||
* },
|
||||
* toString: function toString() {
|
||||
* return this.x + ':' + this.y + '@' + this.hex();
|
||||
* }
|
||||
* });
|
||||
*
|
||||
* var pixel = Pixel.new(11, 23, 'CC3399')
|
||||
* pixel.toString(); // 11:23@#CC3399
|
||||
*
|
||||
* pixel.red(); // 204
|
||||
* pixel.green(); // 51
|
||||
* pixel.blue(); // 153
|
||||
*
|
||||
* pixel.cyan(); // 0.0000
|
||||
* pixel.magenta(); // 0.7500
|
||||
* pixel.yellow(); // 0.2500
|
||||
*
|
||||
*/
|
||||
extend: { value: function extend() {
|
||||
return Object.freeze(this.merge.apply(Object.create(this), arguments));
|
||||
}}
|
||||
}));
|
||||
|
||||
});
|
|
@ -0,0 +1,119 @@
|
|||
/*!
|
||||
* Copyright (C) 2010-2014 by Revolution Analytics Inc.
|
||||
*
|
||||
* This program is licensed to you under the terms of Version 2.0 of the
|
||||
* Apache License. This program is distributed WITHOUT
|
||||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
|
||||
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
var Lang = require('./lang');
|
||||
|
||||
var get = exports.get = function(s, key) {
|
||||
function traverse(obj, fn, parent) {
|
||||
for (var i in obj) {
|
||||
var result = fn.apply(this, [i, obj[i], parent]);
|
||||
if (result) {
|
||||
return result;
|
||||
} else {
|
||||
if (obj[i] instanceof Object && !(obj[i] instanceof Array)) {
|
||||
traverse(obj[i], fn, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getProperty(obj, property) {
|
||||
var acc = {};
|
||||
traverse(obj, function(key, value, parent) {
|
||||
if (key === property) {
|
||||
acc = value;
|
||||
return acc;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
return acc;
|
||||
}
|
||||
|
||||
function empty(obj) {
|
||||
for (var prop in obj) { if (obj.hasOwnProperty(prop)) return obj; }
|
||||
return !Lang.isObject(obj) ? obj : null;
|
||||
}
|
||||
|
||||
return empty(getProperty(s, key));
|
||||
};
|
||||
|
||||
var inArray = exports.inArray = function(haystack, needle, key) {
|
||||
var i, max = haystack.length;
|
||||
|
||||
for (i = 0; i < max; i++) {
|
||||
if (key) {
|
||||
if (haystack[i][key] === needle) { return haystack[i]; }
|
||||
} else {
|
||||
if (haystack[i] === needle) { return haystack[i]; }
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
exports.merge = function(to, from) {
|
||||
if (!to || typeof(to) !== 'object') { to = {}; }
|
||||
if (!from || typeof(from) !== 'object') { from = {}; }
|
||||
|
||||
for (var k in from) { to[k] = from[k]; }
|
||||
|
||||
return to;
|
||||
};
|
||||
|
||||
exports.workspace = function(obj, name) {
|
||||
var ws = get(obj, 'workspace');
|
||||
return (ws ? name ? inArray(ws.objects, name, 'name') : ws.objects || ws.object: null);
|
||||
};
|
||||
|
||||
exports.signature = function() {
|
||||
var args = Array.prototype.slice.call(arguments['0'], 0),
|
||||
len = args.length,
|
||||
api,
|
||||
opts = {};
|
||||
|
||||
if (len === 1 && Lang.isObject(args[0])) {
|
||||
opts = args[0];
|
||||
api = opts.project ? '/r/project/execute/script' :
|
||||
'/r/repository/script/execute';
|
||||
} else if (len === 1 && Lang.isString(args[0])) {
|
||||
args = args[0].split('\/');
|
||||
api = '/r/repository/script/execute'
|
||||
opts = {
|
||||
author: args[1],
|
||||
directory: args[2],
|
||||
filename: args[3]
|
||||
};
|
||||
} else if (len === 2) {
|
||||
//deployr.script('/testuser/root/DeployR - Hello World.R', project)
|
||||
var project = args[1];
|
||||
api = project ? '/r/project/execute/script' : '/r/repository/script/execute';
|
||||
|
||||
args = args[0].split('\/');
|
||||
opts = {
|
||||
project: project,
|
||||
author: args[1],
|
||||
directory: args[2],
|
||||
filename: args[3]
|
||||
};
|
||||
} else if (len > 2) {
|
||||
// deployr.script('DeployR - Hello World.R', 'testuser', 'root')
|
||||
opts = {
|
||||
author: args[2],
|
||||
directory: args[1],
|
||||
filename: args[0]
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
api: api,
|
||||
opts: opts
|
||||
};
|
||||
};
|
|
@ -0,0 +1,49 @@
|
|||
{
|
||||
"name": "deployr",
|
||||
"version": "7.3.0",
|
||||
"description": "Simplified JavaScript client library for making requests to DeployR.",
|
||||
"private": true,
|
||||
"keywords": [
|
||||
"deployr",
|
||||
"deployr.io",
|
||||
"ajax",
|
||||
"R",
|
||||
"api",
|
||||
"simple"
|
||||
],
|
||||
"author": "DeployR - Revolution Analytics Inc.",
|
||||
"contributors": [{
|
||||
"name": "Sean Wells"
|
||||
}],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/deployr/js-client-library.git"
|
||||
},
|
||||
"homepage": "http://deployr.revolutionanalytics.com/documents/dev/client-jsdoc",
|
||||
"scripts": {
|
||||
"start": "gulp start"
|
||||
},
|
||||
"devDependencies": {
|
||||
"browserify-shim": "~3.4.1",
|
||||
"browserify": "~3.36.0",
|
||||
"vinyl-source-stream": "~0.1.1",
|
||||
"connect": "~2.14.3",
|
||||
"gulp": "^3.8.8",
|
||||
"gulp-uglifyjs": "~0.4.2",
|
||||
"gulp-plumber": "~0.6.4",
|
||||
"gulp-util": "~2.2.20",
|
||||
"gulp-livereload": "~2.1.0",
|
||||
"gulp-jshint": "^1.7.1",
|
||||
"gulp-header": "^1.1.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"superagent": "^0.18.0",
|
||||
"d.js": "^0.6.0",
|
||||
"ws": "^0.4.32"
|
||||
},
|
||||
"main": "deployr.js",
|
||||
"engines": {
|
||||
"node": ">= 0.10.0"
|
||||
},
|
||||
"license": "Apache 2.0 License"
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
Tests
|
||||
=====
|
||||
|
||||
Coming soon...
|
Загрузка…
Ссылка в новой задаче