Class: WindowsLiveAdmin
- Inherits:
-
Object
- Object
- WindowsLiveAdmin
- Includes:
- Templates
- Defined in:
- lib/windows_live_admin.rb
Overview
This creates an windows admin live account instance. The object instantiated will have various member/user/email manipulation methods.
Instance Method Summary collapse
-
#create_member(member_name, password, reset_password, first_name, last_name, lcid = nil) ⇒ Array
This method will add a member to the specified domain and provision an email account The member name is a email id of the member.
-
#delete_member(member_name) ⇒ Array
This method will delete a member given her member_name (email id).
-
#get_auth_data(login_url, login_template) ⇒ String
Fetches auth data by posting the login_template (got from call to get_login_template) to login_url (got from call to get_login_url).
-
#get_login_data_template ⇒ String
Fetches the login template from the server and replaces it with admin’s username and password.
-
#get_login_url ⇒ String
Fetches the login URl where the template needs to be posted to obtain the auth_data (token).
-
#initialize(username, password) ⇒ WindowsLiveAdmin
constructor
Constructor of the WindowsLiveAdmin class.
-
#verify_auth_data ⇒ String
Verifies if the auth_data obtained from the previous calls to get_auth_data is valid.
Methods included from Templates
#create_member_xml, #delete_member_xml, #get_login_data_template_xml, #get_login_url_xml, #verify_auth_data_xml
Constructor Details
#initialize(username, password) ⇒ WindowsLiveAdmin
Constructor of the WindowsLiveAdmin class. Inits class variables @username and @password and makes HTTP calls to get login url and login template. Thereafter obtains auth_data by get_auth_data call
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/windows_live_admin.rb', line 15 def initialize(username, password) @username = username @password = password begin login_url = get_login_url login_template = get_login_data_template @auth_data = get_auth_data(login_url, login_template) rescue @auth_data = nil # nil auth_data signifies there was an error in the login process end end |
Instance Method Details
#create_member(member_name, password, reset_password, first_name, last_name, lcid = nil) ⇒ Array
This method will add a member to the specified domain and provision an email account The member name is a email id of the member. Note that the corresponding domain should be already manually added and configured in the windows admin live center by logging on to the web interface.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/windows_live_admin.rb', line 100 def create_member(member_name, password, reset_password, first_name, last_name, lcid=nil) http, request = get_request_headers("http://domains.live.com/Service/ManageDomain/V1.0/CreateMember") request.body = create_member_xml(member_name, password, reset_password, first_name, last_name, lcid) #puts request.body response = http.request(request) # puts response.body error = is_error?(response.body) # if response is an error xml, error string describes the error if error # Response XML had in error node called ErrorDescription return [false, error] else # Absence of ErrorDescription node is taken as success return [true, "Member #{first_name} #{last_name} (#{member_name}) successfully created."] end end |
#delete_member(member_name) ⇒ Array
This method will delete a member given her member_name (email id)
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/windows_live_admin.rb', line 122 def delete_member(member_name) http, request = get_request_headers("http://domains.live.com/Service/ManageDomain/V1.0/DeleteMember") request.body = delete_member_xml(member_name) #puts request.body response = http.request(request) # puts response.body error = is_error?(response.body) # if response is an error, error is a string describing the error if error # Response XML had in error node called ErrorDescription return [false, error] else # Absence of ErrorDescription node is taken as success return [true, "Member #{member_name} successfully deleted."] end end |
#get_auth_data(login_url, login_template) ⇒ String
Fetches auth data by posting the login_template (got from call to get_login_template) to login_url (got from call to get_login_url)
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/windows_live_admin.rb', line 57 def get_auth_data(login_url, login_template) uri = URI.parse(login_url) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true request = Net::HTTP::Post.new(login_url) request.body = login_template response = http.request(request) @auth_data = REXML::XPath.first(REXML::Document.new(response.body), "//Redirect").text @auth_data.gsub!(/&/, "&") # rexml converts & to &. Convert them back to & end |
#get_login_data_template ⇒ String
Fetches the login template from the server and replaces it with admin’s username and password
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/windows_live_admin.rb', line 41 def get_login_data_template http, request = get_request_headers("http://domains.live.com/Service/ManageDomain/V1.0/GetLoginDataTemplate") request.body = get_login_data_template_xml #puts @request.inspect response = http.request(request) # puts response.body template = REXML::XPath.first(REXML::Document.new(response.body), "//GetLoginDataTemplateResult").text template.gsub!(/%NAME%/, @username) template.gsub!(/%PASSWORD%/, @password) end |
#get_login_url ⇒ String
Fetches the login URl where the template needs to be posted to obtain the auth_data (token)
30 31 32 33 34 35 36 37 |
# File 'lib/windows_live_admin.rb', line 30 def get_login_url http, request = get_request_headers('http://domains.live.com/Service/ManageDomain/V1.0/GetLoginUrl') request.body = get_login_url_xml #puts @request.body response = http.request(request) login_url = REXML::XPath.first(REXML::Document.new(response.body), "//GetLoginUrlResult").text end |
#verify_auth_data ⇒ String
Verifies if the auth_data obtained from the previous calls to get_auth_data is valid
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/windows_live_admin.rb', line 71 def verify_auth_data http, request = get_request_headers("http://domains.live.com/Service/ManageDomain/V1.0/VerifyAuthData") request.body = verify_auth_data_xml # puts request.body response = http.request(request) # puts response.body begin = REXML::XPath.first(REXML::Document.new(response.body), "//VerifyAuthDataResult").text end return end |