Class: PritunlApiClient::User
- Inherits:
-
Object
- Object
- PritunlApiClient::User
- Defined in:
- lib/pritunl_api_client/user.rb
Overview
Interact with /user api’s
Instance Method Summary collapse
-
#all(organization_id:) ⇒ Array
Returns a list of users in an organization.
-
#create(params) ⇒ Hash, Array
Create a new user in an organization.
-
#delete(id, organization_id:) ⇒ Object
Delete an existing user in an organization, this will disconnect the user.
-
#find(id, organization_id:) ⇒ Hash
Returns a user from an organization.
-
#initialize(api) ⇒ User
constructor
A new instance of User.
-
#otp_secret(id, organization_id:) ⇒ Hash
Generate a new two-step authentication secret for an existing user.
-
#update(id, params) ⇒ Hash
Update an existing user in an organization.
Constructor Details
#initialize(api) ⇒ User
Returns a new instance of User.
7 8 9 |
# File 'lib/pritunl_api_client/user.rb', line 7 def initialize( api ) @api = api end |
Instance Method Details
#all(organization_id:) ⇒ Array
Returns a list of users in an organization
15 16 17 |
# File 'lib/pritunl_api_client/user.rb', line 15 def all( organization_id: ) @api.get( "/user/#{organization_id}" ) end |
#create(params) ⇒ Hash, Array
Create a new user in an organization. An array of users can be sent for bulk adding users
34 35 36 37 38 39 |
# File 'lib/pritunl_api_client/user.rb', line 34 def create( params ) fail ArgumentError, 'params must be a Hash or an Array' unless ( params.is_a?( Hash ) || params.is_a?( Array ) ) fail ArgumentError, '"organization_id" is a required parameter' unless params.keys.include? :organization_id organization_id = params.delete( :organization_id ) @api.post( "/user/#{organization_id}", params ) end |
#delete(id, organization_id:) ⇒ Object
Delete an existing user in an organization, this will disconnect the user
59 60 61 |
# File 'lib/pritunl_api_client/user.rb', line 59 def delete( id, organization_id: ) @api.delete( "/user/#{organization_id}/#{id}" ) end |
#find(id, organization_id:) ⇒ Hash
Returns a user from an organization
24 25 26 |
# File 'lib/pritunl_api_client/user.rb', line 24 def find( id, organization_id: ) @api.get( "/user/#{organization_id}/#{id}" ) end |
#otp_secret(id, organization_id:) ⇒ Hash
Generate a new two-step authentication secret for an existing user
68 69 70 |
# File 'lib/pritunl_api_client/user.rb', line 68 def otp_secret( id, organization_id: ) @api.put( "/user/#{organization_id}/#{id}/otp_secret" ) end |
#update(id, params) ⇒ Hash
Update an existing user in an organization
48 49 50 51 52 53 |
# File 'lib/pritunl_api_client/user.rb', line 48 def update( id, params ) fail ArgumentError, 'params must be a Hash' unless params.is_a? Hash fail ArgumentError, '"organization_id" is a required parameter' unless params.keys.include? :organization_id organization_id = params.delete( :organization_id ) @api.put( "/user/#{organization_id}/#{id}", params ) end |