Skip to content

Instantly share code, notes, and snippets.

@adam-phillipps
Created May 25, 2013 19:33
Show Gist options
  • Save adam-phillipps/5650473 to your computer and use it in GitHub Desktop.
Save adam-phillipps/5650473 to your computer and use it in GitHub Desktop.
@token = tokens[@token] if tokens[@token]
if tokens[@token] (if there's a matching token in hash, use it)
@token = tokens[@token] (if not, leave it alone)
end
tokens = {
'PORTAL ADMIN' => "1~R6LQJOPqzOWXQfLYDTnWXXC8rBnzlfcD9yatg004A7kQlkpEKSk8GtDGERhAJ86K"
'PORTAL TEACHER' => "1~4HqG8O8JN1f8H94IkhMYgjxD8LlEcNosQ0AJ7ET3Wh78X54fS6Be3mFHHnMiuiJs"
'PORTAL TOKEN' => "1~R6LQJOPqzOWXQfLYDTnWXXC8rBnzlfcD9yatg004A7kQlkpEKSk8GtDGERhAJ86K"
'PORTAL AT TOKEN' => "1~4HqG8O8JN1f8H94IkhMYgjxD8LlEcNosQ0AJ7ET3Wh78X54fS6Be3mFHHnMiuiJs"
'LOCAL TOKEN' => "1~KtP1voLOAsUkIgqum0qfMZl7N9PaQQhsI9vAhii0UgASIUDW40belLlk0Bhm8Mmi"
'BETA TOKEN' => "1~gBl5tEyJ1jcCe8onAgO7rOhp8lo9fm2omVbYISciCa8BrKFJndmTqkUtNdWrJQoF"
}
urls = {
'portal url' => "54.243.66.130"
'local url' => "http://localhost:3000"
'beta url' => "http://adam.beta.instructure.com"
}
'RECIPIENT' => 2
@number = 0
@account = ''
@token = ''
@url = ''
@recipient = 0
@body = ''
@user_response = ''
#add password protection for tokens
puts "****WARNING: AT THIS TIME, NO PRODUCTION TESTING MAY BE DONE DUE TO SECURITY RISKS****"
puts "*****UNLESS YOU SUPPLY YOUR OWN TOKEN.*****"
def token
puts "****What user (token) will you be sending the conversation with?*******"
puts "****Portal Admin, Portal Teacher, Local Admin, Beta Admin, Other? *******"
@token = gets.to_s.strip!
@token = tokens[@token.upcase] if tokens[@token.upcase]
def url
puts "What URL are you testing against: "
puts "Portal, Local, Beta, Production, Other? "
@url = gets.to_s.strip!
@url = urls[@url.downcase] if urls[@url.downcase]
end
def account
puts "What account do you want users created in? If you don't know, type 1a"
@account = gets.to_i.strip!
if @account = 1a
puts ""
end
end
def tester_selection
print "Number of conversations generated: "
@number = gets.to_i
end
def recipient_selection
print "Who you want the conversations to go to: "
@recipient = gets.to_i
end
def create_users (token, url, account, name, login)
post = "curl -H 'Authorization: Bearer #{token}' \'#{url}/api/v1/accounts/#{@account}/users' \-F 'user[name]=#{@counter}'
\-F 'pseudonym[unique_id]=#{@counter}' \-F 'pseudonym[password]=password' \-X POST"
result = %x[#{post}]
result.to_s
end
def body
Random.new.rand(1..99999999).to_s
end
def create_conversations (token, url, recipients, body)
post = "curl -H 'Authorization: Bearer #{token}' \'#{url}/api/v1/conversations' \-F 'recipients[]=#{recipients}' \-F 'body=#{body}' \-X POST"
result = %x[#{post}]
result.to_s
end
token
url
account
tester_selection
@number.times do |f|
create_users(@account, @url, @account, f + 1, f + 1)
create_conversations(@token, @url, @recipient)
puts f.to_i
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment