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 +4 -4
- data/changelog.md +3 -0
- data/lib/samanage.rb +1 -0
- data/lib/samanage/api.rb +1 -0
- data/lib/samanage/api/problems.rb +63 -0
- data/lib/samanage/url_builder.rb +2 -0
- data/lib/samanage/version.rb +1 -1
- data/spec/api/samanage_problem_spec.rb +100 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ece5c3016e90c18aaf34302957f04396f3853650
|
4
|
+
data.tar.gz: 6f618e3d780ade5f0311f3ff76e611ab3ebc5dfc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 760118d00c46695d9ca41e8cbbd529225cc83b0e46b7c8c194d1b1f76612f99f4afec0dcae310bccd5f2376d12fea29cc43e3279a01b30349584c9793d054d8f
|
7
|
+
data.tar.gz: 4331fcb97fcdfd58986985c93a2c576d6d4e4fce06f36f5b1a9ff4474e86e704453c6166a07da09f4326cd1b028a470c3707b5e7a455e6798a920fe217e9cbcc
|
data/changelog.md
CHANGED
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
@@ -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
|
data/lib/samanage/url_builder.rb
CHANGED
data/lib/samanage/version.rb
CHANGED
@@ -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.
|
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-
|
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
|