Skip to content

Instantly share code, notes, and snippets.

@adam-phillipps
Created June 11, 2013 21:31
Show Gist options
  • Save adam-phillipps/5760891 to your computer and use it in GitHub Desktop.
Save adam-phillipps/5760891 to your computer and use it in GitHub Desktop.
v2 create conversations/users. need token
1 tokens = {
2 'PORTAL ADMIN' => "1~R6LQJOPqzOWXQfLYDTnWXXC8rBnzlfcD9yatg004A7kQlkpEKSk8GtDGERhAJ86K"
3 'PORTAL TEACHER' => "1~4HqG8O8JN1f8H94IkhMYgjxD8LlEcNosQ0AJ7ET3Wh78X54fS6Be3mFHHnMiuiJs"
4 'PORTAL TOKEN' => "1~R6LQJOPqzOWXQfLYDTnWXXC8rBnzlfcD9yatg004A7kQlkpEKSk8GtDGERhAJ86K"
5 'PORTAL AT TOKEN' => "1~4HqG8O8JN1f8H94IkhMYgjxD8LlEcNosQ0AJ7ET3Wh78X54fS6Be3mFHHnMiuiJs"
6 'LOCAL TOKEN' => "1~KtP1voLOAsUkIgqum0qfMZl7N9PaQQhsI9vAhii0UgASIUDW40belLlk0Bhm8Mmi"
7 'BETA TOKEN' => "1~gBl5tEyJ1jcCe8onAgO7rOhp8lo9fm2omVbYISciCa8BrKFJndmTqkUtNdWrJQoF"
8 }
9
10 urls = {
11 'portal url' => "54.243.66.130"
12 'local url' => "http://localhost:3000"
13 'beta url' => "http://adam.beta.instructure.com"
14 }
15
16 'RECIPIENT' => 2
17
18 @number = 0
19 @account = ''
20 @token = ''
21 @url = ''
22 @recipient = 0
23 @body = ''
24 @user_response = ''
25
26
27 #add password protection for tokens
28
29 puts "****WARNING: AT THIS TIME, NO PRODUCTION TESTING MAY BE DONE DUE TO SECURITY RISKS****"
30 puts "*****UNLESS YOU SUPPLY YOUR OWN TOKEN.*****"
31
32 def token
33 puts "****What user (token) will you be sending the conversation with?*******"
34 puts "****Portal Admin, Portal Teacher, Local Admin, Beta Admin, Other? *******"
35 @token = gets.to_s.strip!
36 @token = tokens[@token.upcase] if tokens[@token.upcase]
37
38
39
40 def url
41 puts "What URL are you testing against: "
42 puts "Portal, Local, Beta, Production, Other? "
43 @url = gets.to_s.strip!
44 @url = urls[@url.downcase] if urls[@url.downcase]
45 end
46
47
48 def account
49 puts "What account do you want users created in? If you don't know, type 1a"
50 @account = gets.to_i.strip!
51 if @account = 1a
52 puts ""
53 end
54 end
55
56
57
58 def tester_selection
59 print "Number of conversations generated: "
60 @number = gets.to_i
61 end
62
63
64
65 def recipient_selection
66 print "Who you want the conversations to go to: "
67 @recipient = gets.to_i
68 end
69
70
71
72
73 def create_users (token, url, account, name, login)
74 post = "curl -H 'Authorization: Bearer #{token}' \'#{url}/api/v1/accounts/#{@account}/users' \-F 'user[name]=#{@counter}'
75 \-F 'pseudonym[unique_id]=#{@counter}' \-F 'pseudonym[password]=password' \-X POST"
76 result = %x[#{post}]
77 result.to_s
78 end
79
80
81
82 def body
83 Random.new.rand(1..99999999).to_s
84 end
85
86
87
88 def create_conversations (token, url, recipients, body)
89 post = "curl -H 'Authorization: Bearer #{token}' \'#{url}/api/v1/conversations' \-F 'recipients[]=#{recipients}' \-F 'body=#{body}' \-X POST"
90
91 result = %x[#{post}]
92 result.to_s
93 end
94
95
96 token
97
98 url
99
100 account
101
102 tester_selection
103
104 @number.times do |f|
105 create_users(@account, @url, @account, f + 1, f + 1)
106 create_conversations(@token, @url, @recipient)
107 puts f.to_i
108 end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment