Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## qresource.rb
- module Qresource
- def get_parser(xml_str) # {{{
- begin
- p = XML::Parser.new
- p.string = xml_str
- p.parse
- rescue
- # TODO raise exception here!
- nil
- end
- end # }}}
- end
- ## dt_user.rb
- def self.authenticate(login = '', password = '', api_url = '') # {{{
- rc = RestClient::Resource.new(
- api_url,
- :user => APP_CONFIG[:api][:backoffice][:user],
- :password => APP_CONFIG[:api][:backoffice][:password]
- )
- url = "/users/validate.xml?login=#{login}&password=#{password}"
- begin
- response = rc[url].get
- doc = get_parser( response )
- valid_password = doc.find_first('valid_password')
- if valid_password.content == 'yes'
- logger.debug "found valid password hurray!"
- return DtUser.new :login => login, :password => password, :api_url => api_url
- else
- logger.warn "valid_password #{valid_password.content}"
- return false
- end
- rescue
- logger.error "call/parsing failed with #{$!}"
- return false
- end
- logger.error "unable to login with #{login}/#{password} @ #{api_url}"
- return false
- end
- end
- ## explain.txt
- results in "unkown method get_parser"
- the dt_user is somewhat different from the rest of the qresource's since it needs a super-custom call to validate password.
- regular qresource objects are not used as singletons...
Add Comment
Please, Sign In to add comment