Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slack improvements #479

Merged
merged 4 commits into from
Feb 10, 2015
Merged
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
29 changes: 18 additions & 11 deletions social/backends/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,18 @@ def get_user_details(self, response):

# Build the username with the team $username@$team_url
# Necessary to get unique names for all of slack
match = re.search("//([^.]+)\.slack\.com", response["team_url"])
username = "%s@%s" % (response.get("name"), match.group(1))
match = re.search("//([^.]+)\.slack\.com", response["url"])
username = "%s@%s" % (response.get("user"), match.group(1))

return {'username': username,
'email': response["profile"].get('email', ''),
out = {'username': username}
if response.get("profile"):
out.update({
'email': response["profile"].get("email"),
'fullname': response["profile"].get("real_name"),
'first_name': response["profile"].get("first_name"),
'last_name': response["profile"].get("last_name")
}
})
return out

def user_data(self, access_token, *args, **kwargs):
"""Loads user data from service"""
Expand All @@ -44,17 +47,21 @@ def user_data(self, access_token, *args, **kwargs):
auth_test = self.get_json('https://slack.com/api/auth.test', params={
'token': access_token
})
out = auth_test
del out["ok"]

# https://api.slack.com/methods/users.info
data = self.get_json('https://slack.com/api/users.info', params={
user_info = self.get_json('https://slack.com/api/users.info', params={
'token': access_token,
'user': auth_test.get("user_id")
})

# Inject the team data
out = data["user"].copy()
out["team_id"] = auth_test.get("team_id")
out["team"] = auth_test.get("team")
out["team_url"] = auth_test.get("url")
if user_info.get("user"):
# Capture the user data, if available based on the scope
out.update(user_info["user"])

# Clean up user_id vs id
out["id"] = out["user_id"]
del out["user_id"]

return out