Class: Cloudinary::AccountApi

Inherits:
Object
  • Object
show all
Extended by:
BaseApi
Defined in:
lib/cloudinary/account_api.rb

Class Method Summary collapse

Methods included from BaseApi

call_json_api, extended

Class Method Details

.access_keys(sub_account_id, options = {}) ⇒ Object

Lists access keys.

Parameters:

  • sub_account_id (String)

    The ID of the sub-account.

  • options (Object) (defaults to: {})

    Additional options.



229
230
231
232
# File 'lib/cloudinary/account_api.rb', line 229

def self.access_keys(, options = {})
  params = Cloudinary::Api.only(options, :page_size, :page, :sort_by, :sort_order)
  (:get, ['sub_accounts', , 'access_keys'], params, options)
end

.add_user_to_group(group_id, user_id, options = {}) ⇒ Object

Adds a user to a group with the specified ID.

Parameters:

  • group_id (String)

    The ID of the user group.

  • user_id (String)

    The ID of the user.

  • options (Object) (defaults to: {})

    additional options



186
187
188
# File 'lib/cloudinary/account_api.rb', line 186

def self.add_user_to_group(group_id, user_id, options = {})
  (:post, ['user_groups', group_id, 'users', user_id], {}, options.merge(content_type: :json))
end

.create_sub_account(name, cloud_name = nil, custom_attributes = {}, enabled = nil, base_account = nil, options = {}) ⇒ Object

Creates a new sub-account. Any users that have access to all sub-accounts will also automatically have access to the new sub-account.

Parameters:

  • name (String)

    The display name as shown in the management console

  • cloud_name (String) (defaults to: nil)

    A case-insensitive cloud name comprised of alphanumeric and underscore characters. Generates an error if the specified cloud name is not unique across all Cloudinary accounts. Note: Once created, the name can only be changed for accounts with fewer than 1000 assets.

  • custom_attributes (Object) (defaults to: {})

    Any custom attributes you want to associate with the sub-account

  • enabled (Boolean) (defaults to: nil)

    Whether to create the account as enabled (default is enabled)

  • base_account (String) (defaults to: nil)

    ID of sub-account from which to copy settings

  • options (Object) (defaults to: {})

    additional options



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/cloudinary/account_api.rb', line 14

def self.(name, cloud_name = nil, custom_attributes = {}, enabled = nil,  = nil, options = {})
  params = {
    name:                name,
    cloud_name:          cloud_name,
    custom_attributes:   custom_attributes,
    enabled:             enabled,
    base_sub_account_id: 
  }

  (:post, 'sub_accounts', params, options.merge(content_type: :json))
end

.create_user(name, email, role, sub_account_ids = [], options = {}) ⇒ Object

Creates a new user in the account.

Parameters:

  • name (String)

    The name of the user.

  • email (String)

    A unique email address, which serves as the login name and notification address.

  • role (String)

    The role to assign. Possible values: master_admin, admin, billing, technical_admin, reports, media_library_admin, media_library_user

  • sub_account_ids (Array<String>) (defaults to: [])

    The list of sub-account IDs that this user can access. Note: This parameter is ignored if the role is specified as master_admin.

  • options (Object) (defaults to: {})

    additional options



85
86
87
88
89
90
91
92
93
94
# File 'lib/cloudinary/account_api.rb', line 85

def self.create_user(name, email, role,  = [], options = {})
  params = {
    name:            name,
    email:           email,
    role:            role,
    sub_account_ids: 
  }

  (:post, 'users', params, options.merge(content_type: :json))
end

.create_user_group(name, options = {}) ⇒ Object

Creates a new user group.

Parameters:

  • name (String)

    The name for the user group.

  • options (Object) (defaults to: {})

    additional options



162
163
164
165
166
167
168
# File 'lib/cloudinary/account_api.rb', line 162

def self.create_user_group(name, options = {})
  params = {
    name: name
  }

  (:post, 'user_groups', params, options.merge(content_type: :json))
end

.delete_access_key(sub_account_id, api_key = nil, name = nil, options = {}) ⇒ Object

Deletes access key.

Parameters:

  • sub_account_id (String)

    The ID of the sub-account.

  • api_key (String, nil) (defaults to: nil)

    The API key.

  • name (String, nil) (defaults to: nil)

    The display name as shown in the management console.

  • options (Object) (defaults to: {})

    Additional options.



269
270
271
272
273
274
275
276
277
278
279
# File 'lib/cloudinary/account_api.rb', line 269

def self.delete_access_key(, api_key = nil, name = nil, options = {})
  uri = ['sub_accounts', , 'access_keys']
  unless api_key.blank?
    uri.append(api_key)
  end

  params = {
    name: name,
  }
  (:delete, uri, params, options.merge(content_type: :json))
end

.delete_sub_account(sub_account_id, options = {}) ⇒ Object

Deletes the specified sub-account. Supported only for accounts with fewer than 1000 assets.

Parameters:

  • sub_account_id (String)

    The ID of the sub-account.

  • options (Object) (defaults to: {})

    additional options



73
74
75
# File 'lib/cloudinary/account_api.rb', line 73

def self.(, options = {})
  (:delete, ['sub_accounts', ], {}, options)
end

.delete_user(user_id, options = {}) ⇒ Object

Deletes an existing user.

Parameters:

  • user_id (String)

    The ID of the user to delete.

  • options (Object) (defaults to: {})

    additional options



99
100
101
# File 'lib/cloudinary/account_api.rb', line 99

def self.delete_user(user_id, options = {})
  (:delete, ['users', user_id], {}, options)
end

.delete_user_group(group_id, options = {}) ⇒ Object

Deletes the user group with the specified ID.

Parameters:

  • group_id (String)

    The ID of the user group to delete.

  • options (Object) (defaults to: {})

    additional options



201
202
203
# File 'lib/cloudinary/account_api.rb', line 201

def self.delete_user_group(group_id, options = {})
  (:delete, ['user_groups', group_id], {}, options)
end

.generate_access_key(sub_account_id, name = nil, enabled = nil, options = {}) ⇒ Object

Generates access key.

Parameters:

  • sub_account_id (String)

    The ID of the sub-account.

  • name (String) (defaults to: nil)

    The display name as shown in the management console.

  • enabled (Boolean) (defaults to: nil)

    Whether to create the access key as enabled (default is enabled).

  • options (Object) (defaults to: {})

    Additional options.



240
241
242
243
244
245
246
# File 'lib/cloudinary/account_api.rb', line 240

def self.generate_access_key(, name = nil, enabled = nil, options = {})
  params = {
    name:    name,
    enabled: enabled,
  }
  (:post, ['sub_accounts', , 'access_keys'], params, options.merge(content_type: :json))
end

.remove_user_from_group(group_id, user_id, options = {}) ⇒ Object

Removes a user from a group with the specified ID.

Parameters:

  • group_id (String)

    The ID of the user group.

  • user_id (String)

    The ID of the user.

  • options (Object) (defaults to: {})

    additional options



194
195
196
# File 'lib/cloudinary/account_api.rb', line 194

def self.remove_user_from_group(group_id, user_id, options = {})
  (:delete, ['user_groups', group_id, 'users', user_id], {}, options.merge(content_type: :json))
end

.sub_account(sub_account_id, options = {}) ⇒ Object

Retrieves the details of the specified sub-account.

Parameters:

  • sub_account_id (String)

    The ID of the sub-account.

  • options (Object) (defaults to: {})

    additional options



66
67
68
# File 'lib/cloudinary/account_api.rb', line 66

def self.(, options = {})
  (:get, ['sub_accounts', ], {}, options.merge(content_type: :json))
end

.sub_accounts(enabled = nil, ids = [], prefix = nil, options = {}) ⇒ Object

Lists sub-accounts.

Parameters:

  • enabled (Boolean) (defaults to: nil)

    Whether to only return enabled sub-accounts (true) or disabled accounts (false). Default: all accounts are returned (both enabled and disabled).

  • ids (Array<String>) (defaults to: [])

    A list of up to 100 sub-account IDs. When provided, other parameters are ignored.

  • prefix (String) (defaults to: nil)

    Returns accounts where the name begins with the specified case-insensitive string.

  • options (Object) (defaults to: {})

    additional options



53
54
55
56
57
58
59
60
61
# File 'lib/cloudinary/account_api.rb', line 53

def self.sub_accounts(enabled = nil, ids = [], prefix = nil, options = {})
  params = {
    enabled: enabled,
    ids:     ids,
    prefix:  prefix
  }

  (:get, 'sub_accounts', params, options.merge(content_type: :json))
end

.update_access_key(sub_account_id, api_key, name = nil, enabled = nil, options = {}) ⇒ Object

Updates access key.

Parameters:

  • sub_account_id (String)

    The ID of the sub-account.

  • api_key (String)

    The API key.

  • name (String) (defaults to: nil)

    The display name as shown in the management console.

  • enabled (Boolean) (defaults to: nil)

    Enable or disable the access key.

  • options (Object) (defaults to: {})

    Additional options.



255
256
257
258
259
260
261
# File 'lib/cloudinary/account_api.rb', line 255

def self.update_access_key(, api_key, name = nil, enabled = nil, options = {})
  params = {
    name:    name,
    enabled: enabled,
  }
  (:put, ['sub_accounts', , 'access_keys', api_key], params, options.merge(content_type: :json))
end

.update_sub_account(sub_account_id, name = nil, cloud_name = nil, custom_attributes = nil, enabled = nil, options = {}) ⇒ Object

Updates the specified details of the sub-account.

Parameters:

  • sub_account_id (String)

    The ID of the sub-account.

  • name (String) (defaults to: nil)

    The display name as shown in the management console

  • cloud_name (String) (defaults to: nil)

    A case-insensitive cloud name comprised of alphanumeric and underscore characters. Generates an error if the specified cloud name is not unique across all Cloudinary accounts. Note: Once created, the name can only be changed for accounts with fewer than 1000 assets.

  • custom_attributes (Object) (defaults to: nil)

    Any custom attributes you want to associate with the sub-account, as a map/hash of key/value pairs.

  • enabled (Boolean) (defaults to: nil)

    Whether the sub-account is enabled.

  • options (Object) (defaults to: {})

    additional options



36
37
38
39
40
41
42
43
44
45
# File 'lib/cloudinary/account_api.rb', line 36

def self.(, name = nil, cloud_name = nil, custom_attributes = nil, enabled = nil, options = {})
  params = {
    name:              name,
    cloud_name:        cloud_name,
    custom_attributes: custom_attributes,
    enabled:           enabled
  }

  (:put, ['sub_accounts', ], params, options.merge(content_type: :json))
end

.update_user(user_id, name = nil, email = nil, role = nil, sub_account_ids = nil, options = {}) ⇒ Object

Updates the details of the specified user.

Parameters:

  • user_id (String)

    The ID of the user to update.

  • name (String) (defaults to: nil)

    The name of the user.

  • email (String) (defaults to: nil)

    A unique email address, which serves as the login name and notification address.

  • role (String) (defaults to: nil)

    The role to assign. Possible values: master_admin, admin, billing, technical_admin, reports, media_library_admin, media_library_user

  • sub_account_ids (Array<String>) (defaults to: nil)

    The list of sub-account IDs that this user can access. Note: This parameter is ignored if the role is specified as master_admin.

  • options (Object) (defaults to: {})

    additional options



112
113
114
115
116
117
118
119
120
121
# File 'lib/cloudinary/account_api.rb', line 112

def self.update_user(user_id, name = nil, email = nil, role = nil,  = nil, options = {})
  params = {
    name:            name,
    email:           email,
    role:            role,
    sub_account_ids: 
  }

  (:put, ['users', user_id], params, options.merge(content_type: :json))
end

.update_user_group(group_id, name, options = {}) ⇒ Object

Updates the specified user group.

Parameters:

  • group_id (String)

    The ID of the user group to update.

  • name (String)

    The name for the user group.

  • options (Object) (defaults to: {})

    additional options



174
175
176
177
178
179
180
# File 'lib/cloudinary/account_api.rb', line 174

def self.update_user_group(group_id, name, options = {})
  params = {
    name: name
  }

  (:put, ['user_groups', group_id], params, options.merge(content_type: :json))
end

.user(user_id, options = {}) ⇒ Object

Returns the user with the specified ID.

Parameters:

  • user_id (String)

    The ID of the user.

  • options (Object) (defaults to: {})

    additional options



126
127
128
# File 'lib/cloudinary/account_api.rb', line 126

def self.user(user_id, options = {})
  (:get, ['users', user_id], {}, options.merge(content_type: :json))
end

.user_group(group_id, options = {}) ⇒ Object

Retrieves the details of the specified user group.

Parameters:

  • group_id (String)

    The ID of the user group to retrieve.

  • options (Object) (defaults to: {})

    additional options



214
215
216
# File 'lib/cloudinary/account_api.rb', line 214

def self.user_group(group_id, options = {})
  (:get, ['user_groups', group_id], {}, options.merge(content_type: :json))
end

.user_group_users(group_id, options = {}) ⇒ Object

Lists users in the specified user group.

Parameters:

  • group_id (String)

    The ID of the user group.

  • options (Object) (defaults to: {})

    additional options



221
222
223
# File 'lib/cloudinary/account_api.rb', line 221

def self.user_group_users(group_id, options = {})
  (:get, ['user_groups', group_id, 'users'], {}, options.merge(content_type: :json))
end

.user_groups(options = {}) ⇒ Object

Lists user groups in the account.

Parameters:

  • options (Object) (defaults to: {})

    additional options



207
208
209
# File 'lib/cloudinary/account_api.rb', line 207

def self.user_groups(options = {})
  (:get, 'user_groups', {}, options.merge(content_type: :json))
end

.users(pending = nil, user_ids = [], prefix = nil, sub_account_id = nil, options = {}) ⇒ Cloudinary::Api::Response

Get a list of the users according to filters.

Parameters:

  • pending (Boolean) (defaults to: nil)

    Optional. Limit results to pending users (true), users that are not pending (false), or all users (null)

  • user_ids (Array<String>) (defaults to: [])

    Optional. List of user IDs. Up to 100

  • prefix (String) (defaults to: nil)

    Optional. Search by prefix of the user’s name or email. Case-insensitive

  • sub_account_id (String) (defaults to: nil)

    Optional. Return only users who have access to the given sub-account

  • options (Object) (defaults to: {})

    Generic advanced options map, see online documentation.

Options Hash (options):

  • :last_login (Boolean)

    Optional. Return only users that last logged in in the specified range of dates (true), users that didn’t last logged in in that range (false), or all users (null).

  • :from (Date)

    Optional. Last login start date.

  • :to (Date)

    Optional. Last login end date.

Returns:

Raises:



145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/cloudinary/account_api.rb', line 145

def self.users(pending = nil, user_ids = [], prefix = nil,  = nil, options = {})
  params = {
    ids:            user_ids,
    prefix:         prefix,
    sub_account_id: ,
    pending:        pending,
    last_login:     options[:last_login].to_s,
    from:           Cloudinary::Utils.to_usage_api_date_format(options[:from]),
    to:             Cloudinary::Utils.to_usage_api_date_format(options[:to])
  }

  (:get, 'users', params, options.merge(content_type: :json))
end