samanage 2.1.06 → 2.1.07

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 57907ba419f116d71c6213300a479cb66c295fb2
4
- data.tar.gz: 5596f9279a0a966be653698370b0a7656d6ff492
3
+ metadata.gz: ece5c3016e90c18aaf34302957f04396f3853650
4
+ data.tar.gz: 6f618e3d780ade5f0311f3ff76e611ab3ebc5dfc
5
5
  SHA512:
6
- metadata.gz: 037f7a2eb6dfcbea53e665458915205574141b560c31fc8808a89c705e2fa9d0daa7621946215b44d3912630fb9d16f2a5824a06f793ad8191b8ac96a912e78b
7
- data.tar.gz: 659da3f6311b6810d69a1107ca8ca545da3c82010decf93c727dd702d698cf1671802bad00b83395754720551c2c98cb4db7529f7d279a7c5859d322cb26488c
6
+ metadata.gz: 760118d00c46695d9ca41e8cbbd529225cc83b0e46b7c8c194d1b1f76612f99f4afec0dcae310bccd5f2376d12fea29cc43e3279a01b30349584c9793d054d8f
7
+ data.tar.gz: 4331fcb97fcdfd58986985c93a2c576d6d4e4fce06f36f5b1a9ff4474e86e704453c6166a07da09f4326cd1b028a470c3707b5e7a455e6798a920fe217e9cbcc
data/changelog.md CHANGED
@@ -1,3 +1,6 @@
1
+ ### 2.1.07
2
+ - Added problems
3
+
1
4
  ### 2.1.06
2
5
  - Added time track support
3
6
  ### 2.1.05
data/lib/samanage.rb CHANGED
@@ -15,6 +15,7 @@ require 'samanage/api/hardwares'
15
15
  require 'samanage/api/incidents'
16
16
  require 'samanage/api/mobiles'
17
17
  require 'samanage/api/other_assets'
18
+ require 'samanage/api/problems'
18
19
  require 'samanage/api/requester'
19
20
  require 'samanage/api/sites'
20
21
  require 'samanage/api/solutions'
data/lib/samanage/api.rb CHANGED
@@ -14,6 +14,7 @@ module Samanage
14
14
  department: 'departments.json',
15
15
  group: 'groups.json',
16
16
  hardware: 'hardwares.json',
17
+ problem: 'problems.json',
17
18
  incident: 'incidents.json',
18
19
  mobile: 'mobiles.json',
19
20
  other_asset: 'other_assets.json',
@@ -0,0 +1,63 @@
1
+ module Samanage
2
+ class Api
3
+
4
+ # Default get problem path
5
+ def get_problems(path: PATHS[:problem], options: {})
6
+ params = self.set_params(options: options)
7
+ path = 'problems.json?' + params
8
+ self.execute(path: path)
9
+ end
10
+
11
+
12
+ # Returns all problems.
13
+ # Options:
14
+ # - audit_archives: true
15
+ # - layout: 'long'
16
+ def collect_problems(options: {})
17
+ problems = Array.new
18
+ total_pages = self.get_problems(options: options)[:total_pages]
19
+ 1.upto(total_pages) do |page|
20
+ options[:page] = page
21
+ params = self.set_params(options: options)
22
+ puts "Collecting problems page: #{page}/#{total_pages}" if options[:verbose]
23
+ path = "problems.json?" + params
24
+ request = self.execute(http_method: 'get', path: path)
25
+ request[:data].each do |problem|
26
+ if block_given?
27
+ yield problem
28
+ end
29
+ problems << problem
30
+ end
31
+ end
32
+ problems
33
+ end
34
+
35
+
36
+ # Create an problem given json
37
+ def create_problem(payload: nil, options: {})
38
+ self.execute(path: PATHS[:problem], http_method: 'post', payload: payload)
39
+ end
40
+
41
+ # Find problem by ID
42
+ def find_problem(id: , options: {})
43
+ path = "problems/#{id}.json"
44
+ if options[:layout] == 'long'
45
+ path += '?layout=long'
46
+ end
47
+ self.execute(path: path)
48
+ end
49
+
50
+ # Update an problem given id and json
51
+ def update_problem(payload: , id: , options: {})
52
+ path = "problems/#{id}.json"
53
+ self.execute(path: path, http_method: 'put', payload: payload)
54
+ end
55
+
56
+ def delete_problem(id: )
57
+ self.execute(path: "problems/#{id}.json", http_method: 'delete')
58
+ end
59
+
60
+
61
+ alias_method :problems, :collect_problems
62
+ end
63
+ end
@@ -37,6 +37,8 @@ module Samanage
37
37
  url += 'solutions'
38
38
  when /contract/
39
39
  url += 'contracts'
40
+ when /problem/
41
+ url += 'problems'
40
42
  when /group/
41
43
  url += 'groups'
42
44
  end
@@ -1,3 +1,3 @@
1
1
  module Samanage
2
- VERSION = '2.1.06'
2
+ VERSION = '2.1.07'
3
3
  end
@@ -0,0 +1,100 @@
1
+ require 'samanage'
2
+ require 'faker'
3
+ describe Samanage::Api do
4
+ context 'problems' do
5
+ describe 'API Functions' do
6
+ before(:all) do
7
+ TOKEN ||= ENV['SAMANAGE_TEST_API_TOKEN']
8
+ @samanage = Samanage::Api.new(token: TOKEN)
9
+ @problems = @samanage.problems
10
+ @users = @samanage.get_users[:data]
11
+ end
12
+ it 'get_problems: it returns API call of problems' do
13
+ api_call = @samanage.get_problems
14
+ expect(api_call).to be_a(Hash)
15
+ expect(api_call[:total_count]).to be_an(Integer)
16
+ expect(api_call).to have_key(:response)
17
+ expect(api_call).to have_key(:code)
18
+ end
19
+ it 'collect_problems: collects array of problems' do
20
+ problem_count = @samanage.get_problems[:total_count]
21
+ @problems = @samanage.problems
22
+ expect(@problems).to be_an(Array)
23
+ expect(@problems.size).to eq(problem_count)
24
+ end
25
+ it 'create_problem(payload: json): creates a problem' do
26
+ users_email = @samanage.collect_users.sample['email']
27
+ problem_name = Faker::Book.title
28
+ json = {
29
+ problem: {
30
+ requester: {email: users_email},
31
+ name: problem_name,
32
+ state: 'Open',
33
+ priority: 'Low',
34
+ description: "Description"
35
+ }
36
+ }
37
+ problem_create = @samanage.create_problem(payload: json)
38
+
39
+ expect(problem_create[:data]['id']).to be_an(Integer)
40
+ expect(problem_create[:data]['name']).to eq(problem_name)
41
+ expect(problem_create[:code]).to eq(200).or(201)
42
+ end
43
+ it 'create_problem: fails if no name/title' do
44
+ users_email = @users.sample['email']
45
+ json = {
46
+ :problem => {
47
+ :requester => {:email => users_email},
48
+ :description => "Description"
49
+ }
50
+ }
51
+ expect{@samanage.create_problem(payload: json)}.to raise_error(Samanage::InvalidRequest)
52
+ end
53
+ it 'find_problem: returns a problem card by known id' do
54
+ sample_id = @problems.sample['id']
55
+ problem = @samanage.find_problem(id: sample_id)
56
+
57
+ expect(problem[:data]['id']).to eq(sample_id) # id should match found problem
58
+ expect(problem[:data]).to have_key('name')
59
+ expect(problem[:data]).to have_key('requester')
60
+ expect(problem[:data]).to have_key('id')
61
+ end
62
+ it 'find_problem: returns more keys with layout=long' do
63
+ sample_id = @problems.sample['id']
64
+ layout_regular_problem = @samanage.find_problem(id: sample_id)
65
+ layout_long_problem = @samanage.find_problem(id: sample_id, options: {layout: 'long'})
66
+
67
+ expect(layout_long_problem[:data]['id']).to eq(sample_id) # id should match found problem
68
+ expect(layout_long_problem[:data].keys.size).to be > (layout_regular_problem.keys.size)
69
+ expect(layout_long_problem[:data].keys - layout_regular_problem[:data].keys).to_not be([])
70
+ end
71
+ it 'find_problem: returns nothing for an invalid id' do
72
+ sample_id = (0..10).entries.sample
73
+ expect{@samanage.find_problem(id: sample_id)}.to raise_error(Samanage::NotFound) # id should match found problem
74
+ end
75
+ it 'update_problem: update_problem by id' do
76
+ sample_problem = @problems.reject{|i| ['Closed','Resolved'].include? i['state']}.sample
77
+ sample_id = sample_problem['id']
78
+ description = (0...500).map { ('a'..'z').to_a[rand(26)] }.join
79
+ problem_json = {
80
+ :problem => {
81
+ :description => description
82
+ }
83
+ }
84
+ problem_update = @samanage.update_problem(payload: problem_json, id: sample_id)
85
+ # expect(problem_update[:data]['description']).to eq(description) # problem bug #00044569
86
+ expect(problem_update[:code]).to eq(200).or(201)
87
+ end
88
+ it 'finds more data for option[:layout] = "long"' do
89
+ full_layout_problem_keys = @samanage.problems(options: {layout: 'long'}).first.keys
90
+ basic_problem_keys = @samanage.problems.sample.keys
91
+ expect(basic_problem_keys.size).to be < full_layout_problem_keys.size
92
+ end
93
+ it 'deletes a valid problem' do
94
+ sample_problem_id = @problems.sample['id']
95
+ problem_delete = @samanage.delete_problem(id: sample_problem_id)
96
+ expect(problem_delete[:code]).to eq(200).or(201)
97
+ end
98
+ end
99
+ end
100
+ end
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.1.06
4
+ version: 2.1.07
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-09-28 00:00:00.000000000 Z
11
+ date: 2018-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -66,6 +66,7 @@ files:
66
66
  - lib/samanage/api/incidents.rb
67
67
  - lib/samanage/api/mobiles.rb
68
68
  - lib/samanage/api/other_assets.rb
69
+ - lib/samanage/api/problems.rb
69
70
  - lib/samanage/api/requester.rb
70
71
  - lib/samanage/api/sites.rb
71
72
  - lib/samanage/api/solutions.rb
@@ -91,6 +92,7 @@ files:
91
92
  - spec/api/samanage_incident_spec.rb
92
93
  - spec/api/samanage_mobile_spec.rb
93
94
  - spec/api/samanage_other_asset_spec.rb
95
+ - spec/api/samanage_problem_spec.rb
94
96
  - spec/api/samanage_site_spec.rb
95
97
  - spec/api/samanage_solution_spec.rb
96
98
  - spec/api/samanage_time_tracks_spec.rb