Class: SBF::Client::UserEndpoint
- Inherits:
-
EntityEndpoint
- Object
- EntityEndpoint
- SBF::Client::UserEndpoint
- Defined in:
- lib/stbaldricks/endpoints/user.rb
Instance Attribute Summary
Attributes inherited from EntityEndpoint
Instance Method Summary collapse
-
#change_password(profile_id, password) ⇒ Object
Changes the password of the user associated with the given profile_id.
-
#disconnect_facebook(profile_id) ⇒ Object
Removes the Facebook user of the given profile_id.
-
#list_entities_user_has_permission(permission_id, event_years) ⇒ Object
Returns array of entity hash info for the entities logged in user has access to for requested permission.
-
#login!(username, password) ⇒ string
Logs in a user and configures the client library to use user credentials for subsequent requests.
Methods inherited from EntityEndpoint
#aggregate, #create, #delete, #find, #find_first, #get, #initialize, #save, #update
Constructor Details
This class inherits a constructor from SBF::Client::EntityEndpoint
Instance Method Details
#change_password(profile_id, password) ⇒ Object
Changes the password of the user associated with the given profile_id
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/stbaldricks/endpoints/user.rb', line 61 def change_password(profile_id, password) raise SBF::Client::Error, 'User not logged in' if SBF::Client::Configuration.user_token.nil? response = SBF::Client::Api::Request.post_request( "/#{SBF::Client::Api::VERSION}/security/change_password", profile_id: profile_id, password: password ) if ok?(response) SBF::Client::Configuration.user_token = nil else SBF::Client::Configuration.user_token = nil parsed_response = JSON.parse(response.body).symbolize! error = SBF::Client::ErrorEntity.new(parsed_response) end SBF::Client::LOG.info { "SB::Client - Change Password for user with profile_id: #{profile_id}" } SBF::Client::Api::Response.new(http_code: response.code, data: nil, error: error) end |
#disconnect_facebook(profile_id) ⇒ Object
Removes the Facebook user of the given profile_id
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/stbaldricks/endpoints/user.rb', line 85 def disconnect_facebook(profile_id) raise SBF::Client::Error, 'User not logged in' if SBF::Client::Configuration.user_token.nil? response = SBF::Client::Api::Request.post_request( "/#{SBF::Client::Api::VERSION}/user/disconnect_facebook", profile_id: profile_id ) if ok?(response) SBF::Client::Configuration.user_token = nil else SBF::Client::Configuration.user_token = nil parsed_response = JSON.parse(response.body).symbolize! error = SBF::Client::ErrorEntity.new(parsed_response) end SBF::Client::LOG.info { "SB::Client - Disconnecting Facebook user with profile_id: #{profile_id}" } SBF::Client::Api::Response.new(http_code: response.code, data: nil, error: error) end |
#list_entities_user_has_permission(permission_id, event_years) ⇒ Object
Returns array of entity hash info for the entities logged in user has access to for requested permission.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/stbaldricks/endpoints/user.rb', line 36 def (, event_years) raise SBF::Client::Error, 'User not logged in' if SBF::Client::Configuration.user_token.nil? event_years = [event_years] if event_years.is_a? Fixnum response = SBF::Client::Api::Request.post_request( "/#{SBF::Client::Api::VERSION}/security/list_entities_user_has_permission", permission_id: , event_years: event_years ) parsed_response = JSON.parse(response.body).symbolize! if ok?(response) data = parsed_response else error = SBF::Client::ErrorEntity.new(parsed_response) end SBF::Client::LOG.info { "SBF::Client - User List Entities User Has Permission: #{}, #{event_years}, Entities: #{data}" } SBF::Client::Api::Response.new(http_code: response.code, data: data, error: error) end |
#login!(username, password) ⇒ string
Logs in a user and configures the client library to use user credentials for subsequent requests. Returns the access token for the user that should be held onto to configure the client library in future requests that are outside of this scope.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/stbaldricks/endpoints/user.rb', line 13 def login!(username, password) response = SBF::Client::Api::Request.post_request( "/#{SBF::Client::Api::VERSION}/security/login", username: username, password: password ) parsed_response = JSON.parse(response.body).symbolize! if ok?(response) SBF::Client::Configuration.user_token = parsed_response[:token] data = parsed_response.merge(user: target_class.new(parsed_response[:user])) else SBF::Client::Configuration.user_token = nil error = SBF::Client::ErrorEntity.new(parsed_response) end SBF::Client::LOG.info { "SBF::Client - User Login: #{username}, Token: #{parsed_response[:token]}" } SBF::Client::Api::Response.new(http_code: response.code, data: data, error: error) end |