Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
adds services from authentication
  • Loading branch information
citin committed Sep 3, 2024
commit 6dc1f65b1e25e82e8c6b111741a62a888a8c0c15
36 changes: 36 additions & 0 deletions lib/beyond_api/services/authentication/email_address.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

module BeyondApi
module Authentication
# @example How to instantiate a client
# @client = BeyondApi::Authentication::EmailAddress.new(
# api_url: 'https://example.com/api',
# access_token: 'your_token'
# )
class EmailAddress < BaseService
# Trigger an email address change
#
# @see https://developer.epages.com/beyond-docs/#trigger_email_address_change
#
# @option params [Integer] :user_id
# @option params [String] :locale defines the language of the confirmation email is to be sent.
# @option params [String] :current_password the current password of the user account.
# @option params [String] :new_email the new email address for the user to set.
#
# @example
# @client.trigger_change(
# "9ed8418f-d568-4327-9f20-ec1d00614398",
# "en-US",
# "GoodPassword01!;)",
# "[email protected]"
# )
def trigger_change(user_id, locale, current_password, new_email)
post(
"users/#{user_id}/change-email-request",
{ current_password:, new_email: }, # body
locale # query params
)
end
end
end
end
2 changes: 1 addition & 1 deletion lib/beyond_api/services/authentication/signer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Signer < BaseService
# @see https://developer.epages.com/beyond-docs/#list_signers
#
# @return [Hash]
# #
#
# @example
# @client.all
def all
Expand Down
92 changes: 92 additions & 0 deletions lib/beyond_api/services/authentication/user_and_password.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# frozen_string_literal: true

module BeyondApi
module Authentication
# @example How to instantiate a client
# @client = BeyondApi::Authentication::UserAndPassword.new(
# api_url: 'https://example.com/api',
# access_token: 'your_token'
# )
class UserAndPassword < BaseService
# Verify a password against the password guidelines.
#
# @see https://developer.epages.com/beyond-docs/#verify_password
#
# @option params [Integer] :user_role the type of user. Can be one of merchant, support, or customer.
# @option params [String] :password the password that needs to be verified.
#
# @example
# @client.verify_password(
# "merchant",
# "ValidPassword!"
# )
def verify_password(user_role, password)
post(
'users/verify-password',
{ password: }, # body
user_role # query params
)
end

# Trigger an email address change
#
# @see https://developer.epages.com/beyond-docs/#change_password
#
# @option params [Integer] :user_id
# @option params [String] :current_password the current password of the user. This is verified before the password change.
# @option params [String] :new_password the new password to set in order to change the password.
#
# @example
# @client.change_password(
# "9ed8418f-d568-4327-9f20-ec1d00614398",
# "GoodPassword01!;)",
# "ValidPassword123"
# )
def change_password(user_id, current_password, new_password)
post(
"users/#{user_id}/change-password",
{ current_password:, new_password: } # body
)
end

# Trigger an email address change
#
# @see https://developer.epages.com/beyond-docs/#trigger_password_reset_email
#
# @option params [String] :email the email address of the user account.
#
# @example
# @client.password_reset_email(
# "[email protected]"
# )
def password_reset_email(email)
post(
'users/reset-password-request',
{ email: } # body
)
end

# Change the username of a user.
#
# @see https://developer.epages.com/beyond-docs/#change_username
#
# @option params [Integer] :user_id the email address of the user account.
# @option params [String] :current_password The current password of the user. This is verified before the username change.
# @option params [String] :new_username The new username to set in order to change the username.
#
# @example
# @client.change_username(
# "9ed8418f-d568-4327-9f20-ec1d00614398",
# "ValidPassword123",
# "[email protected]"
# )
def change_username(user_id, current_password, new_username)
post(
"users/#{user_id}/change-username",
{ current_password:, new_username: }, # body
user_role # query params
)
end
end
end
end