Skip to content

Instantly share code, notes, and snippets.

@j-mcnally
Last active August 29, 2015 14:16
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save j-mcnally/0e30bb4a7fa14e01c224 to your computer and use it in GitHub Desktop.
Save j-mcnally/0e30bb4a7fa14e01c224 to your computer and use it in GitHub Desktop.
Automate Slack invites, for slack chat / community websites. Used by http://struct.tv
module Slack
class Invite
def call(options)
email = options[:email]
throw "You must call this method with an email" unless email.present?
invite = agent.post("https://#{ENV['SLACK_SUBDOMAIN']}.slack.com/api/users.admin.invite?t=#{Time.now.to_i}",
{"email" => email,
"token" => ENV['SLACK_API_TOKEN'],
"set_active" => "true",
"_attempts" => "1"
}
)
return invite.body
end
def agent
@agent ||= Mechanize.new
end
end
end
@j-mcnally
Copy link
Author

You might be able to just pass a pre-generated api token, but i was having problems getting it to work.

@smathy
Copy link

smathy commented Mar 22, 2015

I think you meant raise on line 5, not throw

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment