Skip to content

Commit

Permalink
Merge pull request #9 from stephenyeargin/fix-approve
Browse files Browse the repository at this point in the history
Fix friend request approval
  • Loading branch information
stephenyeargin authored Oct 13, 2016
2 parents bc27365 + 14a53df commit 3a16542
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"url": "https://github.com/stephenyeargin/hubot-fitbit-leaders/issues"
},
"dependencies": {
"fitbit-node": "^2.0.1",
"fitbit-node": "^2.0.2",
"moment": "^2.14.1"
},
"devDependencies": {
Expand Down
12 changes: 7 additions & 5 deletions src/hubot-fitbit-leaders.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# Fitbit leaderboards
#
# Dependencies:
# "fitbit-js": "0.2.0"
# "fitbit-node": "^2.0.2",
# "moment": "^2.14.1"
#
# Configuration:
# FITBIT_CLIENT_ID
Expand Down Expand Up @@ -54,7 +55,7 @@ module.exports = (robot) ->
robot.respond /fitbit friends/i, (msg) ->
Fitbit.get('/friends.json', accessToken)
.then (res) ->
robot.logger.debug res
robot.logger.debug getResponseBody(res)
friends = getResponseBody(res).friends
if friends.length > 0
list = []
Expand All @@ -70,7 +71,7 @@ module.exports = (robot) ->
robot.respond /fitbit register/i, (msg) ->
Fitbit.get('/profile.json', accessToken)
.then (res) ->
robot.logger.debug res
robot.logger.debug getResponseBody(res)
user = getResponseBody(res).user
unless user.fullName
user.fullName = 'the bot'
Expand All @@ -82,7 +83,7 @@ module.exports = (robot) ->
robot.respond /fitbit approve/i, (msg) ->
Fitbit.get('/friends/invitations.json', accessToken)
.then (res) ->
robot.logger.debug res
robot.logger.debug getResponseBody(res)
if getResponseBody(res).friends.length is 0
msg.send "No pending requests."
return
Expand All @@ -91,6 +92,7 @@ module.exports = (robot) ->
accept: true
Fitbit.post("/friends/invitations/#{friend.user.encodedId}.json", accessToken, params)
.then (res) ->
robot.logger.debug getResponseBody(res)
msg.send "Approve: #{friend.user.displayName}"
.catch (error) ->
displayErrors(error, msg)
Expand All @@ -101,7 +103,7 @@ module.exports = (robot) ->
try
Fitbit.get('/friends/leaderboard.json', accessToken)
.then (res) ->
robot.logger.debug res
robot.logger.debug getResponseBody(res)
leaders = getResponseBody(res).friends
sortedleaders = []
for own key, leader of leaders
Expand Down

0 comments on commit 3a16542

Please sign in to comment.