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
87 88 89 90 91 92 93 94 95 |
# File 'lib/services/user_service.rb', line 87 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
54 55 56 57 58 59 60 61 |
# File 'lib/services/user_service.rb', line 54 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 27 |
# 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) puts create_user_payload 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
149 150 151 152 153 |
# File 'lib/services/user_service.rb', line 149 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
134 135 136 137 138 139 140 |
# File 'lib/services/user_service.rb', line 134 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
70 71 72 73 74 75 76 77 |
# File 'lib/services/user_service.rb', line 70 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
104 105 106 107 108 109 |
# File 'lib/services/user_service.rb', line 104 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
119 120 121 122 123 124 125 |
# File 'lib/services/user_service.rb', line 119 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
37 38 39 40 41 42 43 44 45 |
# File 'lib/services/user_service.rb', line 37 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 |