Created
April 19, 2014 07:44
-
-
Save mimosa/11077136 to your computer and use it in GitHub Desktop.
发送邀请码。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# user_id = '522d3cf8a57cbb890f000005' | |
# send_invites(user_id, secret: 'android', desc: '郑州见面会专用。', welcome: '感谢您使用收留我App。') | |
# send_invites(user_id, { secret: 'android', limit: 50 }, 2) | |
def send_invites(user_id, opts={}, num=1) | |
u = User.find(user_id) | |
return false if u.nil? | |
opts.symbolize_keys! | |
return false if opts[:secret].nil? | |
1.upto(num) { |i| | |
u.invites.create( | |
secret: opts[:secret], | |
desc: opts[:desc] || '', | |
welcome: opts[:welcome] || '', | |
code: opts[:code], | |
limit: opts[:limit] || 1, | |
started_at: opts[:started_at] || Time.now, | |
expired_at: opts[:expired_at], | |
) | |
} | |
true | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment