Class: BeyondApi::Users

Inherits:
Base
  • Object
show all
Includes:
Utils
Defined in:
lib/beyond_api/resources/users.rb

Instance Attribute Summary

Attributes inherited from Base

#session

Instance Method Summary collapse

Methods included from Utils

#handle_all_request, #handle_error, #handle_response, #sanitize_key, #sanitize_response, #to_object_struct

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from BeyondApi::Base

Instance Method Details

#add_roles(user_id, body) ⇒ Object

A POST request is used to add the roles of a user.

Examples:

session.users.add_roles(user_id, body)

Parameters:

  • user_id (String)

    the user UUID

  • body (Hash)

    the request body

Returns:

  • true

Scopes:


27
28
29
30
31
# File 'lib/beyond_api/resources/users.rb', line 27

def add_roles(user_id, body)
  response, status = BeyondApi::Request.post(@session, "/users/#{user_id}/roles", body)

  handle_response(response, status, respond_with_true: true)
end

#all(params = {}) ⇒ OpenStruct

A GET request is used to list all users visible to the current user. This request will not list the support user.

$ curl 'https://api-shop.beyondshop.cloud/api/users' -i -X GET \
    -H 'Content-Type: application/json' \
    -H 'Accept: application/hal+json' \
    -H 'Authorization: Bearer <Access token>'

Examples:

@users = session.users.all(size: 100, page: 0)

Parameters:

  • params (Hash) (defaults to: {})

    a customizable set of options

Options Hash (params):

  • :paginated (Boolean)
  • :size (Integer)

    the page size

  • :page (Integer)

    the page number

Returns:

  • (OpenStruct)

Scopes:

  • user:r


52
53
54
# File 'lib/beyond_api/resources/users.rb', line 52

def all(params = {})
  handle_all_request("/users", :users, params)
end

#change_password(user_id, current_password, new_password) ⇒ OpenStruct

A POST request is used to change the password of a user.

$ curl 'https://api-shop.beyondshop.cloud/api/users/e112b1fe-5f67-4e22-a3c7-a1f6d1891b22/change-password' -i -X POST \
    -H 'Content-Type: application/json' \
    -H 'Accept: application/json' \
    -H 'Authorization: Bearer <Access token>' \
    -d '{
  "currentPassword" : "GoodPassword01!;)",
  "newPassword" : "ValidPassword123"
}'

Examples:

session.users.change_password(user_id, current_password, new_password)

Parameters:

  • user_id (String)

    the user UUID

  • current_password (String)

    the current password

  • new_password (String)

    the new password

Returns:

  • (OpenStruct)

Scopes:

  • ++


79
80
81
82
83
# File 'lib/beyond_api/resources/users.rb', line 79

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)

  handle_response(response, status)
end

#change_username(user_id, new_username, current_password) ⇒ OpenStruct

A POST request is used to change the username of a user.

$ curl 'https://api-shop.beyondshop.cloud/api/users/ea0ddc0b-e3fb-47c7-9133-e9f5fc0ec442/change-username' -i -X POST \
    -H 'Content-Type: application/json' \
    -H 'Accept: application/json' \
    -H 'Authorization: Bearer <Access token>' \
    -d '{
  "currentPassword" : "GoodPassword01!;)",
  "newUsername" : "new username"
}'

Examples:

session.users.change_username(user_id, new_username, current_password)

Parameters:

  • user_id (String)

    the user UUID

  • new_username (String)

    the new username

  • current_password (String)

    the current password

Returns:

  • (OpenStruct)

106
107
108
109
110
# File 'lib/beyond_api/resources/users.rb', line 106

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)

  handle_response(response, status)
end

#create(body) ⇒ OpenStruct

A POST request is used to create a user.

$ curl 'https://api-shop.beyondshop.cloud/api/users' -i -X POST \
    -H 'Content-Type: application/json' \
    -H 'Accept: application/json' \
    -H 'Authorization: Bearer <Access token>' \
    -d '{
  "username" : "user",
  "password" : "GoodPassword01!;)",
  "email" : "[email protected]"
}'

Examples:

body = {
  "username" => "user",
  "password" => "GoodPassword01!;)",
  "email" => "[email protected]"
}
@user = session.users.create(body)

Parameters:

  • body (Hash)

    the request body

Returns:

  • (OpenStruct)

Scopes:

  • user:c


139
140
141
142
143
# File 'lib/beyond_api/resources/users.rb', line 139

def create(body)
  response, status = BeyondApi::Request.post(@session, "/users", body)

  handle_response(response, status)
end

#disable_support_accessObject

A POST request is used to disable support access.

$ curl 'https://api-shop.beyondshop.cloud/api/users/support' -i -X DELETE \
    -H 'Content-Type: application/json' \
    -H 'Accept: application/json' \
    -H 'Authorization: Bearer <Access token>'

Examples:

session.users.disable_support_access

Returns:

  • true

Scopes:

  • user:c


181
182
183
184
185
# File 'lib/beyond_api/resources/users.rb', line 181

def disable_support_access
  response, status = BeyondApi::Request.delete(@session, "/users/support")

  handle_response(response, status, respond_with_true: true)
end

#enable_support_accessObject

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.

$ curl 'api-shop.beyondshop.cloud/api/users/support' -i -X POST \

-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer <Access token>'

Examples:

session.users.enable_support_access

Returns:

  • true

Scopes:

  • user:c


160
161
162
163
164
# File 'lib/beyond_api/resources/users.rb', line 160

def enable_support_access
  response, status = BeyondApi::Request.post(@session, "/users/support")

  handle_response(response, status, respond_with_true: true)
end

#find(user_id) ⇒ OpenStruct

A GET request is used to retrieve the details of a user.

$ curl 'https://api-shop.beyondshop.cloud/api/users/e4b528ce-bb9e-4cc5-95e1-7dadfa4cf0f3' -i -X GET \
    -H 'Content-Type: application/json' \
    -H 'Accept: application/hal+json' \
    -H 'Authorization: Bearer <Access token>'

Examples:

@user = session.users.find("e4b528ce-bb9e-4cc5-95e1-7dadfa4cf0f3")

Parameters:

  • user_id (String)

    the user UUID

Returns:

  • (OpenStruct)

Scopes:

  • user:r


204
205
206
207
208
# File 'lib/beyond_api/resources/users.rb', line 204

def find(user_id)
  response, status = BeyondApi::Request.get(@session, "/users/#{user_id}")

  handle_response(response, status)
end

#roles(user_id) ⇒ OpenStruct

A GET request is used to list all roles of a user.

$ curl 'https://api-shop.beyondshop.cloud/api/users/0d4bd0a5-94dc-498e-b6a6-305c619bb20d/roles' -i -X GET \
    -H 'Authorization: Bearer <Access token>'

Examples:

@roles = session.users.roles("0d4bd0a5-94dc-498e-b6a6-305c619bb20d")

Parameters:

  • user_id (String)

    the user UUID

Returns:

  • (OpenStruct)

Scopes:

  • user:r


225
226
227
228
229
# File 'lib/beyond_api/resources/users.rb', line 225

def roles(user_id)
  response, status = BeyondApi::Request.get(@session, "/users/#{user_id}/roles")

  handle_response(response, status)
end

#search_by_username(username) ⇒ OpenStruct

A GET request is used to find a user by username.

$ curl 'https://api-shop.beyondshop.cloud/api/users/search/find-by-username?username=username' -i -X GET \
    -H 'Accept: application/hal+json' \
    -H 'Authorization: Bearer <Access token>'

Examples:

@user = session.users.search_by_username(username)

Parameters:

  • username (String)

    the user username

Returns:

  • (OpenStruct)

Scopes:

  • user:r


247
248
249
250
251
# File 'lib/beyond_api/resources/users.rb', line 247

def search_by_username(username)
  response, status = BeyondApi::Request.get(@session, "/users/search/find-by-username", username: username)

  handle_response(response, status)
end

#send_email_address_change(user_id, new_email, current_password, locale) ⇒ Object

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.

$ curl 'https://api-shop.beyondshop.cloud/api/users/8f5fd817-0ea1-4550-b4b9-fc437b1b6905/change-email-request?locale=en-US' -i -X POST \
    -H 'Content-Type: application/json' \
    -H 'Accept: application/json' \
    -H 'Authorization: Bearer <Access token>' \
    -d '{
  "currentPassword" : "GoodPassword01!;)",
  "newEmail" : "[email protected]"
}'

Examples:

session.users.send_email_address_change(user_id, new_email, current_password, locale)

Parameters:

  • user_id (String)

    the user UUID

  • new_email (String)

    the new email address

  • current_password (String)

    the current password

  • locale (String)

    the email locale

Returns:

  • true

Scopes:

  • ++


277
278
279
280
281
# File 'lib/beyond_api/resources/users.rb', line 277

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 })

  handle_response(response, status, respond_with_true: true)
end

#send_reset_password_email(email, locale) ⇒ Object

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.

$ curl 'https://api-shop.beyondshop.cloud/api/users/reset-password-request?locale=en-US' -i -X POST \
    -H 'Content-Type: application/json' \
    -H 'Accept: application/json' \
    -d '{
  "email" : "[email protected]"
}'

Examples:

session.users.send_reset_password_email(email, locale)

Parameters:

  • email (String)

    the user email

  • locale (String)

    the email locale

Returns:

  • true

Scopes:

  • ++


303
304
305
306
307
# File 'lib/beyond_api/resources/users.rb', line 303

def send_reset_password_email(email, locale)
  response, status = BeyondApi::Request.post(@session, "/users/reset-password-request", { email: email }, { locale: locale })

  handle_response(response, status, respond_with_true: true)
end

#set_roles(user_id, body) ⇒ Object

A PUT request is used set the roles of a user.

Examples:

session.users.set_roles(user_id, body)

Parameters:

  • user_id (String)

    the user UUID

  • body (Hash)

    the request body

Returns:

  • true

Scopes:


327
328
329
330
331
# File 'lib/beyond_api/resources/users.rb', line 327

def set_roles(user_id, body)
  response, status = BeyondApi::Request.put(@session, "/users/#{user_id}/roles", body)

  handle_response(response, status, respond_with_true: true)
end

#support_accessOpenStruct

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.

$ curl 'https://api-shop.beyondshop.cloud/api/users/support' -i -X GET \
    -H 'Accept: application/hal+json' \
    -H 'Authorization: Bearer <Access token>'

Examples:

session.users.support_access

Returns:

  • (OpenStruct)

Scopes:

  • user:r


347
348
349
350
351
# File 'lib/beyond_api/resources/users.rb', line 347

def support_access
  response, status = BeyondApi::Request.get(@session, "/users/support")

  handle_response(response, status)
end

#verify_password(password, user_role) ⇒ Object

A POST request is used to verify a password against the password guidelines.

$ curl 'https://api-shop.beyondshop.cloud/api/users/verify-password?userRole=merchant' -i -X POST \
    -H 'Content-Type: application/json' \
    -H 'Accept: application/json' \
    -d '{
  "password" : "ValidPassword!"
}'

Examples:

session.users.verify_password(password)

Parameters:

  • password (String)

    the password to verify

Returns:

  • true

Scopes:

  • ++


372
373
374
375
376
# File 'lib/beyond_api/resources/users.rb', line 372

def verify_password(password, user_role)
  response, status = BeyondApi::Request.post(@session, "/users/verify-password", password: password, user_role: user_role)

  handle_response(response, status, respond_with_true: true)
end