Module: Auth0::Api::V2::Connections

Included in:
Auth0::Api::V2
Defined in:
lib/auth0/api/v2/connections.rb

Overview

Methods to use the connections endpoints

Instance Method Summary collapse

Instance Method Details

#connection(connection_id, fields: nil, include_fields: true) ⇒ json

Retrieves a connection by its id.

Parameters:

  • connection_id (string)

    The id of the connection to retrieve.

  • fields (string)

    A comma separated list of fields to include or exclude from the result.

  • include_fields (boolean)

    True if the fields specified are to be included in the result, false otherwise.

Returns:

  • (json)

    Returns the matching connection.

Raises:

See Also:



54
55
56
57
58
59
60
61
62
# File 'lib/auth0/api/v2/connections.rb', line 54

def connection(connection_id, fields: nil, include_fields: true)
  raise Auth0::InvalidParameter, 'Must supply a valid connection id' if connection_id.to_s.empty?
  path = "#{connections_path}/#{connection_id}"
  request_params = {
    fields:         fields,
    include_fields: include_fields
  }
  get(path, request_params)
end

#connections(strategy: nil, fields: nil, include_fields: nil, page: nil, per_page: nil) ⇒ json Also known as: get_connections

Retrieves every connection matching the specified strategy. All connections are retrieved if no strategy is being specified. Accepts a list of fields to include or exclude in the resulting list of connection objects.

Parameters:

  • strategy (string)

    Strategy to filter connection results.

  • fields (string)

    A comma separated list of fields to include or exclude from the result.

  • include_fields (boolean)

    True if the fields specified are to be included in the result, false otherwise.

  • page (int)

    Page number to get, 0-based.

  • per_page (int)

    Results per page if also passing a page number.

Returns:

  • (json)

    Returns the existing connections matching the strategy.

See Also:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/auth0/api/v2/connections.rb', line 17

def connections(
  strategy: nil,
  fields: nil,
  include_fields: nil,
  page: nil,
  per_page: nil
)
  include_fields = true if !fields.nil? && include_fields.nil?
  request_params = {
    strategy: strategy,
    fields: fields.is_a?(Array) ? fields.join(',') : fields,
    include_fields: include_fields,
    page: !page.nil? ? page.to_i : nil,
    per_page: !page.nil? && !per_page.nil? ? per_page.to_i : nil
  }
  get(connections_path, request_params)
end

#create_connection(body) ⇒ json

Creates a new connection according to the JSON object received in body.

Parameters:

  • body (hash)

    The Hash options used to define the conecctions's properties.

Returns:

  • (json)

    Returns the created connection.

Raises:

See Also:



41
42
43
44
45
# File 'lib/auth0/api/v2/connections.rb', line 41

def create_connection(body)
  raise Auth0::InvalidParameter, 'Must specify a body to create a connection' if body.to_s.empty?
  request_params = body
  post(connections_path, request_params)
end

#delete_connection(connection_id) ⇒ Object

Deletes a connection and all its users.

Parameters:

  • connection_id (string)

    The id of the connection to delete.

Raises:

See Also:



67
68
69
70
71
# File 'lib/auth0/api/v2/connections.rb', line 67

def delete_connection(connection_id)
  raise Auth0::InvalidParameter, 'Must supply a valid connection id' if connection_id.to_s.empty?
  path = "#{connections_path}/#{connection_id}"
  delete(path)
end

#delete_connection_user(connection_id, user_email) ⇒ Object

Deletes a specified connection user by its email (currently only database connections are supported and you cannot delete all users from specific connection).

Parameters:

  • connection_id (string)

    The id of the connection.

  • user_email (string)

    The email of the user to delete.

Raises:

See Also:



78
79
80
81
82
83
# File 'lib/auth0/api/v2/connections.rb', line 78

def delete_connection_user(connection_id, user_email)
  raise Auth0::InvalidParameter, 'Must supply a valid connection id' if connection_id.to_s.empty?
  raise Auth0::InvalidParameter, 'Must supply a valid user email' if user_email.to_s.empty?
  path = "#{connections_path}/#{connection_id}/users?email=#{user_email}"
  delete(path)
end

#update_connection(connection_id, body) ⇒ json

Updates a connection. Updates the fields specified in the body parameter.

Parameters:

  • connection_id (string)

    The id of the connection to delete.

  • body (hash)

    The Hash options used to update the conecctions's properties.

Returns:

  • (json)

    Returns the updated connection.

Raises:

See Also:



91
92
93
94
95
# File 'lib/auth0/api/v2/connections.rb', line 91

def update_connection(connection_id, body)
  raise Auth0::InvalidParameter, 'Must supply a valid connection id' if connection_id.to_s.empty?
  path = "#{connections_path}/#{connection_id}"
  patch(path, body)
end