Permalink
Browse files

fix to brains

class methods can't be called inside callback functions, but local /
global? variables and functions can be called
  • Loading branch information...
1 parent 05c8b1d commit ad6d85b1f42cb3e36c1bdb8a612a3669714e9ea0 @markomanninen committed Nov 19, 2011
Showing with 8 additions and 7 deletions.
  1. +3 −3 lib/widgets/Hubot.js
  2. +1 −1 package.json
  3. +4 −3 src/widgets/Hubot.coffee
View
@@ -82,12 +82,12 @@
};
Hubot.prototype.set_access_token = function(robot, msg, api, service) {
- var access_token_extract;
+ var access_token_extract, brains;
+ brains = this.init_robot_brains(robot, api);
access_token_extract = function(response) {
- var brains, token;
+ var token;
console.log('Response: ' + response.data);
token = service.api.getAccessTokenExtractor()(response.data);
- brains = this.init_robot_brains(robot, api);
if (brains['access_token'] = token.getToken()) {
console.log('Access token set: ' + brains['access_token']);
if (service.getVersion() === "2.0") {
View
@@ -2,7 +2,7 @@
"name": "scribe-node",
"description": "Scribe java OAuth library port to node.js",
"author": "Marko Manninen <mmstud@gmail.com> (http://about.me/markomanninen)",
- "version": "0.0.10",
+ "version": "0.0.11",
"homepage": "https://github.com/mmstud/scribe-node",
"keywords": ["scribe","oauth","web2.0","node.js","coffeescript","java","google","api"],
"licenses": [{
View
@@ -26,7 +26,7 @@ class root.Hubot
robot.brain.data.oauth = []
robot.brain.data.oauth[api] = []
else if not robot.brain.data.oauth[api]
- robot.brain.data.oauth[api] = []
+ robot.brain.data.oauth[api] = []
return robot.brain.data.oauth[api]
get_authorization_url: (robot, msg, api) ->
@@ -41,7 +41,7 @@ class root.Hubot
console.log 'Response: ' + response.data
token = service.api.getRequestTokenExtractor() response.data
url = service.getAuthorizationUrl token
- msg.send "Authorization url: "+url
+ msg.send "Authorization url: " + url
brains['request_token'] = token.getToken()
brains['request_secret'] = token.getSecret()
console.log "Request token set: " + brains['request_token']
@@ -56,10 +56,11 @@ class root.Hubot
new scribe.Verifier robot.brain.data.oauth[api]['code']
set_access_token: (robot, msg, api, service) ->
+ # this (@) references cant be used inside callback functions, but variables (local) can be used
+ brains = @init_robot_brains robot, api
access_token_extract = (response) ->
console.log 'Response: ' + response.data
token = service.api.getAccessTokenExtractor() response.data
- brains = @init_robot_brains robot, api
if brains['access_token'] = token.getToken()
console.log 'Access token set: ' + brains['access_token']
# access secret is not really needed on OAuth 2.0 scheme. expires, type and refresh tokens are instead

0 comments on commit ad6d85b

Please sign in to comment.