Class: Code42::Client

Inherits:
Object
  • Object
show all
Includes:
API::Computer, API::Org, API::PasswordReset, API::Role, API::Token, API::User
Defined in:
lib/code42/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from API::PasswordReset

#reset_password

Methods included from API::Token

#delete_token, #get_login_token, #get_token, #validate_token

Methods included from API::Computer

#computer, #computers

Methods included from API::Org

#activate_org, #block_org, #create_org, #create_pro_org, #find_inactive_org_by_name, #find_org_by_name, #org, #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.



15
16
17
# File 'lib/code42/client.rb', line 15

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

Instance Attribute Details

#settingsObject

Returns the value of attribute settings.



13
14
15
# File 'lib/code42/client.rb', line 13

def settings
  @settings
end

Instance Method Details

#block_computer(id) ⇒ Code42::Computer

Block a computer from backing up

Returns:



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

def block_computer(id)
  put("computerblock/#{id}")
end

#connectionObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/code42/client.rb', line 65

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
  @connection
end

#deactivate_org(id) ⇒ Object



61
62
63
# File 'lib/code42/client.rb', line 61

def deactivate_org(id)
  put("OrgDeactivation/#{id}")
end

#diagnosticObject



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

def diagnostic
  object_from_response(Diagnostic, :get, 'diagnostic')
end

#last_responseObject



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

def last_response; connection.last_response; end

#pingBoolean

Pings the server

Returns:

  • (Boolean)

    A boolean result (this should always return true)



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

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

#unblock_computer(id) ⇒ Object



57
58
59
# File 'lib/code42/client.rb', line 57

def unblock_computer(id)
  delete("computerblock/#{id}")
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



34
35
36
37
38
# File 'lib/code42/client.rb', line 34

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



42
43
44
# File 'lib/code42/client.rb', line 42

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