Skip to content

Commit 481d08e

Browse files
committedMar 28, 2016
Add push/post/fetch/pull methods
Signed-off-by: Eric Windisch <[email protected]>
1 parent babf674 commit 481d08e

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
 

‎js/iopipe.js

+32
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ var url = require('url')
3232
var request = require("request")
3333
var vm = require('vm')
3434
var path = require('path')
35+
var crypto = require('crypto')
3536

3637
var local_driver = require('./exec_drivers/local/index.js')
3738

@@ -147,6 +148,37 @@ IOpipe.prototype.make_context = function(done) {
147148
return ctx
148149
}
149150

151+
IOpipe.prototype.post_function = function(data, callback) {
152+
this.define(base + '/v0/filters/',
153+
iopipe.make_context(callback))(data)
154+
}
155+
156+
IOpipe.prototype.fetch_function = function(id, callback) {
157+
this.fetch(base + '/v0/filters/' + id, function(func) {
158+
const hash = crypto.createHash('sha256');
159+
hash.update(func)
160+
var hex = hash.digest('hex')
161+
if (hex !== id) {
162+
throw "Error"
163+
}
164+
callback(input)
165+
})
166+
}
167+
168+
IOpipe.prototype.pull_function = function(id, callback) {
169+
var iopipe = this
170+
this.fetch_function(id, function(func) {
171+
iopipe._exec_driver.CreateFunction(func, callback)
172+
})
173+
}
174+
175+
IOpipe.prototype.push_function = function(id, callback) {
176+
var iopipe = this
177+
this._exec_driver.GetFunction(id, function(func) {
178+
iopipe.post_function(func, callback)
179+
})
180+
}
181+
150182
/**
151183
@description
152184
Defines a pipeline, returning a function.

0 commit comments

Comments
 (0)