Method: Warrant::Object.create

Defined in:
lib/warrant/models/object.rb

.create(params = {}, options = {}) ⇒ Object

Creates an object with the given parameters

Examples:

Create a new Object with the object type “user” and object id “test-customer”

Warrant::Object.create(object_type: "user", object_id: "test-customer")

Parameters:

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

    a customizable set of options

Options Hash (params):

  • :object_type (String)

    The type of the object (e.g. user, tenant, role, permission, etc).

  • :object_id (String)

    Customer defined string identifier for this object. Can only contain alphanumeric chars and/or ‘-’, ‘_’, ‘|’, ‘@’. If not provided, Warrant will create a univerally unique identifier (UUID) for the object and return it. If allowing Warrant to generate an id, store the id in your application so you can provide it for authorization requests on that object. (optional)

  • :meta (Hash)

    A JSON object containing additional information about this object (e.g. role name/description, user email/name, etc.) to be persisted to Warrant. (optional)

Returns:

Raises:



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/warrant/models/object.rb', line 32

def self.create(params = {}, options = {})
    res = APIOperations.post(URI.parse("#{::Warrant.config.api_base}/v2/objects"), params: Util.normalize_params(params), options: options)

    case res
    when Net::HTTPSuccess
        res_json = JSON.parse(res.body, symbolize_names: true)
        Object.new(res_json[:objectType], res_json[:objectId], res_json[:meta], res_json[:createdAt])
    else
        APIOperations.raise_error(res)
    end
end