Class: CrowdRest::Session
- Inherits:
-
Object
- Object
- CrowdRest::Session
- Defined in:
- lib/crowd_rest/session.rb
Class Method Summary collapse
- .create(username, password) ⇒ Object
- .destroy(username, options = {}) ⇒ Object
- .find(token, options = {}) ⇒ Object
- .invalidate(token) ⇒ Object
- .validate(token, validation_factors = {}) ⇒ Object
Class Method Details
.create(username, password) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/crowd_rest/session.rb', line 5 def self.create(username, password) body = "<authentication-context> <username>#{username}</username> <password>#{password}</password> </authentication-context>" response = CrowdRest.post("/session", :body => body) normalize_response(response, 201) do |successful_response| successful_response.token = response['session']['token'] end end |
.destroy(username, options = {}) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/crowd_rest/session.rb', line 27 def self.destroy(username, = {}) path = "/session?username=#{username}" path << "&except=#{.except}" if [:except] response = CrowdRest.delete(path) normalize_response(response, 204) end |
.find(token, options = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/crowd_rest/session.rb', line 16 def self.find(token, = {}) request_user = [:include] && [:include] == :user path = "/session/#{token}" path << "?expand=user" if request_user response = CrowdRest.get(path) normalize_response(response) do |successful_response| user = response['session']['user'] successful_response.user = CrowdRest::User.new(user) end end |
.invalidate(token) ⇒ Object
50 51 52 53 54 |
# File 'lib/crowd_rest/session.rb', line 50 def self.invalidate(token) path = "/session/#{token}" response = CrowdRest.delete(path) normalize_response(response, 204) end |
.validate(token, validation_factors = {}) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/crowd_rest/session.rb', line 34 def self.validate(token, validation_factors = {}) path = "/session/#{token}" body = "<validation-factors>" validation_factors.each do |name, value| body << "<validation-factor> <name>#{name}</name> <value>#{value}</value> </validation-factor>" end body << "</validation-factors>" response = CrowdRest.post(path, :body => body) normalize_response(response, 200) do |successful_response| successful_response.token = response['session']['token'] end end |