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.



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.



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.



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.



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



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.



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