Class: ServiceNow::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/servicenow/client.rb

Defined Under Namespace

Classes: CMDB, Tables

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ Client

Returns a new instance of Client.



34
35
36
# File 'lib/servicenow/client.rb', line 34

def initialize(connection)
  @connection = connection
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



5
6
7
# File 'lib/servicenow/client.rb', line 5

def connection
  @connection
end

Class Method Details

.authenticate(instance_id, client_id, client_secret, username, password) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/servicenow/client.rb', line 8

def authenticate(instance_id, client_id, client_secret, username, password)
  connection_options = {
    url: "https://#{instance_id}.service-now.com/"
  }

  conn = Faraday.new(connection_options) do |faraday|
    faraday.request :url_encoded
    faraday.response :json
    faraday.response :raise_error
    faraday.adapter Faraday.default_adapter
  end

  params = {
    grant_type: "password",
    client_id: client_id,
    client_secret: client_secret,
    username: username,
    password: password
  }

  response = conn.post('oauth_token.do', params)
  connection = Connection.new(instance_id, response.body["access_token"])
  Client.new(connection)
end

Instance Method Details

#cmdb_instance(instance_class) ⇒ Object



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

def cmdb_instance(instance_class)
  Client::CMDB.new(@connection, instance_class)
end

#incidentsObject



38
39
40
# File 'lib/servicenow/client.rb', line 38

def incidents
  @incidents ||= Client::Tables.new(@connection, "incident")
end

#tables(table_name) ⇒ Object



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

def tables(table_name)
  Client::Tables.new(@connection, table_name)
end