samanage 1.8.91 → 1.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/changelog.md +6 -0
- data/lib/samanage.rb +1 -0
- data/lib/samanage/api.rb +2 -1
- data/lib/samanage/api/contracts.rb +54 -0
- data/lib/samanage/api/utils.rb +0 -1
- data/lib/samanage/url_builder.rb +2 -0
- data/lib/samanage/version.rb +1 -1
- data/spec/api/samanage_comments_spec.rb +6 -8
- data/spec/api/samanage_contract_spec.rb +89 -0
- data/spec/api/samanage_group_spec.rb +1 -1
- data/spec/api/samanage_hardware_spec.rb +1 -1
- data/spec/api/samanage_incident_spec.rb +2 -1
- data/spec/api/samanage_other_asset_spec.rb +1 -1
- data/spec/api/samanage_util_spec.rb +1 -1
- 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: f8c02d4669579f854f505bf78ab70ccaeb5d3cc3
|
4
|
+
data.tar.gz: 48c449e4261c287a933a8ae556362f66e258ff4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6845ac50e4c1718f5ff36899b0e8304c839db31c2eb4fa353cb396455cccebb09b4cb55aa182537b6348235ace14f135fbe86c147ec12d4339d56194656f432f
|
7
|
+
data.tar.gz: 7f0694ed93f51c163a60a6efafdd54b9937ce8f880094ddc05280f7b5a50c421a23149a6f30596c4c51315ed24b5fa3b65c82906c7177c1521602dbf915b4e5c
|
data/changelog.md
CHANGED
data/lib/samanage.rb
CHANGED
data/lib/samanage/api.rb
CHANGED
@@ -4,6 +4,7 @@ module Samanage
|
|
4
4
|
MAX_RETRIES = 3
|
5
5
|
PATHS = {
|
6
6
|
category: 'categories.json',
|
7
|
+
contract: 'contracts.json',
|
7
8
|
custom_fields: 'custom_fields.json',
|
8
9
|
custom_forms: 'custom_forms.json',
|
9
10
|
department: 'departments.json',
|
@@ -88,7 +89,7 @@ module Samanage
|
|
88
89
|
when 'put'
|
89
90
|
api_call = self.class.put(full_path, query: payload, headers: headers)
|
90
91
|
when 'delete'
|
91
|
-
api_call = self.class.
|
92
|
+
api_call = self.class.delete(full_path, query: payload, headers: headers)
|
92
93
|
else
|
93
94
|
raise Samanage::Error.new(response: {response: 'Unknown HTTP method'})
|
94
95
|
end
|
@@ -0,0 +1,54 @@
|
|
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: nil, 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: nil)
|
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: nil, id: nil, options: {})
|
41
|
+
path = "contracts/#{id}.json"
|
42
|
+
self.execute(path: path, http_method: 'put', payload: payload)
|
43
|
+
end
|
44
|
+
|
45
|
+
def add_item_to_contract(id: nil, payload: nil)
|
46
|
+
path = "contracts/#{id}/items.json"
|
47
|
+
self.execute(path: path, http_method: 'post', payload: payload)
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
alias_method :contracts, :collect_contracts
|
53
|
+
end
|
54
|
+
end
|
data/lib/samanage/api/utils.rb
CHANGED
data/lib/samanage/url_builder.rb
CHANGED
data/lib/samanage/version.rb
CHANGED
@@ -4,16 +4,17 @@ describe Samanage::Api do
|
|
4
4
|
before(:all) do
|
5
5
|
TOKEN ||= ENV['SAMANAGE_TEST_API_TOKEN']
|
6
6
|
@samanage = Samanage::Api.new(token: TOKEN)
|
7
|
+
@incidents = @samanage.get_incidents[:data]
|
7
8
|
end
|
8
9
|
describe 'API Functions' do
|
9
10
|
it 'gets comments' do
|
10
|
-
incident_id = @
|
11
|
+
incident_id = @incidents.sample.dig('id')
|
11
12
|
comments = @samanage.get_comments(incident_id: incident_id)
|
12
13
|
expect(comments).to be_a(Hash)
|
13
14
|
end
|
14
15
|
|
15
16
|
it 'creates a comment' do
|
16
|
-
incident_id = @
|
17
|
+
incident_id = @incidents.sample.dig('id')
|
17
18
|
rand_text = ('a'..'z').to_a.shuffle[0,8].join
|
18
19
|
comment = {
|
19
20
|
comment: {
|
@@ -26,13 +27,10 @@ describe Samanage::Api do
|
|
26
27
|
end
|
27
28
|
|
28
29
|
it 'collects all comments' do
|
29
|
-
|
30
|
-
|
31
|
-
# comments_api = @samanage.get_comments(incident_id: incident_id)
|
32
|
-
# comments_found = @samanage.collect_comments(incident_id: incident_id)
|
33
|
-
|
30
|
+
incident_id = @incidents.sample.dig('id')
|
31
|
+
comments = @samanage.collect_comments(incident_id: incident_id)
|
34
32
|
# Total count bug
|
35
|
-
# expect(
|
33
|
+
# expect(comments).to be(Array)
|
36
34
|
end
|
37
35
|
end
|
38
36
|
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'samanage'
|
2
|
+
|
3
|
+
describe Samanage::Api do
|
4
|
+
context 'Contract' do
|
5
|
+
describe 'API Fucntions' do
|
6
|
+
before(:all) do
|
7
|
+
TOKEN ||= ENV['SAMANAGE_TEST_API_TOKEN']
|
8
|
+
@samanage = Samanage::Api.new(token: TOKEN)
|
9
|
+
@contracts = @samanage.contracts
|
10
|
+
end
|
11
|
+
it 'get_contracts: it returns API call of contracts' do
|
12
|
+
api_call = @samanage.get_contracts
|
13
|
+
expect(api_call).to be_a(Hash)
|
14
|
+
expect(api_call[:total_count]).to be_an(Integer)
|
15
|
+
expect(api_call).to have_key(:response)
|
16
|
+
expect(api_call).to have_key(:code)
|
17
|
+
end
|
18
|
+
it 'collect_contracts: collects array of contracts' do
|
19
|
+
contract_count = @samanage.get_contracts[:total_count]
|
20
|
+
expect(@contracts).to be_an(Array)
|
21
|
+
expect(@contracts.size).to eq(contract_count)
|
22
|
+
end
|
23
|
+
it 'create_contract(payload: json): creates a contract' do
|
24
|
+
manufacturer_name = "samanage-ruby-#{(rand*10**10).ceil}"
|
25
|
+
random_name = (0...50).map { ('a'..'z').to_a[rand(26)] }.join
|
26
|
+
json = {
|
27
|
+
contract: {
|
28
|
+
type: 'SoftwareLicense',
|
29
|
+
manufacturer_name: 'Adobe',
|
30
|
+
status: 'Active',
|
31
|
+
name: random_name,
|
32
|
+
}
|
33
|
+
}
|
34
|
+
contract_create = @samanage.create_contract(payload: json)
|
35
|
+
|
36
|
+
expect(contract_create[:data]['id']).to be_an(Integer)
|
37
|
+
expect(contract_create[:data]['name']).to eq(random_name)
|
38
|
+
end
|
39
|
+
it 'create_contract: fails if no status' do
|
40
|
+
contract_name = "samanage-ruby-#{(rand*10**10).ceil}"
|
41
|
+
json = {
|
42
|
+
:contract => {
|
43
|
+
model: 'test',
|
44
|
+
manufacturer_name: contract_name,
|
45
|
+
}
|
46
|
+
}
|
47
|
+
expect{@samanage.create_contract(payload: json)}.to raise_error(Samanage::InvalidRequest)
|
48
|
+
end
|
49
|
+
it 'find_contract: returns a contract card by known id' do
|
50
|
+
sample_id = @contracts.sample['id']
|
51
|
+
contract = @samanage.find_contract(id: sample_id)
|
52
|
+
|
53
|
+
expect(contract[:data]['id']).to eq(sample_id) # id should match found contract
|
54
|
+
expect(contract[:data]).to have_key('manufacturer_name')
|
55
|
+
expect(contract[:data]).to have_key('name')
|
56
|
+
expect(contract[:data]).to have_key('id')
|
57
|
+
end
|
58
|
+
it 'find_contract: returns nothing for an invalid id' do
|
59
|
+
sample_id = (0..10).entries.sample
|
60
|
+
expect{@samanage.find_contract(id: sample_id)}.to raise_error(Samanage::NotFound) # id should match found contract
|
61
|
+
end
|
62
|
+
it 'update_contract: update_contract by id' do
|
63
|
+
sample_id = @contracts.sample['id']
|
64
|
+
new_name = (0...50).map {('a'..'z').to_a[rand(26)] }.join
|
65
|
+
json = {
|
66
|
+
contract: {
|
67
|
+
manufacturer_name: new_name
|
68
|
+
}
|
69
|
+
}
|
70
|
+
contract_update = @samanage.update_contract(payload: json, id: sample_id)
|
71
|
+
expect(contract_update[:data]["manufacturer_name"]).to eq(new_name)
|
72
|
+
expect(contract_update[:code]).to eq(200).or(201)
|
73
|
+
end
|
74
|
+
it 'adds an item to a contract by id' do
|
75
|
+
sample_id = @contracts.sample['id']
|
76
|
+
item = {
|
77
|
+
item: {
|
78
|
+
name: "name",
|
79
|
+
version:" 123",
|
80
|
+
qty: "2",
|
81
|
+
tag: "tag",
|
82
|
+
}
|
83
|
+
}
|
84
|
+
add_item = @samanage.add_item_to_contract(id: sample_id, payload: item)
|
85
|
+
expect(add_item[:code]).to eq(200).or(201)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -5,7 +5,7 @@ describe Samanage::Api do
|
|
5
5
|
TOKEN ||= ENV['SAMANAGE_TEST_API_TOKEN']
|
6
6
|
@samanage = Samanage::Api.new(token: TOKEN)
|
7
7
|
@groups = @samanage.groups
|
8
|
-
@users = @samanage.
|
8
|
+
@users = @samanage.get_users[:data]
|
9
9
|
end
|
10
10
|
it 'get_users: it returns API call of users' do
|
11
11
|
api_call = @samanage.get_groups
|
@@ -5,7 +5,7 @@ describe Samanage::Api do
|
|
5
5
|
before(:all) do
|
6
6
|
TOKEN ||= ENV['SAMANAGE_TEST_API_TOKEN']
|
7
7
|
@samanage = Samanage::Api.new(token: TOKEN)
|
8
|
-
@hardwares = @samanage.
|
8
|
+
@hardwares = @samanage.get_hardwares[:data]
|
9
9
|
end
|
10
10
|
it 'get_hardwares: it returns API call of hardwares' do
|
11
11
|
api_call = @samanage.get_hardwares
|
@@ -81,7 +81,8 @@ describe Samanage::Api do
|
|
81
81
|
end
|
82
82
|
it 'finds more audit archives for option[:audit_archives] = true' do
|
83
83
|
incident_keys = @incidents_with_archives.sample.keys
|
84
|
-
expect(incident_keys).to include
|
84
|
+
expect(incident_keys).to include
|
85
|
+
('audits')
|
85
86
|
end
|
86
87
|
it 'finds audit archives for options: {audit_archives: true, layout: "long"}' do
|
87
88
|
full_incident_keys = @incidents_with_archives.sample.keys
|
@@ -6,7 +6,7 @@ describe Samanage::Api do
|
|
6
6
|
before(:all) do
|
7
7
|
TOKEN ||= ENV['SAMANAGE_TEST_API_TOKEN']
|
8
8
|
@samanage = Samanage::Api.new(token: TOKEN)
|
9
|
-
@other_assets = @samanage.
|
9
|
+
@other_assets = @samanage.get_other_assets[:data]
|
10
10
|
end
|
11
11
|
it 'get_other_assets: it returns API call of other_assets' do
|
12
12
|
api_call = @samanage.get_other_assets
|
@@ -5,7 +5,7 @@ describe Samanage::Api do
|
|
5
5
|
before(:each) do
|
6
6
|
TOKEN ||= ENV['SAMANAGE_TEST_API_TOKEN']
|
7
7
|
@samanage = Samanage::Api.new(token: TOKEN)
|
8
|
-
@users = @samanage.
|
8
|
+
@users = @samanage.get_users[:data]
|
9
9
|
end
|
10
10
|
it 'sends an activation email' do
|
11
11
|
valid_email = @users.sample['email']
|
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: 1.
|
4
|
+
version: 1.9.1
|
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-01-
|
11
|
+
date: 2018-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -56,6 +56,7 @@ files:
|
|
56
56
|
- lib/samanage/api.rb
|
57
57
|
- lib/samanage/api/category.rb
|
58
58
|
- lib/samanage/api/comments.rb
|
59
|
+
- lib/samanage/api/contracts.rb
|
59
60
|
- lib/samanage/api/custom_fields.rb
|
60
61
|
- lib/samanage/api/custom_forms.rb
|
61
62
|
- lib/samanage/api/departments.rb
|
@@ -75,6 +76,7 @@ files:
|
|
75
76
|
- samanage.gemspec
|
76
77
|
- spec/api/samanage_category_spec.rb
|
77
78
|
- spec/api/samanage_comments_spec.rb
|
79
|
+
- spec/api/samanage_contract_spec.rb
|
78
80
|
- spec/api/samanage_custom_field_spec.rb
|
79
81
|
- spec/api/samanage_custom_form_spec.rb
|
80
82
|
- spec/api/samanage_department_spec.rb
|