Class: Code42::Client

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
API::Computer, API::Destination, API::Diagnostic, API::Org, API::PasswordReset, API::ProductLicense, API::Role, API::Server, API::ServerConnectionString, API::ServerSettings, API::StorePoint, API::Token, API::User
Defined in:
lib/code42/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from API::ServerConnectionString

#server_connection_string

Methods included from API::Diagnostic

#diagnostic

Methods included from API::StorePoint

#find_store_point_by_id, #find_store_points_by_name, #store_points, #update_store_point

Methods included from API::PasswordReset

#reset_password

Methods included from API::Server

#create_server, #server, #servers

Methods included from API::Destination

#create_destination, #destination, #destinations

Methods included from API::ServerSettings

#server_settings, #update_server_settings

Methods included from API::ProductLicense

#add_product_license, #product_licenses, #remove_product_license

Methods included from API::Token

#apply_mlk, #delete_token, #get_login_token, #get_token, #validate_token

Methods included from API::Computer

#block_computer, #computer, #computers, #unblock_computer

Methods included from API::Org

#activate_org, #block_org, #create_org, #create_pro_org, #deactivate_org, #find_inactive_org_by_name, #find_org_by_name, #org, #org_share_destinations, #orgs, #search_orgs, #unblock_org, #update_org

Methods included from API::Role

#assign_role, #create_role, #delete_role, #role, #roles, #unassign_role, #update_role, #user_roles

Methods included from API::User

#activate_user, #block_user, #create_user, #deactivate_user, #find_user_by_channel_id, #find_user_by_id, #find_user_by_username, #permissions, #unblock_user, #update_user, #user, #user_exists?, #users

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



27
28
29
# File 'lib/code42/client.rb', line 27

def initialize(options = {})
  self.settings = options
end

Instance Attribute Details

#settingsObject

Returns the value of attribute settings.



21
22
23
# File 'lib/code42/client.rb', line 21

def settings
  @settings
end

Instance Method Details

#connectionObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/code42/client.rb', line 58

def connection
  @connection ||= begin
                    connection = Connection.new
                    settings.debug && connection.use(Faraday::Response::Logger)
                    connection
                  end
  @connection.host         = settings.host
  @connection.port         = settings.port
  @connection.scheme       = settings.scheme
  @connection.path_prefix  = settings.api_root
  @connection.verify_https = settings.verify_https
  if settings.username && settings.password
    @connection.username = settings.username
    @connection.password = settings.password
  end
  if settings.token
    @connection.token = settings.token
  end
  if settings.mlk
    @connection.mlk = settings.mlk
  end
  @connection
end

#last_responseObject



31
# File 'lib/code42/client.rb', line 31

def last_response; connection.last_response; end

#pingBoolean

Pings the server

Returns:

  • (Boolean)

    A boolean result (this should always return true)



39
40
41
# File 'lib/code42/client.rb', line 39

def ping
  get('ping')['data']['success']
end

#use_basic_auth(username, password) ⇒ Object

Use basic authentication for future requests

Parameters:

  • username (String)

    The username to authenticate with

  • password (String)

    The password to authenticate with



46
47
48
49
50
# File 'lib/code42/client.rb', line 46

def use_basic_auth(username, password)
  settings.token = nil
  settings.username = username
  settings.password = password
end

#use_token_auth(token) ⇒ Object

Use token authentication for future requests

Parameters:

  • token (Code42::Token, String)

    The token to authenticate with



54
55
56
# File 'lib/code42/client.rb', line 54

def use_token_auth(token)
  settings.token = token.to_s
end