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) (defaults to: nil)

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

  • include_fields (boolean) (defaults to: true)

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

Returns:

  • (json)

    Returns the matching connection.

Raises:

See Also:



60
61
62
63
64
65
66
67
68
# File 'lib/auth0/api/v2/connections.rb', line 60

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, name: nil, fields: nil, include_fields: nil, page: nil, per_page: nil, include_totals: 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) (defaults to: nil)

    Strategy to filter connection results.

  • name (string) (defaults to: nil)

    Name to filter connection results.

  • fields (string) (defaults to: nil)

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

  • include_fields (boolean) (defaults to: nil)

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

  • page (int) (defaults to: nil)

    Page number to get, 0-based.

  • per_page (int) (defaults to: nil)

    Results per page if also passing a page number.

  • include_totals (boolean) (defaults to: nil)

    True if query totals should be included in the result. Defaults to false.

Returns:

  • (json)

    Returns the existing connections matching the strategy.

See Also:



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/auth0/api/v2/connections.rb', line 19

def connections(
  strategy: nil,
  name: nil,
  fields: nil,
  include_fields: nil,
  page: nil,
  per_page: nil,
  include_totals: nil
)
  include_fields = true if !fields.nil? && include_fields.nil?
  request_params = {
    strategy: strategy,
    name: name,
    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,
    include_totals: include_totals
  }
  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 connections’s properties.

Returns:

  • (json)

    Returns the created connection.

Raises:

See Also:



47
48
49
50
51
# File 'lib/auth0/api/v2/connections.rb', line 47

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:



73
74
75
76
77
# File 'lib/auth0/api/v2/connections.rb', line 73

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:



84
85
86
87
88
89
90
91
92
# File 'lib/auth0/api/v2/connections.rb', line 84

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"
  request_params = {
    email: user_email
  }
  delete(path, request_params)
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:



100
101
102
103
104
# File 'lib/auth0/api/v2/connections.rb', line 100

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