samanage 1.9.33 → 2.0.03
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -2
- data/Gemfile.lock +24 -26
- data/changelog.md +13 -0
- data/lib/samanage.rb +2 -1
- data/lib/samanage/api.rb +140 -144
- data/lib/samanage/api/attachments.rb +21 -0
- data/lib/samanage/api/category.rb +24 -19
- data/lib/samanage/api/changes.rb +59 -0
- data/lib/samanage/api/comments.rb +13 -13
- data/lib/samanage/api/contracts.rb +51 -47
- data/lib/samanage/api/custom_fields.rb +23 -19
- data/lib/samanage/api/custom_forms.rb +42 -38
- data/lib/samanage/api/departments.rb +25 -22
- data/lib/samanage/api/groups.rb +43 -39
- data/lib/samanage/api/hardwares.rb +57 -53
- data/lib/samanage/api/incidents.rb +60 -51
- data/lib/samanage/api/mobiles.rb +50 -46
- data/lib/samanage/api/other_assets.rb +47 -43
- data/lib/samanage/api/requester.rb +7 -7
- data/lib/samanage/api/sites.rb +27 -23
- data/lib/samanage/api/users.rb +58 -54
- data/lib/samanage/api/utils.rb +0 -19
- data/lib/samanage/error.rb +20 -20
- data/lib/samanage/url_builder.rb +53 -53
- data/lib/samanage/version.rb +2 -2
- data/samanage.gemspec +2 -2
- data/sample_file.txt +1 -0
- data/spec/api/samanage_attachment_spec.rb +14 -0
- data/spec/api/samanage_category_spec.rb +24 -24
- data/spec/api/samanage_change_spec.rb +98 -0
- data/spec/api/samanage_comments_spec.rb +25 -32
- data/spec/api/samanage_contract_spec.rb +62 -68
- data/spec/api/samanage_custom_field_spec.rb +12 -12
- data/spec/api/samanage_custom_form_spec.rb +24 -24
- data/spec/api/samanage_department_spec.rb +35 -36
- data/spec/api/samanage_group_spec.rb +59 -59
- data/spec/api/samanage_hardware_spec.rb +80 -85
- data/spec/api/samanage_incident_spec.rb +99 -103
- data/spec/api/samanage_mobile_spec.rb +70 -74
- data/spec/api/samanage_other_asset_spec.rb +72 -76
- data/spec/api/samanage_site_spec.rb +45 -45
- data/spec/api/samanage_user_spec.rb +117 -100
- data/spec/api/samanage_util_spec.rb +4 -9
- data/spec/samanage_api_spec.rb +48 -48
- data/spec/samanage_category_spec.rb +21 -28
- data/spec/samanage_url_builder_spec.rb +15 -15
- metadata +15 -11
- data/lib/data/gd-class2-root.crt +0 -24
@@ -1,26 +1,31 @@
|
|
1
1
|
module Samanage
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
class Api
|
3
|
+
def get_categories(path: PATHS[:category], options: {})
|
4
|
+
url = Samanage::UrlBuilder.new(path: path, options: options).url
|
5
|
+
self.execute(path: url)
|
6
|
+
end
|
7
7
|
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
9
|
+
# Samanage categories are not paginated
|
10
|
+
# - to break into subcategories, add
|
11
|
+
def collect_categories
|
12
|
+
categories = Array.new
|
13
|
+
self.execute(http_method: 'get', path: "categories.json")[:data].each do |category|
|
14
|
+
if block_given?
|
15
|
+
yield category
|
16
|
+
end
|
17
|
+
categories << category
|
18
|
+
end
|
19
|
+
end
|
15
20
|
|
16
|
-
|
17
|
-
|
18
|
-
|
21
|
+
def create_category(payload: nil, options: {})
|
22
|
+
self.execute(path: PATHS[:category], http_method: 'post', payload: payload)
|
23
|
+
end
|
19
24
|
|
20
|
-
|
21
|
-
|
22
|
-
|
25
|
+
def delete_category(id: )
|
26
|
+
self.execute(path: "categories/#{id}", http_method: 'delete')
|
27
|
+
end
|
23
28
|
|
24
|
-
|
25
|
-
|
29
|
+
alias_method :categories, :collect_categories
|
30
|
+
end
|
26
31
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Samanage
|
2
|
+
class Api
|
3
|
+
|
4
|
+
# Default get change path
|
5
|
+
def get_changes(path: PATHS[:change], options: {})
|
6
|
+
url = Samanage::UrlBuilder.new(path: path, options: options).url
|
7
|
+
self.execute(path: url)
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
# Returns all changes.
|
12
|
+
# Options:
|
13
|
+
# - audit_archives: true
|
14
|
+
# - layout: 'long'
|
15
|
+
def collect_changes(options: {})
|
16
|
+
changes = Array.new
|
17
|
+
total_pages = self.get_changes[:total_pages]
|
18
|
+
1.upto(total_pages) do |page|
|
19
|
+
puts "Collecting changes page: #{page}/#{total_pages}" if options[:verbose]
|
20
|
+
layout = options[:layout] == 'long' ? '&layout=long' : nil
|
21
|
+
self.execute(http_method: 'get', path: "changes.json?page=#{page}#{layout}")[:data].each do |change|
|
22
|
+
if block_given?
|
23
|
+
yield change
|
24
|
+
end
|
25
|
+
changes << change
|
26
|
+
end
|
27
|
+
end
|
28
|
+
changes
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
# Create an change given json
|
33
|
+
def create_change(payload: nil, options: {})
|
34
|
+
self.execute(path: PATHS[:change], http_method: 'post', payload: payload)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Find change by ID
|
38
|
+
def find_change(id: , options: {})
|
39
|
+
path = "changes/#{id}.json"
|
40
|
+
if options[:layout] == 'long'
|
41
|
+
path += '?layout=long'
|
42
|
+
end
|
43
|
+
self.execute(path: path)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Update an change given id and json
|
47
|
+
def update_change(payload: , id: , options: {})
|
48
|
+
path = "changes/#{id}.json"
|
49
|
+
self.execute(path: path, http_method: 'put', payload: payload)
|
50
|
+
end
|
51
|
+
|
52
|
+
def delete_change(id: )
|
53
|
+
self.execute(path: "changes/#{id}.json", http_method: 'delete')
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
alias_method :changes, :collect_changes
|
58
|
+
end
|
59
|
+
end
|
@@ -1,20 +1,20 @@
|
|
1
1
|
module Samanage
|
2
|
-
|
2
|
+
class Api
|
3
3
|
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
# Find comments given incident_id
|
6
|
+
def get_comments(incident_id: )
|
7
|
+
path = "incidents/#{incident_id}/comments.json"
|
8
|
+
self.execute(path: path)
|
9
|
+
end
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
# Add a new comment
|
12
|
+
def create_comment(incident_id: , comment: , options: {})
|
13
|
+
path = "incidents/#{incident_id}/comments.json"
|
14
|
+
self.execute(http_method: 'post', path: path, payload: comment)
|
15
|
+
end
|
16
16
|
|
17
17
|
|
18
|
-
|
19
|
-
|
18
|
+
alias_method :comments, :get_comments
|
19
|
+
end
|
20
20
|
end
|
@@ -1,58 +1,62 @@
|
|
1
1
|
module Samanage
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
2
|
+
class Api
|
3
|
+
|
4
|
+
# Get contract default path
|
5
|
+
def get_contracts(path: PATHS[:contract], options: {})
|
6
|
+
url = Samanage::UrlBuilder.new(path: path, options: options).url
|
7
|
+
self.execute(path: url)
|
8
|
+
end
|
9
|
+
|
10
|
+
# Get all contracts
|
11
|
+
def collect_contracts(options: {})
|
12
|
+
contracts = Array.new
|
13
|
+
total_pages = self.get_contracts[:total_pages]
|
14
|
+
1.upto(total_pages) do |page|
|
15
|
+
puts "Collecting contracts page: #{page}/#{total_pages}" if options[:verbose]
|
16
|
+
self.execute(http_method: 'get', path: "contracts.json?page=#{page}")[:data].each do |contract|
|
17
|
+
if block_given?
|
18
|
+
yield contract
|
19
|
+
end
|
20
|
+
contracts << contract
|
21
|
+
end
|
22
|
+
end
|
23
|
+
contracts
|
24
|
+
end
|
25
|
+
|
26
|
+
# Create contract given json payload
|
27
|
+
def create_contract(payload: , options: {})
|
28
|
+
self.execute(path: PATHS[:contract], http_method: 'post', payload: payload)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Find contract given id
|
32
|
+
def find_contract(id: )
|
33
|
+
path = "contracts/#{id}.json"
|
34
|
+
self.execute(path: path)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Check for contract using URL builder
|
38
|
+
def check_contract(options: {})
|
39
|
+
url = Samanage::UrlBuilder.new(path: PATHS[:contract], options: options).url
|
40
|
+
self.execute(path: url)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Update contract given id
|
44
|
+
def update_contract(payload: , id: , options: {})
|
45
|
+
path = "contracts/#{id}.json"
|
46
|
+
self.execute(path: path, http_method: 'put', payload: payload)
|
47
|
+
end
|
44
48
|
|
45
49
|
def add_item_to_contract(id: , payload: )
|
46
50
|
path = "contracts/#{id}/items.json"
|
47
51
|
self.execute(path: path, http_method: 'post', payload: payload)
|
48
|
-
|
49
|
-
|
50
|
-
|
52
|
+
end
|
53
|
+
|
54
|
+
def delete_contract(id: )
|
51
55
|
self.execute(path: "contracts/#{id}.json", http_method: 'delete')
|
52
56
|
end
|
53
57
|
|
54
58
|
|
55
59
|
|
56
|
-
|
57
|
-
|
60
|
+
alias_method :contracts, :collect_contracts
|
61
|
+
end
|
58
62
|
end
|
@@ -1,25 +1,29 @@
|
|
1
1
|
module Samanage
|
2
|
-
|
2
|
+
class Api
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
# Get custom fields default url
|
5
|
+
def get_custom_fields(path: PATHS[:custom_fields], options:{})
|
6
|
+
url = Samanage::UrlBuilder.new(path: path, options: options).url
|
7
|
+
self.execute(path: url)
|
8
|
+
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
10
|
+
# Gets all custom fields
|
11
|
+
def collect_custom_fields(options: {})
|
12
|
+
custom_fields = Array.new
|
13
|
+
total_pages = self.get_custom_fields[:total_pages] ||= 2
|
14
|
+
1.upto(total_pages) do |page|
|
15
|
+
puts "Collecting Custom Fields page: #{page}/#{total_pages}" if options[:verbose]
|
16
|
+
self.execute(path: "custom_fields.json")[:data].each do |custom_field|
|
17
|
+
if block_given?
|
18
|
+
yield custom_field
|
19
|
+
end
|
20
|
+
custom_fields << custom_field
|
21
|
+
end
|
22
|
+
end
|
23
|
+
custom_fields
|
24
|
+
end
|
21
25
|
|
22
26
|
|
23
|
-
|
24
|
-
|
27
|
+
alias_method :custom_fields, :collect_custom_fields
|
28
|
+
end
|
25
29
|
end
|
@@ -1,43 +1,47 @@
|
|
1
1
|
module Samanage
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
class Api
|
3
|
+
# Get custom forms path
|
4
|
+
def get_custom_forms(path: PATHS[:custom_forms], options: {})
|
5
|
+
url = Samanage::UrlBuilder.new(path: path, options: options).url
|
6
|
+
self.execute(path: url)
|
7
|
+
end
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
9
|
+
# Get all custom forms
|
10
|
+
def collect_custom_forms(options: {})
|
11
|
+
custom_forms = Array.new
|
12
|
+
total_pages = self.get_custom_forms[:total_pages]
|
13
|
+
1.upto(total_pages) do |page|
|
14
|
+
puts "Collecting Custom Forms page: #{page}/#{total_pages}" if options[:verbose]
|
15
|
+
self.execute(http_method: 'get', path: "custom_forms.json?page=#{page}")[:data].each do |custom_form|
|
16
|
+
if block_given?
|
17
|
+
yield custom_form
|
18
|
+
end
|
19
|
+
custom_forms << custom_form
|
20
|
+
end
|
21
|
+
end
|
22
|
+
custom_forms
|
23
|
+
end
|
20
24
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
25
|
+
# Set forms by type and map fields
|
26
|
+
def organize_forms
|
27
|
+
custom_forms = self.collect_custom_forms
|
28
|
+
custom_forms.map{|form| form.delete_if{|k, v| v.nil?}}
|
29
|
+
custom_forms.map{|form| form['custom_form_fields'].map{|fields| fields.delete_if{|k, v| v == false}}}
|
30
|
+
custom_forms.map{|form| form['custom_form_fields'].map{|fields| fields['custom_field'].delete_if{|k, v| !v}}}
|
31
|
+
custom_forms.group_by{|k|
|
32
|
+
k['module']}.each_pair{|forms_name, forms|
|
33
|
+
forms.each{|form|
|
34
|
+
form['custom_form_fields'].group_by{|f| f['name'] }
|
35
|
+
}
|
36
|
+
}
|
37
|
+
end
|
34
38
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
39
|
+
# Get form for a specific object type
|
40
|
+
def form_for(object_type: nil)
|
41
|
+
if self.custom_forms == nil
|
42
|
+
self.custom_forms = self.organize_forms
|
43
|
+
end
|
44
|
+
self.custom_forms[object_type]
|
45
|
+
end
|
46
|
+
end
|
43
47
|
end
|
@@ -1,30 +1,33 @@
|
|
1
1
|
module Samanage
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
class Api
|
3
|
+
def get_departments(path: PATHS[:department], options: {})
|
4
|
+
url = Samanage::UrlBuilder.new(path: path, options: options).url
|
5
|
+
self.execute(path: url)
|
6
|
+
end
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
8
|
+
def collect_departments(options: {})
|
9
|
+
departments = Array.new
|
10
|
+
total_pages = self.get_departments[:total_pages]
|
11
|
+
1.upto(total_pages) do |page|
|
12
|
+
puts "Collecting Groups page: #{page}/#{total_pages}" if options[:verbose]
|
13
|
+
self.execute(http_method: 'get', path: "departments.json?page=#{page}")[:data].each do |department|
|
14
|
+
if block_given?
|
15
|
+
yield department
|
16
|
+
end
|
17
|
+
departments << department
|
18
|
+
end
|
19
|
+
end
|
20
|
+
departments
|
21
|
+
end
|
19
22
|
|
20
|
-
|
21
|
-
|
23
|
+
def create_department(payload: , options: {})
|
24
|
+
self.execute(path: PATHS[:department], http_method: 'post', payload: payload)
|
22
25
|
|
23
|
-
|
24
|
-
|
26
|
+
end
|
27
|
+
def delete_department(id: )
|
25
28
|
self.execute(path: "departments/#{id}.json", http_method: 'delete')
|
26
29
|
end
|
27
30
|
|
28
|
-
|
29
|
-
|
31
|
+
alias_method :departments, :collect_departments
|
32
|
+
end
|
30
33
|
end
|