Class: UserService
- Inherits:
-
Object
- Object
- UserService
- Defined in:
- lib/services/user_service.rb
Overview
User Service for CRUD operation related to user
Class Method Summary collapse
-
.change_password(user, bearer_token) ⇒ Json
Updates old password to new password.
-
.check_email(user) ⇒ Json
Verifies if email is already registered.
-
.create_user(user) ⇒ Json
Creates User.
-
.get_user(user) ⇒ Object
Sets Parent to User object.
-
.get_user_with_client_info(user) ⇒ Object
Sets Client information to user object.
-
.reset_password(user) ⇒ Json
Sends email with reset password link.
-
.show_logged_in_user(bearer_token) ⇒ Json
Displays logged in user details.
-
.show_user_id(user_id, bearer_token) ⇒ Json
Displays details of user id.
-
.update_user(user, bearer_token) ⇒ Json
Updates existing user.
Class Method Details
.change_password(user, bearer_token) ⇒ Json
Updates old password to new password
86 87 88 89 90 91 92 93 94 |
# File 'lib/services/user_service.rb', line 86 def self.change_password(user, bearer_token) user_data = get_user(user) change_password_payload = User.get_payload(user_data) RestClient::Request.execute(method: :post, url: ApplicationConfig.get_url('change_password_path'), payload: change_password_payload, headers: { 'Content-Type': 'application/json', 'Authorization': bearer_token }) end |
.check_email(user) ⇒ Json
Verifies if email is already registered
53 54 55 56 57 58 59 60 |
# File 'lib/services/user_service.rb', line 53 def self.check_email(user) RestClient::Request.execute(method: :get, url: ApplicationConfig.get_url('check_email_path'), headers: { 'Content-Type': 'application/json', params: { email: user.email, client_id: ApplicationConfig.client_id, client_secret: ApplicationConfig.client_secret } }) end |
.create_user(user) ⇒ Json
Creates User
19 20 21 22 23 24 25 26 |
# File 'lib/services/user_service.rb', line 19 def self.create_user(user) user_with_client_info = get_user_with_client_info(user) create_user_payload = User.get_payload(user_with_client_info) RestClient::Request.execute(method: :post, url: ApplicationConfig.get_url('create_user_path'), payload: create_user_payload, headers: { 'Content-Type': 'application/json' }) end |
.get_user(user) ⇒ Object
Sets Parent to User object
148 149 150 151 152 |
# File 'lib/services/user_service.rb', line 148 def self.get_user(user) user_data = UserBase.new user_data.user = user user_data end |
.get_user_with_client_info(user) ⇒ Object
Sets Client information to user object
133 134 135 136 137 138 139 |
# File 'lib/services/user_service.rb', line 133 def self.get_user_with_client_info(user) user_with_client_info = ClientInfoBase.new user_with_client_info.client_id = ApplicationConfig.client_id user_with_client_info.client_secret = ApplicationConfig.client_secret user_with_client_info.user = user user_with_client_info end |
.reset_password(user) ⇒ Json
Sends email with reset password link
69 70 71 72 73 74 75 76 |
# File 'lib/services/user_service.rb', line 69 def self.reset_password(user) user_with_client_info = get_user_with_client_info(user) reset_password_payload = User.get_payload(user_with_client_info) RestClient::Request.execute(method: :post, url: ApplicationConfig.get_url('reset_password_path'), payload: reset_password_payload, headers: { 'Content-Type': 'application/json' }) end |
.show_logged_in_user(bearer_token) ⇒ Json
Displays logged in user details
103 104 105 106 107 108 |
# File 'lib/services/user_service.rb', line 103 def self.show_logged_in_user(bearer_token) RestClient::Request.execute(method: :get, url: ApplicationConfig.get_url('show_logged_in_user_path'), headers: { 'Content-Type': 'application/json', 'Authorization': bearer_token }) end |
.show_user_id(user_id, bearer_token) ⇒ Json
Displays details of user id
118 119 120 121 122 123 124 |
# File 'lib/services/user_service.rb', line 118 def self.show_user_id(user_id, bearer_token) url_with_id = ApplicationConfig.get_url('show_user_id_path') + '/' + user_id.to_s RestClient::Request.execute(method: :get, url: url_with_id, headers: { 'Content-Type': 'application/json', 'Authorization': bearer_token }) end |
.update_user(user, bearer_token) ⇒ Json
Updates existing user
36 37 38 39 40 41 42 43 44 |
# File 'lib/services/user_service.rb', line 36 def self.update_user(user, bearer_token) user_data = get_user(user) update_user_payload = User.get_payload(user_data) RestClient::Request.execute(method: :put, url: ApplicationConfig.get_url('update_user_path'), payload: update_user_payload, headers: { 'Content-Type': 'application/json', 'Authorization': bearer_token }) end |