Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- !#/urs/bin/ruby
- require 'rubygems'
- require 'restclient'
- require 'json'
- asi_uri = ""
- password = ""
- #logging in as client
- response = RestClient.post asi_uri + '/session', {:session => { :app_name => "aaltoapps", :app_password => password}}
- cookie = response.cookies
- #creating a new user
- response = RestClient.post asi_uri + '/people', {:person => { :username => "aaltoapps_user", :password => "testi", :email => "apps@example.com", :is_association=>"false", :consent => "FI1"}}, {:cookies => cookie}
- #log out
- response = RestClient.delete asi_uri + '/session', { :cookies => cookie}
- #logging in as client
- response = RestClient.post asi_uri + '/session', {:session => { :app_name => "aaltoapps", :app_password => password}}
- cookie = response.cookies
- #creating a new user
- #showing what happens when user creation has duplicate information with previous user
- begin
- response = RestClient.post asi_uri + '/people', {:person => { :username => "aaltoapps_user2", :password => "testi", :email => "apps@example.com", :is_association=>"false", :consent => "FI1"}}, {:cookies => cookie}
- rescue RestClient::RequestFailed => e
- puts e.response
- end
- response = RestClient.post asi_uri + '/people', {:person => { :username => "aaltoapps_user2", :password => "testi", :email => "apps2@example.com", :is_association=>"false", :consent => "FI1"}}, {:cookies => cookie}
- cookie = response.cookie
- #modifying user info
- response = RestClient.put asi_uri + '/people/@me/@self', { :person => { :name => { :given_name => "Aalto", :family_name => "Apps"}}}, { :cookies => cookie}
- #log out
- response = RestClient.delete asi_uri + '/session', { :cookies => cookie}
- #log in
- response = RestClient.post asi_uri + '/session', {:session => { :app_name => "aaltoapps", :app_password => password, :username => "aaltoapps_user", :password => "testi"}}
- cookie = response.cookies
- #find a user
- response = RestClient.get asi_uri + '/people?search=aaltoapps_user2', { :cookies => cookie}
- id = JSON.parse(response)["entry"][0]["id"]
- #ask friendship
- response = RestClient.post asi_uri + 'people/@me/@friends', { :friend_id => id }, { :cookies => cookie}
- response.code
- #log out
- response = RestClient.delete asi_uri + '/session', { :cookies => cookie}
- #log in
- response = RestClient.post asi_uri + '/session', {:session => { :app_name => "aaltoapps", :app_password => password, :username => "aaltoapps_user2", :password => "testi"}}
- cookie = response.cookies
- #Show pending friend requests
- response = RestClient.get asi_uri + '/people/@me/@pending_friend_requests', { :cookies => cookie}
Add Comment
Please, Sign In to add comment