lib/beyond_api/resources/users.rb in beyond_api-0.18.0.pre vs lib/beyond_api/resources/users.rb in beyond_api-0.18.2.pre

- old
+ new

@@ -23,12 +23,16 @@ # # @example # session.users.add_roles(user_id, body) # def add_roles(user_id, body) - response, status = BeyondApi::Request.post(@session, "/users/#{user_id}/roles", body) + path = "/users/#{user_id}/roles" + response, status = BeyondApi::Request.post(@session, + path, + body) + handle_response(response, status, respond_with_true: true) end # # A +GET+ request is used to list all users visible to the current user. This request will not list the support user. @@ -48,11 +52,13 @@ # # @example # @users = session.users.all(size: 100, page: 0) # def all(params = {}) - handle_all_request("/users", :users, params) + path = "/users" + + handle_all_request(path, :users, params) end # # A +POST+ request is used to change the password of a user. # @@ -75,12 +81,17 @@ # # @example # session.users.change_password(user_id, current_password, new_password) # def change_password(user_id, current_password, new_password) - response, status = BeyondApi::Request.post(@session, "/users/#{user_id}/change-password", current_password: current_password, new_password: new_password) + path = "/users/#{user_id}/change-password" + response, status = BeyondApi::Request.post(@session, + path, + current_password: current_password, + new_password: new_password) + handle_response(response, status) end # # A +POST+ request is used to change the username of a user. @@ -102,12 +113,17 @@ # # @example # session.users.change_username(user_id, new_username, current_password) # def change_username(user_id, new_username, current_password) - response, status = BeyondApi::Request.post(@session, "/users/#{user_id}/change-username", new_username: new_username, current_password: current_password) + path = "/users/#{user_id}/change-username" + response, status = BeyondApi::Request.post(@session, + path, + new_username: new_username, + current_password: current_password) + handle_response(response, status) end # # A +POST+ request is used to create a user. @@ -135,12 +151,16 @@ # "email" => "baxter@example.org" # } # @user = session.users.create(body) # def create(body) - response, status = BeyondApi::Request.post(@session, "/users", body) + path = "/users" + response, status = BeyondApi::Request.post(@session, + path, + body) + handle_response(response, status) end # # A +POST+ request is used to enable support access for a shop. If enabled, the customer support will receive specific rights for direct support in the merchant’s cockpit. @@ -156,12 +176,15 @@ # # @example # session.users.enable_support_access # def enable_support_access - response, status = BeyondApi::Request.post(@session, "/users/support") + path = "/users/support" + response, status = BeyondApi::Request.post(@session, + path) + handle_response(response, status, respond_with_true: true) end # # A +POST+ request is used to disable support access. @@ -177,12 +200,15 @@ # # @example # session.users.disable_support_access # def disable_support_access - response, status = BeyondApi::Request.delete(@session, "/users/support") + path = "/users/support" + response, status = BeyondApi::Request.delete(@session, + path) + handle_response(response, status, respond_with_true: true) end # # A +GET+ request is used to retrieve the details of a user. @@ -200,12 +226,15 @@ # # @example # @user = session.users.find("e4b528ce-bb9e-4cc5-95e1-7dadfa4cf0f3") # def find(user_id) - response, status = BeyondApi::Request.get(@session, "/users/#{user_id}") + path = "/users/#{user_id}" + response, status = BeyondApi::Request.get(@session, + path) + handle_response(response, status) end # # A +GET+ request is used to list all roles of a user. @@ -221,12 +250,15 @@ # # @example # @roles = session.users.roles("0d4bd0a5-94dc-498e-b6a6-305c619bb20d") # def roles(user_id) - response, status = BeyondApi::Request.get(@session, "/users/#{user_id}/roles") + path = "/users/#{user_id}/roles" + response, status = BeyondApi::Request.get(@session, + path) + handle_response(response, status) end # # A +GET+ request is used to find a user by username. @@ -243,12 +275,16 @@ # # @example # @user = session.users.search_by_username(username) # def search_by_username(username) - response, status = BeyondApi::Request.get(@session, "/users/search/find-by-username", username: username) + path = "/users/search/find-by-username" + response, status = BeyondApi::Request.get(@session, + path, + username: username) + handle_response(response, status) end # # A +POST+ request is used to trigger an email address change. A confirmation email to change the email address will be sent to the user. The confirmation email will contain a link to the email address change page of the merchant’s cockpit. The link includes a JWT to authorize the email address change. @@ -273,12 +309,17 @@ # # @example # session.users.send_email_address_change(user_id, new_email, current_password, locale) # def send_email_address_change(user_id, new_email, current_password, locale) - response, status = BeyondApi::Request.post(@session, "/users/#{user_id}/change-email-request", { new_email: new_email, current_password: current_password }, { locale: locale }) + path = "/users/#{user_id}/change-email-request" + response, status = BeyondApi::Request.post(@session, + path, + { new_email: new_email, current_password: current_password }, + { locale: locale }) + handle_response(response, status, respond_with_true: true) end # # A +POST+ request is used to trigger a password reset email to be sent to a user. The email will contain a link to the change password settings page of the merchant’s cockpit. The link includes a JWT to authorize the password reset. @@ -299,12 +340,17 @@ # # @example # session.users.send_reset_password_email(email, locale) # def send_reset_password_email(email, locale) - response, status = BeyondApi::Request.post(@session, "/users/reset-password-request", { email: email }, { locale: locale }) + path = "/users/reset-password-request" + response, status = BeyondApi::Request.post(@session, + path, + { email: email }, + { locale: locale }) + handle_response(response, status, respond_with_true: true) end # # A +PUT+ request is used set the roles of a user. @@ -323,12 +369,16 @@ # # @example # session.users.set_roles(user_id, body) # def set_roles(user_id, body) - response, status = BeyondApi::Request.put(@session, "/users/#{user_id}/roles", body) + path = "/users/#{user_id}/roles" + response, status = BeyondApi::Request.put(@session, + path, + body) + handle_response(response, status, respond_with_true: true) end # # A +GET+ request is used to retrieve the status of the support access for a shop, i.e. if the support user is enabled or disabled for the shop. @@ -343,12 +393,15 @@ # # @example # session.users.support_access # def support_access - response, status = BeyondApi::Request.get(@session, "/users/support") + path = "/users/support" + response, status = BeyondApi::Request.get(@session, + path) + handle_response(response, status) end # # A +POST+ request is used to verify a password against the password guidelines. @@ -368,10 +421,15 @@ # # @example # session.users.verify_password(password) # def verify_password(password, user_role) - response, status = BeyondApi::Request.post(@session, "/users/verify-password", password: password, user_role: user_role) + path = "/users/verify-password" + + response, status = BeyondApi::Request.post(@session, + path, + password: password, + user_role: user_role) handle_response(response, status, respond_with_true: true) end end end