Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save adam-phillipps/5632804 to your computer and use it in GitHub Desktop.
Save adam-phillipps/5632804 to your computer and use it in GitHub Desktop.
This one includes creating a user and a converstation. it still needs to find a way to generate a unique token that complies with canvas and can be updated in the db for each user and entered back in the script. The tokens need to match the users that they were matched up with in the db....gonna be fun.
1 PORTAL_TOKEN = "1~R6LQJOPqzOWXQfLYDTnWXXC8rBnzlfcD9yatg004A7kQlkpEKSk8GtDGERhAJ86K"
2 PORTAL_AT_TOKEN = "1~4HqG8O8JN1f8H94IkhMYgjxD8LlEcNosQ0AJ7ET3Wh78X54fS6Be3mFHHnMiuiJs"
3 LOCAL_TOKEN = "1~KtP1voLOAsUkIgqum0qfMZl7N9PaQQhsI9vAhii0UgASIUDW40belLlk0Bhm8Mmi"
4 BETA_TOKEN = "1~gBl5tEyJ1jcCe8onAgO7rOhp8lo9fm2omVbYISciCa8BrKFJndmTqkUtNdWrJQoF"
5 PORTAL_URL = "54.243.66.130"
6 LOCAL_URL = "http://localhost:3000"
7 BETA_URL = "http://adam.beta.instructure.com"
8 RECIPIENT = "2"
9 @selection = ''
10 @account = ''
11 @counter = ''
12
13 def account
14 print "The account you're testing against: "
15 @account = gets.to_s
16 end
17
18 def tester_selection
19 print "Number of users and conversatoins generated: "
20 @selection = gets.to_i
21 end
22
23 def login_password_creator
24 @counter = 0...@selection
25 end
26
27 def create_users (token, url, account, name, login)
28 post = "curl -H 'Authorization: Bearer #{token}' \'#{url}/api/v1/accounts/#{@account}/users' \-F 'user[name]=#{@counter}'
29 \-F 'pseudonym[unique_id]=#{@counter}' \-F 'pseudonym[password]=password' \-X POST"
30 result = %x[#{post}]
31 result.to_s
32 end
33
34 def body
35 Random.new.rand(1..99999999).to_s
36 end
37
38 def create_conversations (token, url, recipients)
39 post = "curl -H 'Authorization: Bearer #{token}' \'#{url}/api/v1/conversations' \-F 'recipients[]=#{recipients}' \-F 'b=#{body}' \-X POST"
40
41 result = %x[#{post}]
42 result.to_s
43 end
44
45 @selection.times do |f|
46 create_users(PORTAL_TOKEN, PORTAL_URL, @account, @counter, @counter)
47 create_conversations(PORTAL_TOKEN, PORTAL_URL, RECIPIENT)
48 puts f.to_i
49 end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment