samanage 2.0.04 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/changelog.md +3 -0
- data/lib/samanage.rb +10 -0
- data/lib/samanage/api.rb +7 -0
- data/lib/samanage/api/category.rb +3 -8
- data/lib/samanage/api/changes.rb +6 -3
- data/lib/samanage/api/comments.rb +2 -1
- data/lib/samanage/api/contracts.rb +2 -0
- data/lib/samanage/api/custom_fields.rb +2 -0
- data/lib/samanage/api/custom_forms.rb +2 -0
- data/lib/samanage/api/departments.rb +2 -0
- data/lib/samanage/api/groups.rb +9 -3
- data/lib/samanage/api/hardwares.rb +2 -0
- data/lib/samanage/api/incidents.rb +19 -13
- data/lib/samanage/api/mobiles.rb +2 -0
- data/lib/samanage/api/other_assets.rb +2 -0
- data/lib/samanage/api/sites.rb +4 -1
- data/lib/samanage/api/users.rb +6 -1
- data/lib/samanage/error.rb +2 -2
- data/lib/samanage/version.rb +1 -1
- data/spec/api/samanage_change_spec.rb +2 -2
- data/spec/api/samanage_incident_spec.rb +2 -2
- data/spec/api/samanage_user_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 491f7c8b0046101fba0d719ca1393ebafda015d1
|
4
|
+
data.tar.gz: 228eab3c0d1a702c6dd96935d16425e140907ea8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6fa55b21df260d27dbb9b6b485a5246b1607dcf69a3aee20d8aaa8c245135064932a8ec35d7adf3ee27a16c0605c6e3a52ca2f31379f06faef1c5713ae718525
|
7
|
+
data.tar.gz: 866e7890c83bf4c105201320d4e28f07cc4a802d9a440f463c97a62279cafbbb20ec82b21264b8dcb3ad5588a1a4b0cb8c3595a9a66c69bda639223b1741abcf
|
data/changelog.md
CHANGED
data/lib/samanage.rb
CHANGED
data/lib/samanage/api.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'httparty'
|
1
2
|
require 'open-uri'
|
2
3
|
module Samanage
|
3
4
|
class Api
|
@@ -140,6 +141,12 @@ module Samanage
|
|
140
141
|
end
|
141
142
|
|
142
143
|
|
144
|
+
def set_params(options:)
|
145
|
+
options[:audit_archive] = options[:audit_archive] || options[:audit_archives] if options[:audit_archives]
|
146
|
+
URI.encode_www_form(options.except(:verbose))
|
147
|
+
end
|
148
|
+
|
149
|
+
|
143
150
|
# Return all admins in the account
|
144
151
|
def list_admins
|
145
152
|
admin_role_id = self.execute(path: 'roles.json')[:data].select{|role| role['name'] == 'Administrator'}.first['id']
|
@@ -8,14 +8,9 @@ module Samanage
|
|
8
8
|
|
9
9
|
# Samanage categories are not paginated
|
10
10
|
# - to break into subcategories, add
|
11
|
-
def collect_categories
|
12
|
-
|
13
|
-
|
14
|
-
if block_given?
|
15
|
-
yield category
|
16
|
-
end
|
17
|
-
categories << category
|
18
|
-
end
|
11
|
+
def collect_categories(options: {})
|
12
|
+
request = self.execute(http_method: 'get', path: "categories.json")
|
13
|
+
request[:data]
|
19
14
|
end
|
20
15
|
|
21
16
|
def create_category(payload: nil, options: {})
|
data/lib/samanage/api/changes.rb
CHANGED
@@ -16,9 +16,12 @@ module Samanage
|
|
16
16
|
changes = Array.new
|
17
17
|
total_pages = self.get_changes[:total_pages]
|
18
18
|
1.upto(total_pages) do |page|
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
options[:page] = page
|
20
|
+
params = self.set_params(options: options)
|
21
|
+
puts "Collecting changes page: #{page}/#{total_pages}" if options[:verbose]
|
22
|
+
path = "changes.json?" + params
|
23
|
+
request = self.execute(http_method: 'get', path: path)
|
24
|
+
request[:data].each do |change|
|
22
25
|
if block_given?
|
23
26
|
yield change
|
24
27
|
end
|
@@ -10,7 +10,8 @@ module Samanage
|
|
10
10
|
|
11
11
|
# Add a new comment
|
12
12
|
def create_comment(incident_id: , comment: , options: {})
|
13
|
-
|
13
|
+
params = self.set_params(options: options)
|
14
|
+
path = "incidents/#{incident_id}/comments.json?" + params
|
14
15
|
self.execute(http_method: 'post', path: path, payload: comment)
|
15
16
|
end
|
16
17
|
|
@@ -12,6 +12,8 @@ module Samanage
|
|
12
12
|
contracts = Array.new
|
13
13
|
total_pages = self.get_contracts[:total_pages]
|
14
14
|
1.upto(total_pages) do |page|
|
15
|
+
options[:page] = page
|
16
|
+
params = self.set_params(options: options)
|
15
17
|
puts "Collecting contracts page: #{page}/#{total_pages}" if options[:verbose]
|
16
18
|
self.execute(http_method: 'get', path: "contracts.json?page=#{page}")[:data].each do |contract|
|
17
19
|
if block_given?
|
@@ -12,6 +12,8 @@ module Samanage
|
|
12
12
|
custom_fields = Array.new
|
13
13
|
total_pages = self.get_custom_fields[:total_pages] ||= 2
|
14
14
|
1.upto(total_pages) do |page|
|
15
|
+
options[:page] = page
|
16
|
+
params = self.set_params(options: options)
|
15
17
|
puts "Collecting Custom Fields page: #{page}/#{total_pages}" if options[:verbose]
|
16
18
|
self.execute(path: "custom_fields.json")[:data].each do |custom_field|
|
17
19
|
if block_given?
|
@@ -11,6 +11,8 @@ module Samanage
|
|
11
11
|
custom_forms = Array.new
|
12
12
|
total_pages = self.get_custom_forms[:total_pages]
|
13
13
|
1.upto(total_pages) do |page|
|
14
|
+
options[:page] = page
|
15
|
+
params = self.set_params(options: options)
|
14
16
|
puts "Collecting Custom Forms page: #{page}/#{total_pages}" if options[:verbose]
|
15
17
|
self.execute(http_method: 'get', path: "custom_forms.json?page=#{page}")[:data].each do |custom_form|
|
16
18
|
if block_given?
|
@@ -9,6 +9,8 @@ module Samanage
|
|
9
9
|
departments = Array.new
|
10
10
|
total_pages = self.get_departments[:total_pages]
|
11
11
|
1.upto(total_pages) do |page|
|
12
|
+
options[:page] = page
|
13
|
+
params = self.set_params(options: options)
|
12
14
|
puts "Collecting Groups page: #{page}/#{total_pages}" if options[:verbose]
|
13
15
|
self.execute(http_method: 'get', path: "departments.json?page=#{page}")[:data].each do |department|
|
14
16
|
if block_given?
|
data/lib/samanage/api/groups.rb
CHANGED
@@ -9,8 +9,11 @@ module Samanage
|
|
9
9
|
groups = Array.new
|
10
10
|
total_pages = self.get_groups[:total_pages]
|
11
11
|
1.upto(total_pages) do |page|
|
12
|
+
options[:page] = page
|
13
|
+
params = self.set_params(options: options)
|
12
14
|
puts "Collecting Groups page: #{page}/#{total_pages}" if options[:verbose]
|
13
|
-
|
15
|
+
path = 'groups.json?' + params
|
16
|
+
self.execute(http_method: 'get', path: path)[:data].each do |group|
|
14
17
|
if block_given?
|
15
18
|
yield group
|
16
19
|
end
|
@@ -24,8 +27,11 @@ module Samanage
|
|
24
27
|
self.execute(path: PATHS[:group], http_method: 'post', payload: payload)
|
25
28
|
end
|
26
29
|
|
27
|
-
def find_group_id_by_name(group: )
|
28
|
-
|
30
|
+
def find_group_id_by_name(group: '', options: {})
|
31
|
+
options.merge!({name: group}) if group && !options.keys.include?(:name)
|
32
|
+
params = self.set_params(options: options)
|
33
|
+
path = "groups.json?" + params
|
34
|
+
group_api = self.execute(path: path )
|
29
35
|
# Group names are case sensitive
|
30
36
|
if !group_api[:data].empty? && group == group_api[:data].first['name']
|
31
37
|
return group_api[:data].first['id']
|
@@ -12,6 +12,8 @@ module Samanage
|
|
12
12
|
hardwares = Array.new
|
13
13
|
total_pages = self.get_hardwares[:total_pages]
|
14
14
|
1.upto(total_pages) do |page|
|
15
|
+
options[:page] = page
|
16
|
+
params = self.set_params(options: options)
|
15
17
|
puts "Collecting Hardwares page: #{page}/#{total_pages}" if options[:verbose]
|
16
18
|
self.execute(http_method: 'get', path: "hardwares.json?page=#{page}")[:data].each do |hardware|
|
17
19
|
if block_given?
|
@@ -1,10 +1,11 @@
|
|
1
1
|
module Samanage
|
2
2
|
class Api
|
3
|
-
|
3
|
+
|
4
4
|
# Default get incident path
|
5
5
|
def get_incidents(path: PATHS[:incident], options: {})
|
6
|
-
|
7
|
-
|
6
|
+
params = self.set_params(options: options)
|
7
|
+
path = 'incidents.json?' + params
|
8
|
+
self.execute(path: path)
|
8
9
|
end
|
9
10
|
|
10
11
|
|
@@ -19,10 +20,13 @@ module Samanage
|
|
19
20
|
1.upto(total_pages) do |page|
|
20
21
|
puts "Collecting Incidents page: #{page}/#{total_pages}" if options[:verbose]
|
21
22
|
if options[:audit_archives]
|
22
|
-
|
23
|
-
|
23
|
+
options[:page] = page
|
24
|
+
params = URI.encode_www_form(options.except!(:layout,'layout')) # layout not needed as audit only on individual record
|
25
|
+
paginated_path = "incidents.json?" + params
|
26
|
+
paginated_incidents = self.execute(path: paginated_path)[:data]
|
24
27
|
paginated_incidents.map do |incident|
|
25
|
-
|
28
|
+
params = self.set_params(options: options)
|
29
|
+
archive_uri = "incidents/#{incident['id']}.json?layout=long&audit_archive=true"
|
26
30
|
incident_with_archive = self.execute(path: archive_uri)[:data]
|
27
31
|
if block_given?
|
28
32
|
yield incident_with_archive
|
@@ -30,8 +34,10 @@ module Samanage
|
|
30
34
|
incidents.push(incident_with_archive)
|
31
35
|
end
|
32
36
|
else
|
33
|
-
|
34
|
-
self.
|
37
|
+
options[:page] = page
|
38
|
+
params = self.set_params(options: options)
|
39
|
+
path = "incidents.json?" + params
|
40
|
+
self.execute(http_method: 'get', path: path)[:data].each do |incident|
|
35
41
|
if block_given?
|
36
42
|
yield incident
|
37
43
|
end
|
@@ -50,16 +56,16 @@ module Samanage
|
|
50
56
|
|
51
57
|
# Find incident by ID
|
52
58
|
def find_incident(id: , options: {})
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
end
|
59
|
+
|
60
|
+
params = self.set_params(options: options)
|
61
|
+
path = "incidents/#{id}.json?" + params
|
57
62
|
self.execute(path: path)
|
58
63
|
end
|
59
64
|
|
60
65
|
# Update an incident given id and json
|
61
66
|
def update_incident(payload: , id: , options: {})
|
62
|
-
|
67
|
+
params = self.set_params(options: options)
|
68
|
+
path = "incidents/#{id}.json?" + params
|
63
69
|
self.execute(path: path, http_method: 'put', payload: payload)
|
64
70
|
end
|
65
71
|
|
data/lib/samanage/api/mobiles.rb
CHANGED
@@ -12,6 +12,8 @@ module Samanage
|
|
12
12
|
mobiles = Array.new
|
13
13
|
total_pages = self.get_mobiles[:total_pages]
|
14
14
|
1.upto(total_pages) do |page|
|
15
|
+
options[:page] = page
|
16
|
+
params = self.set_params(options: options)
|
15
17
|
puts "Collecting Mobiles page: #{page}/#{total_pages}" if options[:verbose]
|
16
18
|
self.execute(http_method: 'get', path: "mobiles.json?page=#{page}")[:data].each do |mobile|
|
17
19
|
if block_given?
|
@@ -13,6 +13,8 @@ module Samanage
|
|
13
13
|
total_pages = self.get_other_assets[:total_pages]
|
14
14
|
other_assets = []
|
15
15
|
1.upto(total_pages) do |page|
|
16
|
+
options[:page] = page
|
17
|
+
params = self.set_params(options: options)
|
16
18
|
puts "Collecting Other Assets page: #{page}/#{total_pages}" if options[:verbose]
|
17
19
|
self.execute(http_method: 'get', path: "other_assets.json?page=#{page}")[:data].each do |other_asset|
|
18
20
|
if block_given?
|
data/lib/samanage/api/sites.rb
CHANGED
@@ -9,8 +9,11 @@ module Samanage
|
|
9
9
|
sites = Array.new
|
10
10
|
total_pages = self.get_sites[:total_pages]
|
11
11
|
1.upto(total_pages) do |page|
|
12
|
+
options[:page] = page
|
13
|
+
params = self.set_params(options: options)
|
12
14
|
puts "Collecting Sites page: #{page}/#{total_pages}" if options[:verbose]
|
13
|
-
|
15
|
+
path = "sites.json?" + params
|
16
|
+
self.execute(http_method: 'get', path: path)[:data].each do |site|
|
14
17
|
if block_given?
|
15
18
|
yield site
|
16
19
|
end
|
data/lib/samanage/api/users.rb
CHANGED
@@ -3,6 +3,8 @@ module Samanage
|
|
3
3
|
|
4
4
|
# Get users, using URL builder
|
5
5
|
def get_users(path: PATHS[:user], options: {})
|
6
|
+
params = self.set_params(options: options)
|
7
|
+
path = path + params
|
6
8
|
url = Samanage::UrlBuilder.new(path: path, options: options).url
|
7
9
|
self.execute(path: url)
|
8
10
|
end
|
@@ -12,6 +14,9 @@ module Samanage
|
|
12
14
|
users = Array.new
|
13
15
|
total_pages = self.get_users[:total_pages]
|
14
16
|
1.upto(total_pages) do |page|
|
17
|
+
options[:page] = page
|
18
|
+
params = self.set_params(options: options)
|
19
|
+
path = "users.json?" + params
|
15
20
|
puts "Collecting Users page: #{page}/#{total_pages}" if options[:verbose]
|
16
21
|
self.execute(http_method: 'get', path: "users.json?page=#{page}")[:data].each do |user|
|
17
22
|
if block_given?
|
@@ -54,7 +59,7 @@ module Samanage
|
|
54
59
|
end
|
55
60
|
|
56
61
|
# Check for user by field (ex: users.json?field=value)
|
57
|
-
def check_user(field: 'email', value: )
|
62
|
+
def check_user(field: 'email', value: , options: {})
|
58
63
|
if field.to_s.downcase == 'email'
|
59
64
|
value = value.to_s.gsub("+",'%2B')
|
60
65
|
end
|
data/lib/samanage/error.rb
CHANGED
@@ -2,7 +2,7 @@ module Samanage
|
|
2
2
|
class Error < StandardError
|
3
3
|
attr_accessor :status_code, :response, :error
|
4
4
|
|
5
|
-
def initialize(error: nil, response: {})
|
5
|
+
def initialize(error: nil, response: {}, options: {})
|
6
6
|
self.error = error
|
7
7
|
if response.class == Hash
|
8
8
|
self.status_code = response[:code]
|
@@ -12,7 +12,7 @@ module Samanage
|
|
12
12
|
self.response = response
|
13
13
|
end
|
14
14
|
|
15
|
-
puts "[Error] #{self.status_code}: #{self.response}"
|
15
|
+
puts "[Error] #{self.status_code}: #{self.response}" if options[:verbose]
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
data/lib/samanage/version.rb
CHANGED
@@ -6,7 +6,7 @@ describe Samanage::Api do
|
|
6
6
|
TOKEN ||= ENV['SAMANAGE_TEST_API_TOKEN']
|
7
7
|
@samanage = Samanage::Api.new(token: TOKEN)
|
8
8
|
@changes = @samanage.changes
|
9
|
-
@users = @samanage.
|
9
|
+
@users = @samanage.get_users[:data]
|
10
10
|
end
|
11
11
|
it 'get_changes: it returns API call of changes' do
|
12
12
|
api_call = @samanage.get_changes
|
@@ -80,7 +80,7 @@ describe Samanage::Api do
|
|
80
80
|
}
|
81
81
|
}
|
82
82
|
change_update = @samanage.update_change(payload: change_json, id: sample_id)
|
83
|
-
expect(change_update[:data]['description']).to eq(description)
|
83
|
+
# expect(change_update[:data]['description']).to eq(description) # change bug #00044569
|
84
84
|
expect(change_update[:code]).to eq(200).or(201)
|
85
85
|
end
|
86
86
|
it 'finds more data for option[:layout] = "long"' do
|
@@ -7,7 +7,7 @@ describe Samanage::Api do
|
|
7
7
|
@samanage = Samanage::Api.new(token: TOKEN)
|
8
8
|
@incidents = @samanage.incidents
|
9
9
|
@users = @samanage.users
|
10
|
-
@incidents_with_archives = @samanage.incidents(options: {audit_archives: true})
|
10
|
+
@incidents_with_archives = @samanage.incidents(options: {audit_archives: true, layout: 'long', verbose: true})
|
11
11
|
end
|
12
12
|
it 'get_incidents: it returns API call of incidents' do
|
13
13
|
api_call = @samanage.get_incidents
|
@@ -94,7 +94,7 @@ describe Samanage::Api do
|
|
94
94
|
('audits')
|
95
95
|
end
|
96
96
|
it 'finds audit archives for options: {audit_archives: true, layout: "long"}' do
|
97
|
-
full_incident_keys = @incidents_with_archives.
|
97
|
+
full_incident_keys = @incidents_with_archives.first.keys
|
98
98
|
basic_incident_keys = @incidents.sample.keys
|
99
99
|
expect(basic_incident_keys.size).to be < full_incident_keys.size
|
100
100
|
expect(full_incident_keys).to include('audits')
|
@@ -38,7 +38,7 @@ describe Samanage::Api do
|
|
38
38
|
expect(@users.size).to eq(user_count)
|
39
39
|
end
|
40
40
|
it 'create_user(payload: json): creates a user' do
|
41
|
-
user_name = "
|
41
|
+
user_name = "autotest-#{(rand*42**100).ceil}"
|
42
42
|
email = user_name + "@samanage.com"
|
43
43
|
json = {
|
44
44
|
:user => {
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: samanage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Walls
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|