samanage 1.9.33 → 2.0.03

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -2
  3. data/Gemfile.lock +24 -26
  4. data/changelog.md +13 -0
  5. data/lib/samanage.rb +2 -1
  6. data/lib/samanage/api.rb +140 -144
  7. data/lib/samanage/api/attachments.rb +21 -0
  8. data/lib/samanage/api/category.rb +24 -19
  9. data/lib/samanage/api/changes.rb +59 -0
  10. data/lib/samanage/api/comments.rb +13 -13
  11. data/lib/samanage/api/contracts.rb +51 -47
  12. data/lib/samanage/api/custom_fields.rb +23 -19
  13. data/lib/samanage/api/custom_forms.rb +42 -38
  14. data/lib/samanage/api/departments.rb +25 -22
  15. data/lib/samanage/api/groups.rb +43 -39
  16. data/lib/samanage/api/hardwares.rb +57 -53
  17. data/lib/samanage/api/incidents.rb +60 -51
  18. data/lib/samanage/api/mobiles.rb +50 -46
  19. data/lib/samanage/api/other_assets.rb +47 -43
  20. data/lib/samanage/api/requester.rb +7 -7
  21. data/lib/samanage/api/sites.rb +27 -23
  22. data/lib/samanage/api/users.rb +58 -54
  23. data/lib/samanage/api/utils.rb +0 -19
  24. data/lib/samanage/error.rb +20 -20
  25. data/lib/samanage/url_builder.rb +53 -53
  26. data/lib/samanage/version.rb +2 -2
  27. data/samanage.gemspec +2 -2
  28. data/sample_file.txt +1 -0
  29. data/spec/api/samanage_attachment_spec.rb +14 -0
  30. data/spec/api/samanage_category_spec.rb +24 -24
  31. data/spec/api/samanage_change_spec.rb +98 -0
  32. data/spec/api/samanage_comments_spec.rb +25 -32
  33. data/spec/api/samanage_contract_spec.rb +62 -68
  34. data/spec/api/samanage_custom_field_spec.rb +12 -12
  35. data/spec/api/samanage_custom_form_spec.rb +24 -24
  36. data/spec/api/samanage_department_spec.rb +35 -36
  37. data/spec/api/samanage_group_spec.rb +59 -59
  38. data/spec/api/samanage_hardware_spec.rb +80 -85
  39. data/spec/api/samanage_incident_spec.rb +99 -103
  40. data/spec/api/samanage_mobile_spec.rb +70 -74
  41. data/spec/api/samanage_other_asset_spec.rb +72 -76
  42. data/spec/api/samanage_site_spec.rb +45 -45
  43. data/spec/api/samanage_user_spec.rb +117 -100
  44. data/spec/api/samanage_util_spec.rb +4 -9
  45. data/spec/samanage_api_spec.rb +48 -48
  46. data/spec/samanage_category_spec.rb +21 -28
  47. data/spec/samanage_url_builder_spec.rb +15 -15
  48. metadata +15 -11
  49. data/lib/data/gd-class2-root.crt +0 -24
@@ -1,48 +1,52 @@
1
1
  module Samanage
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
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
- def collect_groups(options: {})
9
- page = 1
10
- groups = Array.new
11
- total_pages = self.get_groups[:total_pages]
12
- 1.upto(total_pages) do |page|
13
- puts "Collecting Groups page: #{page}/#{total_pages}" if options[:verbose]
14
- groups += self.execute(http_method: 'get', path: "groups.json?page=#{page}")[:data]
15
- end
16
- groups
17
- end
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
- def create_group(payload: , options: {})
20
- self.execute(path: PATHS[:group], http_method: 'post', payload: payload)
21
- end
23
+ def create_group(payload: , options: {})
24
+ self.execute(path: PATHS[:group], http_method: 'post', payload: payload)
25
+ end
22
26
 
23
- def find_group_id_by_name(group: )
24
- group_api = self.execute(path: "groups.json?name=#{group}")
25
- if !group_api[:data].empty? && group == group_api[:data].first['name']
26
- return group_api[:data].first['id']
27
- end
28
- end
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
- def find_group(id: )
31
- path = "groups/#{id}.json"
32
- self.execute(path: path)
33
- end
34
+ def find_group(id: )
35
+ path = "groups/#{id}.json"
36
+ self.execute(path: path)
37
+ end
34
38
 
35
- def add_member_to_group(email: , group_id: nil, group_name: nil)
36
- group_id = group_id ||= self.find_group_id_by_name(group: group_name)
37
- user_id = self.find_user_id_by_email(email: email)
38
- member_path = "memberships.json?group_id=#{group_id}.json&user_ids=#{user_id}"
39
- self.execute(path: member_path, http_method: 'post')
40
- end
41
-
42
- def delete_group(id: )
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
- alias_method :groups, :collect_groups
47
- end
49
+
50
+ alias_method :groups, :collect_groups
51
+ end
48
52
  end
@@ -1,58 +1,62 @@
1
1
  module Samanage
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
- page = 1
13
- hardwares = Array.new
14
- total_pages = self.get_hardwares[:total_pages]
15
- 1.upto(total_pages) do |page|
16
- puts "Collecting Hardwares page: #{page}/#{total_pages}" if options[:verbose]
17
- hardwares += self.execute(http_method: 'get', path: "hardwares.json?page=#{page}")[:data]
18
- end
19
- hardwares
20
- end
21
-
22
- # Create hardware given json payload
23
- def create_hardware(payload: , options: {})
24
- self.execute(path: PATHS[:hardware], http_method: 'post', payload: payload)
25
- end
26
-
27
- # Find hardware given id
28
- def find_hardware(id: )
29
- path = "hardwares/#{id}.json"
30
- self.execute(path: path)
31
- end
32
-
33
- # Find hardware given a serial number
34
- def find_hardwares_by_serial(serial_number: )
35
- path = "hardwares.json?serial_number[]=#{serial_number}"
36
- self.execute(path: path)
37
- end
38
-
39
-
40
- # Check for hardware using URL builder
41
- def check_hardware(options: {})
42
- url = Samanage::UrlBuilder.new(path: PATHS[:hardware], options: options).url
43
- self.execute(path: url)
44
- end
45
-
46
- # Update hardware given id
47
- def update_hardware(payload: , id: , options: {})
48
- path = "hardwares/#{id}.json"
49
- self.execute(path: path, http_method: 'put', payload: payload)
50
- end
51
-
52
- def delete_hardware(id: )
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
- alias_method :hardwares, :collect_hardwares
57
- end
60
+ alias_method :hardwares, :collect_hardwares
61
+ end
58
62
  end
@@ -1,64 +1,73 @@
1
1
  module Samanage
2
- class Api
2
+ class Api
3
3
 
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
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
- # 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 = 'layout=long&audit_archive=true'
23
- paginated_incidents = self.execute(path: "incidents.json?page=#{page}")[:data]
24
- paginated_incidents.map do |incident|
25
- archive_path = "incidents/#{incident['id']}.json?#{archives}"
26
- incidents << self.execute(path: archive_path)[:data]
27
- end
28
- else
29
- layout = options[:layout] == 'long' ? '&layout=long' : nil
30
- incidents += self.execute(http_method: 'get', path: "incidents.json?page=#{page}#{layout}")[:data]
31
- end
32
- end
33
- incidents
34
- end
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
- # Create an incident given json
38
- def create_incident(payload: nil, options: {})
39
- self.execute(path: PATHS[:incident], http_method: 'post', payload: payload)
40
- end
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
- # Find incident by ID
43
- def find_incident(id: , options: {})
44
- path = "incidents/#{id}.json"
45
- if options[:layout] == 'long'
46
- path += '?layout=long'
47
- end
48
- self.execute(path: path)
49
- end
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
- # Update an incident given id and json
52
- def update_incident(payload: , id: , options: {})
53
- path = "incidents/#{id}.json"
54
- self.execute(path: path, http_method: 'put', payload: payload)
55
- end
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
- def delete_incident(id: )
66
+ def delete_incident(id: )
58
67
  self.execute(path: "incidents/#{id}.json", http_method: 'delete')
59
68
  end
60
69
 
61
70
 
62
- alias_method :incidents, :collect_incidents
63
- end
64
- end
71
+ alias_method :incidents, :collect_incidents
72
+ end
73
+ end
@@ -1,52 +1,56 @@
1
1
  module Samanage
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
- page = 1
13
- mobiles = Array.new
14
- total_pages = self.get_mobiles[:total_pages]
15
- 1.upto(total_pages) do |page|
16
- puts "Collecting Mobiles page: #{page}/#{total_pages}" if options[:verbose]
17
- mobiles += self.execute(http_method: 'get', path: "mobiles.json?page=#{page}")[:data]
18
- end
19
- mobiles
20
- end
21
-
22
- # Create mobile given json payload
23
- def create_mobile(payload: nil, options: {})
24
- self.execute(path: PATHS[:mobile], http_method: 'post', payload: payload)
25
- end
26
-
27
- # Find mobile given id
28
- def find_mobile(id: nil)
29
- path = "mobiles/#{id}.json"
30
- self.execute(path: path)
31
- end
32
-
33
- # Check for mobile using URL builder
34
- def check_mobile(options: {})
35
- url = Samanage::UrlBuilder.new(path: PATHS[:mobile], options: options).url
36
- self.execute(path: url)
37
- end
38
-
39
- # Update mobile given id
40
- def update_mobile(payload: , id: , options: {})
41
- path = "mobiles/#{id}.json"
42
- self.execute(path: path, http_method: 'put', payload: payload)
43
- end
44
-
45
- def delete_mobile(id: )
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
- alias_method :mobiles, :collect_mobiles
51
- end
54
+ alias_method :mobiles, :collect_mobiles
55
+ end
52
56
  end
@@ -1,49 +1,53 @@
1
1
  module Samanage
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
- page = 1
13
- other_assets = Array.new
14
- total_pages = self.get_other_assets[:total_pages]
15
- other_assets = []
16
- 1.upto(total_pages) do |page|
17
- puts "Collecting Other Assets page: #{page}/#{total_pages}" if options[:verbose]
18
- other_assets += self.execute(http_method: 'get', path: "other_assets.json?page=#{page}")[:data]
19
- end
20
- other_assets.uniq
21
- end
22
-
23
-
24
- # Create an other_asset given json
25
- def create_other_asset(payload: , options: {})
26
- self.execute(path: PATHS[:other_asset], http_method: 'post', payload: payload)
27
- end
28
-
29
-
30
- # Find other_asset by id
31
- def find_other_asset(id: )
32
- path = "other_assets/#{id}.json"
33
- self.execute(path: path)
34
- end
35
-
36
- # Update other_asset given json and id
37
- def update_other_asset(payload: , id: , options: {})
38
- path = "other_assets/#{id}.json"
39
- self.execute(path: path, http_method: 'put', payload: payload)
40
- end
41
-
42
- def delete_other_asset(id: )
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
- alias_method :other_assets, :collect_other_assets
48
- end
51
+ alias_method :other_assets, :collect_other_assets
52
+ end
49
53
  end