Created
May 24, 2013 04:54
-
-
Save adam-phillipps/5641340 to your computer and use it in GitHub Desktop.
Stops working when I enter in the token.
adam-2:scripts adam$ ruby create_conversations_attempt2.rb
WARNING: AT THIS TIME, NO PRODUCTION TESTING MAY BE DONE DUE TO SECURITY RISKS
UNLESS YOU SUPPLY YOUR OWN TOKEN.
What user (token) will you be sending the conversation with?
Portal Admin, Portal Teacher, Local Admin, Beta Admin, Other?
PORTAL
Tell…
This file contains 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
PORTAL_TOKEN = "1~R6LQJOPqzOWXQfLYDTnWXXC8rBnzlfcD9yatg004A7kQlkpEKSk8GtDGERhAJ86K" | |
PORTAL_AT_TOKEN = "1~4HqG8O8JN1f8H94IkhMYgjxD8LlEcNosQ0AJ7ET3Wh78X54fS6Be3mFHHnMiuiJs" | |
LOCAL_TOKEN = "1~KtP1voLOAsUkIgqum0qfMZl7N9PaQQhsI9vAhii0UgASIUDW40belLlk0Bhm8Mmi" | |
BETA_TOKEN = "1~gBl5tEyJ1jcCe8onAgO7rOhp8lo9fm2omVbYISciCa8BrKFJndmTqkUtNdWrJQoF" | |
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 = '' | |
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.upcase | |
if @token == "PORTAL" | |
@token = PORTAL_TOKEN | |
elseif @account == "LOCAL" | |
@token = LOCAL_TOKEN | |
elseif @account == "BETA" | |
@token = BETA_TOKEN | |
elseif @url == "PRODUCTION" | |
@token = PROD_TOKEN | |
else | |
puts "Tell me the token you'll be using" | |
@token = gets.to.s | |
end | |
end | |
def url | |
puts "What URL are you testing against: " | |
puts "Portal, Local, Beta, Production, Other? " | |
@url = gets.to_s.upcase | |
if @url == "PORTAL" | |
@url = PORTAL_URL | |
elseif @url == "LOCAL" | |
@url = LOCAL_URL | |
elseif @url == "BETA" | |
@url = BETA_URL | |
elseif @url == "PRODUCTION" | |
@url = PROD_URL | |
else | |
puts "Tell me the full URL, including http:// and finishing just before%n" | |
puts "the first backslash.%n e.g. http://canvas.instructure.com" | |
@url = gets.to.s | |
end | |
end | |
def account | |
puts "What account are you testing against: " | |
puts "Portal, Local, Beta, Production, Other? " | |
@account = gets.to_s.upcase | |
if @account == "PORTAL" | |
@account = PORTAL_URL | |
elseif @account == "LOCAL" | |
@account = LOCAL_URL | |
elseif @account == "BETA" | |
@account = BETA_URL | |
elseif @account == "PRODUCTION" | |
@account = PROD_URL | |
else | |
print "Tell me the account id." | |
@account = gets.to.s | |
end | |
end | |
def tester_selection | |
print "Number of users and conversatoins 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 | |
@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