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
data/lib/samanage/api/groups.rb
CHANGED
@@ -1,48 +1,52 @@
|
|
1
1
|
module Samanage
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
class Api
|
3
|
+
def get_groups(path: PATHS[:group], 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
|
-
|
8
|
+
def collect_groups(options: {})
|
9
|
+
groups = Array.new
|
10
|
+
total_pages = self.get_groups[: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: "groups.json?page=#{page}")[:data].each do |group|
|
14
|
+
if block_given?
|
15
|
+
yield group
|
16
|
+
end
|
17
|
+
groups << group
|
18
|
+
end
|
19
|
+
end
|
20
|
+
groups
|
21
|
+
end
|
18
22
|
|
19
|
-
|
20
|
-
|
21
|
-
|
23
|
+
def create_group(payload: , options: {})
|
24
|
+
self.execute(path: PATHS[:group], http_method: 'post', payload: payload)
|
25
|
+
end
|
22
26
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
def find_group_id_by_name(group: )
|
28
|
+
group_api = self.execute(path: "groups.json?name=#{group}")
|
29
|
+
if !group_api[:data].empty? && group == group_api[:data].first['name']
|
30
|
+
return group_api[:data].first['id']
|
31
|
+
end
|
32
|
+
end
|
29
33
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
+
def find_group(id: )
|
35
|
+
path = "groups/#{id}.json"
|
36
|
+
self.execute(path: path)
|
37
|
+
end
|
34
38
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
39
|
+
def add_member_to_group(email: , group_id: nil, group_name: nil)
|
40
|
+
group_id = group_id ||= self.find_group_id_by_name(group: group_name)
|
41
|
+
user_id = self.find_user_id_by_email(email: email)
|
42
|
+
member_path = "memberships.json?group_id=#{group_id}.json&user_ids=#{user_id}"
|
43
|
+
self.execute(path: member_path, http_method: 'post')
|
44
|
+
end
|
45
|
+
|
46
|
+
def delete_group(id: )
|
43
47
|
self.execute(path: "groups/#{id}.json", http_method: 'delete')
|
44
48
|
end
|
45
|
-
|
46
|
-
|
47
|
-
|
49
|
+
|
50
|
+
alias_method :groups, :collect_groups
|
51
|
+
end
|
48
52
|
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
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
2
|
+
class Api
|
3
|
+
|
4
|
+
# Get hardware default path
|
5
|
+
def get_hardwares(path: PATHS[:hardware], options: {})
|
6
|
+
url = Samanage::UrlBuilder.new(path: path, options: options).url
|
7
|
+
self.execute(path: url)
|
8
|
+
end
|
9
|
+
|
10
|
+
# Get all hardwares
|
11
|
+
def collect_hardwares(options: {})
|
12
|
+
hardwares = Array.new
|
13
|
+
total_pages = self.get_hardwares[:total_pages]
|
14
|
+
1.upto(total_pages) do |page|
|
15
|
+
puts "Collecting Hardwares page: #{page}/#{total_pages}" if options[:verbose]
|
16
|
+
self.execute(http_method: 'get', path: "hardwares.json?page=#{page}")[:data].each do |hardware|
|
17
|
+
if block_given?
|
18
|
+
yield hardware
|
19
|
+
end
|
20
|
+
hardwares << hardware
|
21
|
+
end
|
22
|
+
end
|
23
|
+
hardwares
|
24
|
+
end
|
25
|
+
|
26
|
+
# Create hardware given json payload
|
27
|
+
def create_hardware(payload: , options: {})
|
28
|
+
self.execute(path: PATHS[:hardware], http_method: 'post', payload: payload)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Find hardware given id
|
32
|
+
def find_hardware(id: )
|
33
|
+
path = "hardwares/#{id}.json"
|
34
|
+
self.execute(path: path)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Find hardware given a serial number
|
38
|
+
def find_hardwares_by_serial(serial_number: )
|
39
|
+
path = "hardwares.json?serial_number[]=#{serial_number}"
|
40
|
+
self.execute(path: path)
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
# Check for hardware using URL builder
|
45
|
+
def check_hardware(options: {})
|
46
|
+
url = Samanage::UrlBuilder.new(path: PATHS[:hardware], options: options).url
|
47
|
+
self.execute(path: url)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Update hardware given id
|
51
|
+
def update_hardware(payload: , id: , options: {})
|
52
|
+
path = "hardwares/#{id}.json"
|
53
|
+
self.execute(path: path, http_method: 'put', payload: payload)
|
54
|
+
end
|
55
|
+
|
56
|
+
def delete_hardware(id: )
|
53
57
|
self.execute(path: "hardwares/#{id}.json", http_method: 'delete')
|
54
58
|
end
|
55
59
|
|
56
|
-
|
57
|
-
|
60
|
+
alias_method :hardwares, :collect_hardwares
|
61
|
+
end
|
58
62
|
end
|
@@ -1,64 +1,73 @@
|
|
1
1
|
module Samanage
|
2
|
-
|
2
|
+
class Api
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
# Default get incident path
|
5
|
+
def get_incidents(path: PATHS[:incident], options: {})
|
6
|
+
url = Samanage::UrlBuilder.new(path: path, options: options).url
|
7
|
+
self.execute(path: url)
|
8
|
+
end
|
9
9
|
|
10
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
|
-
|
11
|
+
# Returns all incidents.
|
12
|
+
# Options:
|
13
|
+
# - audit_archives: true
|
14
|
+
# - layout: 'long'
|
15
|
+
def collect_incidents(options: {})
|
16
|
+
incidents = Array.new
|
17
|
+
total_pages = self.get_incidents[:total_pages]
|
18
|
+
puts "Pulling Incidents with Audit Archives (this may take a while)" if options[:audit_archives] && options[:verbose]
|
19
|
+
1.upto(total_pages) do |page|
|
20
|
+
puts "Collecting Incidents page: #{page}/#{total_pages}" if options[:verbose]
|
21
|
+
if options[:audit_archives]
|
22
|
+
archives_params = 'layout=long&audit_archive=true'
|
23
|
+
paginated_incidents = self.execute(path: "incidents.json?page=#{page}")[:data]
|
24
|
+
paginated_incidents.map do |incident|
|
25
|
+
archive_uri = "incidents/#{incident['id']}.json?#{archives_params}"
|
26
|
+
incident_with_archive = self.execute(path: archive_uri)[:data]
|
27
|
+
if block_given?
|
28
|
+
yield incident_with_archive
|
29
|
+
end
|
30
|
+
incidents.push(incident_with_archive)
|
31
|
+
end
|
32
|
+
else
|
33
|
+
layout = options[:layout] == 'long' ? '&layout=long' : nil
|
34
|
+
self.execute(http_method: 'get', path: "incidents.json?page=#{page}#{layout}")[:data].each do |incident|
|
35
|
+
if block_given?
|
36
|
+
yield incident
|
37
|
+
end
|
38
|
+
incidents.push(incident)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
incidents
|
43
|
+
end
|
35
44
|
|
36
45
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
46
|
+
# Create an incident given json
|
47
|
+
def create_incident(payload: nil, options: {})
|
48
|
+
self.execute(path: PATHS[:incident], http_method: 'post', payload: payload)
|
49
|
+
end
|
41
50
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
51
|
+
# Find incident by ID
|
52
|
+
def find_incident(id: , options: {})
|
53
|
+
path = "incidents/#{id}.json"
|
54
|
+
if options[:layout] == 'long'
|
55
|
+
path += '?layout=long'
|
56
|
+
end
|
57
|
+
self.execute(path: path)
|
58
|
+
end
|
50
59
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
60
|
+
# Update an incident given id and json
|
61
|
+
def update_incident(payload: , id: , options: {})
|
62
|
+
path = "incidents/#{id}.json"
|
63
|
+
self.execute(path: path, http_method: 'put', payload: payload)
|
64
|
+
end
|
56
65
|
|
57
|
-
|
66
|
+
def delete_incident(id: )
|
58
67
|
self.execute(path: "incidents/#{id}.json", http_method: 'delete')
|
59
68
|
end
|
60
69
|
|
61
70
|
|
62
|
-
|
63
|
-
|
64
|
-
end
|
71
|
+
alias_method :incidents, :collect_incidents
|
72
|
+
end
|
73
|
+
end
|
data/lib/samanage/api/mobiles.rb
CHANGED
@@ -1,52 +1,56 @@
|
|
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
|
-
|
44
|
-
|
45
|
-
|
2
|
+
class Api
|
3
|
+
|
4
|
+
# Get mobile default path
|
5
|
+
def get_mobiles(path: PATHS[:mobile], options: {})
|
6
|
+
url = Samanage::UrlBuilder.new(path: path, options: options).url
|
7
|
+
self.execute(path: url)
|
8
|
+
end
|
9
|
+
|
10
|
+
# Get all mobiles
|
11
|
+
def collect_mobiles(options: {})
|
12
|
+
mobiles = Array.new
|
13
|
+
total_pages = self.get_mobiles[:total_pages]
|
14
|
+
1.upto(total_pages) do |page|
|
15
|
+
puts "Collecting Mobiles page: #{page}/#{total_pages}" if options[:verbose]
|
16
|
+
self.execute(http_method: 'get', path: "mobiles.json?page=#{page}")[:data].each do |mobile|
|
17
|
+
if block_given?
|
18
|
+
yield mobiles
|
19
|
+
end
|
20
|
+
mobiles << mobile
|
21
|
+
end
|
22
|
+
end
|
23
|
+
mobiles
|
24
|
+
end
|
25
|
+
|
26
|
+
# Create mobile given json payload
|
27
|
+
def create_mobile(payload: nil, options: {})
|
28
|
+
self.execute(path: PATHS[:mobile], http_method: 'post', payload: payload)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Find mobile given id
|
32
|
+
def find_mobile(id: nil)
|
33
|
+
path = "mobiles/#{id}.json"
|
34
|
+
self.execute(path: path)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Check for mobile using URL builder
|
38
|
+
def check_mobile(options: {})
|
39
|
+
url = Samanage::UrlBuilder.new(path: PATHS[:mobile], options: options).url
|
40
|
+
self.execute(path: url)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Update mobile given id
|
44
|
+
def update_mobile(payload: , id: , options: {})
|
45
|
+
path = "mobiles/#{id}.json"
|
46
|
+
self.execute(path: path, http_method: 'put', payload: payload)
|
47
|
+
end
|
48
|
+
|
49
|
+
def delete_mobile(id: )
|
46
50
|
self.execute(path: "mobiles/#{id}.json", http_method: 'delete')
|
47
51
|
end
|
48
52
|
|
49
53
|
|
50
|
-
|
51
|
-
|
54
|
+
alias_method :mobiles, :collect_mobiles
|
55
|
+
end
|
52
56
|
end
|
@@ -1,49 +1,53 @@
|
|
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
|
-
|
2
|
+
class Api
|
3
|
+
|
4
|
+
# Default get other_assets path
|
5
|
+
def get_other_assets(path: PATHS[:other_asset], options: {})
|
6
|
+
url = Samanage::UrlBuilder.new(path: path, options: options).url
|
7
|
+
self.execute(path: url)
|
8
|
+
end
|
9
|
+
|
10
|
+
# Returns all other assets
|
11
|
+
def collect_other_assets(options: {})
|
12
|
+
other_assets = Array.new
|
13
|
+
total_pages = self.get_other_assets[:total_pages]
|
14
|
+
other_assets = []
|
15
|
+
1.upto(total_pages) do |page|
|
16
|
+
puts "Collecting Other Assets page: #{page}/#{total_pages}" if options[:verbose]
|
17
|
+
self.execute(http_method: 'get', path: "other_assets.json?page=#{page}")[:data].each do |other_asset|
|
18
|
+
if block_given?
|
19
|
+
yield other_asset
|
20
|
+
end
|
21
|
+
other_assets << other_asset
|
22
|
+
end
|
23
|
+
end
|
24
|
+
other_assets
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
# Create an other_asset given json
|
29
|
+
def create_other_asset(payload: , options: {})
|
30
|
+
self.execute(path: PATHS[:other_asset], http_method: 'post', payload: payload)
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
# Find other_asset by id
|
35
|
+
def find_other_asset(id: )
|
36
|
+
path = "other_assets/#{id}.json"
|
37
|
+
self.execute(path: path)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Update other_asset given json and id
|
41
|
+
def update_other_asset(payload: , id: , options: {})
|
42
|
+
path = "other_assets/#{id}.json"
|
43
|
+
self.execute(path: path, http_method: 'put', payload: payload)
|
44
|
+
end
|
45
|
+
|
46
|
+
def delete_other_asset(id: )
|
43
47
|
self.execute(path: "other_assets/#{id}.json", http_method: 'delete')
|
44
48
|
end
|
45
49
|
|
46
50
|
|
47
|
-
|
48
|
-
|
51
|
+
alias_method :other_assets, :collect_other_assets
|
52
|
+
end
|
49
53
|
end
|