Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 70 additions & 1 deletion lib/methodLayer/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,73 @@ var util = require('util')
// query = can pass query
// all with query have default values

// will probably need to impliment with streams
// will probably need to impliment with streams

getForUser = function (client,query,callback) {
var path = urlB.host('api').object('events').url
client.get(path,callback)
}

export.getForUser = getForUser
getForEnterprise = function (client,query,callback) {
var path = urlB.host('api').object('events').url + '?stream_type=admin_logs'
client.get(path,callback)
}
exports.getForEnterprise = getForEnterprise
longPolling = function (client,query,callback) {
var path = urlB.host('api').object('events').url
client.options(path,callback)
}
exports.longPolling = longPolling

pollStreamWrapper = function (client,query,opt){

req = function(reqPath,caller) {
client.options(reqPath,function (response,statcode){
var response = JSON.stringify(response)
switch(response.message){
case 'reconnect':
process.nextTick(req(reqPath,caller))
break
case 'new_change':
client.get(caller.path + '?' + caller.admin + caller.limit +'stream_position=' + caller.streamPosition, function (res,sc) {
var res = JSON.stringify(res)
caller.streamPosition = res.next_Stream_position
for(entry in res.entries){
push(entry)
}
process.nextTick(req(reqPath,caller))
})
break
default:
throw new Error('Unknown response')
}
})
}

streamer = function (client,query,opt){
if(typeof query == 'undefined' || query == null) throw new Error("'query' can't be undefined or null, pass {} for no queryies")
this.path = urlB.host('api').object('events').url
this.streamPath = ''
this.streamPosition = query.streamPosition || 0
this.admin = query.admin == true ? 'stream_type=admin_logs&' : ''
this.limit = 'limit=' + query.limit + '&' || ''
client.get(this.path + '?stream_position='(this.streamPosition || 'now'), function (response,statcode) {
this.streamPosition = JSON.stringify(response).next_Stream_position
client.options(path,function (response,statcode){
this.streamPath = JSON.stringify(response).url
})
})
Readable.call(this, opt)
}

util.inherits(streamer,stream.Readable)

streamer.prototype._read() {
process.nextTick(req(this.streamPath,this))
}

return new streamer(client,query,opt)
}

exports.streamer = pollStreamWrapper
9 changes: 9 additions & 0 deletions lib/modules/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ var client = {
this.headers = func.getHeaders(this.aToken, 'get',{user : this.user})
func.makeRequest(callb, this.path, null, this.headers,'get')
},
options:function (path, callb, extraHeader) {
var headerKeys = Object.keys(extraHeader)
for(var i=0; i<headerKeys.length;i++){
this.headers[headerKeys[i]] = extraHeader[i]
}
this.path = path
this.headers = func.getHeaders(this.aToken, 'get',{user : this.user})
func.makeRequest(callb, this.path, null, this.headers,'options')
}
post:function (path, data, callb) {
this.path = path
this.headers = func.getHeaders(this.aToken,'post',{user : this.user})
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name" : "boxsdk",
"preferGlobal" : false,
"version" : "0.2.10",
"version" : "0.2.11",
"author" : "Thermatix <mbeckerwork@gmail.com>",
"description" : "An SDK to make using the BOX API easier",
"contributors" :[],
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The client can be used to make Oauth easier, do get,post,put and delete calls an

##Authentication
First make a client builder and pass the app ID and secret.
##

<i>The client Builder should be outside of any requests, that way it's accessible from all requests; it's there so you don't have to give the client your appID and secret each time you need it.</i>
###Setup Client Factory:
```javascript
Expand Down Expand Up @@ -211,7 +211,7 @@ Functions implemented are:
- Files (all functions)
- Comments (all functions)
- Collaborations (all functions)
- Events (no functions)
- Events (all functions (streamer is available but untested))
- Search (all functions)
- Users (all functions)
- Groups (all functions)
Expand Down