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

#file_content_type, #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
32
33
34
35
# File 'lib/beyond_api/resources/users.rb', line 27

def add_roles(user_id, body)
  path = "/users/#{user_id}/roles"

  response, status = BeyondApi::Request.post(@session,
                                             path,
                                             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



56
57
58
59
60
# File 'lib/beyond_api/resources/users.rb', line 56

def all(params = {})
  path = "/users"

  handle_all_request(path, :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:

  • ++



85
86
87
88
89
90
91
92
93
94
# File 'lib/beyond_api/resources/users.rb', line 85

def change_password(user_id, current_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

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


117
118
119
120
121
122
123
124
125
126
# File 'lib/beyond_api/resources/users.rb', line 117

def change_username(user_id, new_username, 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

#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



155
156
157
158
159
160
161
162
163
# File 'lib/beyond_api/resources/users.rb', line 155

def create(body)
  path = "/users"

  response, status = BeyondApi::Request.post(@session,
                                             path,
                                             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



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

def disable_support_access
  path = "/users/support"

  response, status = BeyondApi::Request.delete(@session,
                                               path)

  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



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

def enable_support_access
  path = "/users/support"

  response, status = BeyondApi::Request.post(@session,
                                             path)

  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



230
231
232
233
234
235
236
237
# File 'lib/beyond_api/resources/users.rb', line 230

def find(user_id)
  path = "/users/#{user_id}"

  response, status = BeyondApi::Request.get(@session,
                                            path)

  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



254
255
256
257
258
259
260
261
# File 'lib/beyond_api/resources/users.rb', line 254

def roles(user_id)
  path = "/users/#{user_id}/roles"

  response, status = BeyondApi::Request.get(@session,
                                            path)

  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



279
280
281
282
283
284
285
286
287
# File 'lib/beyond_api/resources/users.rb', line 279

def search_by_username(username)
  path = "/users/search/find-by-username"

  response, status = BeyondApi::Request.get(@session,
                                            path,
                                            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:

  • ++



313
314
315
316
317
318
319
320
321
322
# File 'lib/beyond_api/resources/users.rb', line 313

def send_email_address_change(user_id, new_email, current_password, 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

#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:

  • ++



344
345
346
347
348
349
350
351
352
353
# File 'lib/beyond_api/resources/users.rb', line 344

def send_reset_password_email(email, 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

#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:



373
374
375
376
377
378
379
380
381
# File 'lib/beyond_api/resources/users.rb', line 373

def set_roles(user_id, body)
  path = "/users/#{user_id}/roles"

  response, status = BeyondApi::Request.put(@session,
                                            path,
                                            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



397
398
399
400
401
402
403
404
# File 'lib/beyond_api/resources/users.rb', line 397

def support_access
  path = "/users/support"

  response, status = BeyondApi::Request.get(@session,
                                            path)

  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:

  • ++



425
426
427
428
429
430
431
432
433
434
# File 'lib/beyond_api/resources/users.rb', line 425

def verify_password(password, 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