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,26 +1,31 @@
1
1
  module Samanage
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
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
- # Samanage categories are not paginated
10
- # - to break into subcategories, add
11
- def collect_categories
12
- categories = Array.new
13
- categories += self.execute(http_method: 'get', path: "categories.json")[:data]
14
- end
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
- def create_category(payload: nil, options: {})
17
- self.execute(path: PATHS[:category], http_method: 'post', payload: payload)
18
- end
21
+ def create_category(payload: nil, options: {})
22
+ self.execute(path: PATHS[:category], http_method: 'post', payload: payload)
23
+ end
19
24
 
20
- # def find_category(name: )
21
- # self.categories
22
- # end
25
+ def delete_category(id: )
26
+ self.execute(path: "categories/#{id}", http_method: 'delete')
27
+ end
23
28
 
24
- alias_method :categories, :collect_categories
25
- end
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
- class Api
2
+ class Api
3
3
 
4
4
 
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
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
- # 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
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
- alias_method :comments, :get_comments
19
- end
18
+ alias_method :comments, :get_comments
19
+ end
20
20
  end
@@ -1,58 +1,62 @@
1
1
  module Samanage
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
- page = 1
13
- contracts = Array.new
14
- total_pages = self.get_contracts[:total_pages]
15
- 1.upto(total_pages) do |page|
16
- puts "Collecting contracts page: #{page}/#{total_pages}" if options[:verbose]
17
- contracts += self.execute(http_method: 'get', path: "contracts.json?page=#{page}")[:data]
18
- end
19
- contracts
20
- end
21
-
22
- # Create contract given json payload
23
- def create_contract(payload: , options: {})
24
- self.execute(path: PATHS[:contract], http_method: 'post', payload: payload)
25
- end
26
-
27
- # Find contract given id
28
- def find_contract(id: )
29
- path = "contracts/#{id}.json"
30
- self.execute(path: path)
31
- end
32
-
33
- # Check for contract using URL builder
34
- def check_contract(options: {})
35
- url = Samanage::UrlBuilder.new(path: PATHS[:contract], options: options).url
36
- self.execute(path: url)
37
- end
38
-
39
- # Update contract given id
40
- def update_contract(payload: , id: , options: {})
41
- path = "contracts/#{id}.json"
42
- self.execute(path: path, http_method: 'put', payload: payload)
43
- end
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
- end
49
-
50
- def delete_contract(id: )
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
- alias_method :contracts, :collect_contracts
57
- end
60
+ alias_method :contracts, :collect_contracts
61
+ end
58
62
  end
@@ -1,25 +1,29 @@
1
1
  module Samanage
2
- class Api
2
+ class Api
3
3
 
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
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
- # Gets all custom fields
11
- def collect_custom_fields(options: {})
12
- page = 1
13
- custom_fields = Array.new
14
- total_pages = self.get_custom_fields[:total_pages] ||= 2
15
- 1.upto(total_pages) do |page|
16
- puts "Collecting Custom Fields page: #{page}/#{total_pages}" if options[:verbose]
17
- custom_fields += self.execute(path: "custom_fields.json")[:data]
18
- end
19
- custom_fields
20
- end
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
- alias_method :custom_fields, :collect_custom_fields
24
- end
27
+ alias_method :custom_fields, :collect_custom_fields
28
+ end
25
29
  end
@@ -1,43 +1,47 @@
1
1
  module Samanage
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
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
- # Get all custom forms
10
- def collect_custom_forms(options: {})
11
- page = 1
12
- custom_forms = Array.new
13
- total_pages = self.get_custom_forms[:total_pages]
14
- 1.upto(total_pages) do |page|
15
- puts "Collecting Custom Forms page: #{page}/#{total_pages}" if options[:verbose]
16
- custom_forms += self.execute(http_method: 'get', path: "custom_forms.json?page=#{page}")[:data]
17
- end
18
- custom_forms
19
- end
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
- # Set forms by type and map fields
22
- def organize_forms
23
- custom_forms = self.collect_custom_forms
24
- custom_forms.map{|form| form.delete_if{|k, v| v.nil?}}
25
- custom_forms.map{|form| form['custom_form_fields'].map{|fields| fields.delete_if{|k, v| v == false}}}
26
- custom_forms.map{|form| form['custom_form_fields'].map{|fields| fields['custom_field'].delete_if{|k, v| !v}}}
27
- custom_forms.group_by{|k|
28
- k['module']}.each_pair{|forms_name, forms|
29
- forms.each{|form|
30
- form['custom_form_fields'].group_by{|f| f['name'] }
31
- }
32
- }
33
- end
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
- # Get form for a specific object type
36
- def form_for(object_type: nil)
37
- if self.custom_forms == nil
38
- self.custom_forms = self.organize_forms
39
- end
40
- self.custom_forms[object_type]
41
- end
42
- end
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
- 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
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
- def collect_departments(options: {})
9
- page = 1
10
- departments = Array.new
11
- total_pages = self.get_departments[:total_pages]
12
- 1.upto(total_pages) do |page|
13
- puts "Collecting Groups page: #{page}/#{total_pages}" if options[:verbose]
14
- departments += self.execute(http_method: 'get', path: "departments.json?page=#{page}")[:data]
15
- page += 1
16
- end
17
- departments
18
- end
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
- def create_department(payload: , options: {})
21
- self.execute(path: PATHS[:department], http_method: 'post', payload: payload)
23
+ def create_department(payload: , options: {})
24
+ self.execute(path: PATHS[:department], http_method: 'post', payload: payload)
22
25
 
23
- end
24
- def delete_department(id: )
26
+ end
27
+ def delete_department(id: )
25
28
  self.execute(path: "departments/#{id}.json", http_method: 'delete')
26
29
  end
27
30
 
28
- alias_method :departments, :collect_departments
29
- end
31
+ alias_method :departments, :collect_departments
32
+ end
30
33
  end