samanage 2.1.12 → 2.1.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -1
- data/changelog.md +4 -0
- data/lib/samanage.rb +1 -0
- data/lib/samanage/api.rb +12 -12
- data/lib/samanage/api/category.rb +2 -3
- data/lib/samanage/api/changes.rb +5 -6
- data/lib/samanage/api/comments.rb +3 -3
- data/lib/samanage/api/contracts.rb +6 -6
- data/lib/samanage/api/custom_fields.rb +6 -6
- data/lib/samanage/api/custom_forms.rb +4 -4
- data/lib/samanage/api/departments.rb +6 -6
- data/lib/samanage/api/groups.rb +9 -9
- data/lib/samanage/api/hardwares.rb +6 -6
- data/lib/samanage/api/incidents.rb +14 -14
- data/lib/samanage/api/mobiles.rb +6 -6
- data/lib/samanage/api/other_assets.rb +6 -6
- data/lib/samanage/api/problems.rb +6 -6
- data/lib/samanage/api/purchase_orders.rb +6 -6
- data/lib/samanage/api/releases.rb +57 -0
- data/lib/samanage/api/sites.rb +6 -6
- data/lib/samanage/api/solutions.rb +6 -6
- data/lib/samanage/api/users.rb +7 -7
- data/lib/samanage/api/vendors.rb +6 -6
- data/lib/samanage/version.rb +1 -1
- data/spec/api/samanage_hardware_spec.rb +1 -1
- data/spec/api/samanage_incident_spec.rb +18 -1
- data/spec/api/samanage_purchase_order_spec.rb +4 -3
- data/spec/api/samanage_release_spec.rb +81 -0
- data/spec/api/samanage_time_tracks_spec.rb +7 -7
- 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: 0e46107af1beae0b563cc233e9d69c6727feca40
|
4
|
+
data.tar.gz: 045c5ebd2cfc9103a696af0e7439a17a795c2eb5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02ad1751605e323200930b5a15e19c6fc1ebea3e863a28234dad15a1ff18b10cba47ca152fbf2e9deb1bed845314ca4c295008839eeb8c2f15d13f03b8b89f89
|
7
|
+
data.tar.gz: fe6872d3e228a4f04084786b8ccf9a39e5a3ded0168226d755bd22625bde462c5fffddbe1b052fd065eaf948f34adb727c65c78a1f55f24faa069f5ab9f1bfcf
|
data/README.md
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
# Samanage Ruby Gem
|
2
2
|
[![Gem Version](https://badge.fury.io/rb/samanage.svg)](https://badge.fury.io/rb/samanage)
|
3
|
-
[![Build Status](https://semaphoreci.com/api/v1/projects/8e1f8e7f-6e09-4dad-ac10-e9f41fa61b7d/1437435/shields_badge.svg)](https://semaphoreci.com/cw2908/samanage-ruby)
|
4
3
|
## Requirements
|
5
4
|
- Ruby >= 2.3
|
6
5
|
|
data/changelog.md
CHANGED
data/lib/samanage.rb
CHANGED
@@ -18,6 +18,7 @@ require 'samanage/api/other_assets'
|
|
18
18
|
require 'samanage/api/problems'
|
19
19
|
require 'samanage/api/purchase_orders'
|
20
20
|
require 'samanage/api/requester'
|
21
|
+
require 'samanage/api/releases'
|
21
22
|
require 'samanage/api/sites'
|
22
23
|
require 'samanage/api/solutions'
|
23
24
|
require 'samanage/api/time_tracks'
|
data/lib/samanage/api.rb
CHANGED
@@ -20,6 +20,7 @@ module Samanage
|
|
20
20
|
other_asset: 'other_assets.json',
|
21
21
|
problem: 'problems.json',
|
22
22
|
purchase_order: 'purchase_orders.json',
|
23
|
+
release: 'releases.json',
|
23
24
|
site: 'sites.json',
|
24
25
|
solution: 'solutions.json',
|
25
26
|
user: 'users.json',
|
@@ -57,7 +58,7 @@ module Samanage
|
|
57
58
|
end
|
58
59
|
|
59
60
|
# Calling execute without a method defaults to GET
|
60
|
-
def execute(http_method: 'get', path: nil, payload: nil, verbose: nil, headers: {})
|
61
|
+
def execute(http_method: 'get', path: nil, payload: nil, verbose: nil, headers: {}, options: {})
|
61
62
|
if payload.class == Hash && self.content_type == 'json'
|
62
63
|
begin
|
63
64
|
if path != 'attachments.json'
|
@@ -74,26 +75,23 @@ module Samanage
|
|
74
75
|
end
|
75
76
|
|
76
77
|
headers = headers.merge({
|
77
|
-
'Accept' => "application/vnd.samanage.v2.
|
78
|
-
'Content-
|
78
|
+
'Accept' => "application/vnd.samanage.v2.1+#{self.content_type}#{verbose}",
|
79
|
+
'Content-Type' => "application/#{self.content_type}",
|
79
80
|
'X-Samanage-Authorization' => 'Bearer ' + self.token
|
80
81
|
})
|
81
|
-
|
82
|
-
headers: headers,
|
83
|
-
payload: payload
|
84
|
-
}
|
82
|
+
options = options.except(:verbose)
|
85
83
|
full_path = self.base_url + path
|
86
84
|
retries = 0
|
87
85
|
begin
|
88
86
|
case http_method.to_s.downcase
|
89
87
|
when 'get'
|
90
|
-
api_call = self.class.get(full_path, headers: headers)
|
88
|
+
api_call = self.class.get(full_path, headers: headers, query: options)
|
91
89
|
when 'post'
|
92
|
-
api_call = self.class.post(full_path, body: payload, headers: headers)
|
90
|
+
api_call = self.class.post(full_path, body: payload, headers: headers, query: options)
|
93
91
|
when 'put'
|
94
|
-
api_call = self.class.put(full_path, body: payload, headers: headers)
|
92
|
+
api_call = self.class.put(full_path, body: payload, headers: headers, query: options)
|
95
93
|
when 'delete'
|
96
|
-
api_call = self.class.delete(full_path, body: payload, headers: headers)
|
94
|
+
api_call = self.class.delete(full_path, body: payload, headers: headers, query: options)
|
97
95
|
else
|
98
96
|
raise Samanage::Error.new(response: {response: 'Unknown HTTP method'})
|
99
97
|
end
|
@@ -123,7 +121,9 @@ module Samanage
|
|
123
121
|
response[:data] = JSON.parse(api_call.body)
|
124
122
|
rescue JSON::ParserError => e
|
125
123
|
response[:data] = api_call.body
|
126
|
-
|
124
|
+
if !path.match('send_activation_email')
|
125
|
+
puts "[Warning] #{e.class}: #{e}"
|
126
|
+
end
|
127
127
|
end
|
128
128
|
response
|
129
129
|
when 401
|
@@ -1,9 +1,8 @@
|
|
1
1
|
module Samanage
|
2
2
|
class Api
|
3
3
|
def get_categories(path: PATHS[:category], options: {})
|
4
|
-
|
5
|
-
path
|
6
|
-
self.execute(path: path)
|
4
|
+
path = 'categories.json'
|
5
|
+
self.execute(path: path, options: options)
|
7
6
|
end
|
8
7
|
|
9
8
|
|
data/lib/samanage/api/changes.rb
CHANGED
@@ -3,9 +3,8 @@ module Samanage
|
|
3
3
|
|
4
4
|
# Default get change path
|
5
5
|
def get_changes(path: PATHS[:change], options: {})
|
6
|
-
|
7
|
-
path
|
8
|
-
self.execute(path: path)
|
6
|
+
path = 'changes.json?'
|
7
|
+
self.execute(path: path, options: options)
|
9
8
|
end
|
10
9
|
|
11
10
|
|
@@ -18,10 +17,10 @@ module Samanage
|
|
18
17
|
total_pages = self.get_changes(options: options)[:total_pages]
|
19
18
|
1.upto(total_pages) do |page|
|
20
19
|
options[:page] = page
|
21
|
-
|
20
|
+
|
22
21
|
puts "Collecting changes page: #{page}/#{total_pages}" if options[:verbose]
|
23
|
-
path = "changes.json?"
|
24
|
-
request = self.execute(http_method: 'get', path: path)
|
22
|
+
path = "changes.json?"
|
23
|
+
request = self.execute(http_method: 'get', path: path, options: options)
|
25
24
|
request[:data].each do |change|
|
26
25
|
if block_given?
|
27
26
|
yield change
|
@@ -10,9 +10,9 @@ module Samanage
|
|
10
10
|
|
11
11
|
# Add a new comment
|
12
12
|
def create_comment(incident_id: , comment: , options: {})
|
13
|
-
|
14
|
-
path = "incidents/#{incident_id}/comments.json?"
|
15
|
-
self.execute(http_method: 'post', path: path, payload: comment)
|
13
|
+
|
14
|
+
path = "incidents/#{incident_id}/comments.json?"
|
15
|
+
self.execute(http_method: 'post', path: path, payload: comment, options: options)
|
16
16
|
end
|
17
17
|
|
18
18
|
|
@@ -3,9 +3,9 @@ module Samanage
|
|
3
3
|
|
4
4
|
# Get contract default path
|
5
5
|
def get_contracts(path: PATHS[:contract], options: {})
|
6
|
-
|
7
|
-
path = 'contracts.json?'
|
8
|
-
self.execute(path: path)
|
6
|
+
|
7
|
+
path = 'contracts.json?'
|
8
|
+
self.execute(path: path, options: options)
|
9
9
|
end
|
10
10
|
|
11
11
|
# Get all contracts
|
@@ -14,10 +14,10 @@ module Samanage
|
|
14
14
|
total_pages = self.get_contracts(options: options)[:total_pages]
|
15
15
|
1.upto(total_pages) do |page|
|
16
16
|
options[:page] = page
|
17
|
-
|
17
|
+
|
18
18
|
puts "Collecting contracts page: #{page}/#{total_pages}" if options[:verbose]
|
19
|
-
path = "contracts.json
|
20
|
-
self.execute(path: path)[:data].each do |contract|
|
19
|
+
path = "contracts.json?"
|
20
|
+
self.execute(path: path, options: options)[:data].each do |contract|
|
21
21
|
if block_given?
|
22
22
|
yield contract
|
23
23
|
end
|
@@ -3,9 +3,9 @@ module Samanage
|
|
3
3
|
|
4
4
|
# Get custom fields default url
|
5
5
|
def get_custom_fields(path: PATHS[:custom_fields], options:{})
|
6
|
-
|
7
|
-
path = 'custom_fields.json?'
|
8
|
-
self.execute(path: path)
|
6
|
+
|
7
|
+
path = 'custom_fields.json?'
|
8
|
+
self.execute(path: path, options: options)
|
9
9
|
end
|
10
10
|
|
11
11
|
# Gets all custom fields
|
@@ -14,10 +14,10 @@ module Samanage
|
|
14
14
|
total_pages = self.get_custom_fields(options: options)[:total_pages] ||= 2
|
15
15
|
1.upto(total_pages) do |page|
|
16
16
|
options[:page] = page
|
17
|
-
|
17
|
+
|
18
18
|
puts "Collecting Custom Fields page: #{page}/#{total_pages}" if options[:verbose]
|
19
|
-
path = "custom_fields.json
|
20
|
-
self.execute(path: path)[:data].each do |custom_field|
|
19
|
+
path = "custom_fields.json?"
|
20
|
+
self.execute(path: path, options: options)[:data].each do |custom_field|
|
21
21
|
if block_given?
|
22
22
|
yield custom_field
|
23
23
|
end
|
@@ -2,7 +2,7 @@ module Samanage
|
|
2
2
|
class Api
|
3
3
|
# Get custom forms path
|
4
4
|
def get_custom_forms(path: PATHS[:custom_forms], options: {})
|
5
|
-
|
5
|
+
|
6
6
|
self.execute(path: path)
|
7
7
|
end
|
8
8
|
|
@@ -12,10 +12,10 @@ module Samanage
|
|
12
12
|
total_pages = self.get_custom_forms(options: options)[:total_pages]
|
13
13
|
1.upto(total_pages) do |page|
|
14
14
|
options[:page] = page
|
15
|
-
|
15
|
+
|
16
16
|
puts "Collecting Custom Forms page: #{page}/#{total_pages}" if options[:verbose]
|
17
|
-
path = "custom_forms.json
|
18
|
-
self.execute(path: path)[:data].each do |custom_form|
|
17
|
+
path = "custom_forms.json?"
|
18
|
+
self.execute(path: path, options: options)[:data].each do |custom_form|
|
19
19
|
if block_given?
|
20
20
|
yield custom_form
|
21
21
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module Samanage
|
2
2
|
class Api
|
3
3
|
def get_departments(path: PATHS[:department], options: {})
|
4
|
-
|
5
|
-
path = 'departments.json?'
|
6
|
-
self.execute(path: path)
|
4
|
+
|
5
|
+
path = 'departments.json?'
|
6
|
+
self.execute(path: path, options: options)
|
7
7
|
end
|
8
8
|
|
9
9
|
def collect_departments(options: {})
|
@@ -11,10 +11,10 @@ module Samanage
|
|
11
11
|
total_pages = self.get_departments(options: options)[:total_pages]
|
12
12
|
1.upto(total_pages) do |page|
|
13
13
|
options[:page] = page
|
14
|
-
|
14
|
+
|
15
15
|
puts "Collecting Departments page: #{page}/#{total_pages}" if options[:verbose]
|
16
|
-
path = "departments.json
|
17
|
-
self.execute(path: path)[:data].each do |department|
|
16
|
+
path = "departments.json?"
|
17
|
+
self.execute(path: path, options: options)[:data].each do |department|
|
18
18
|
if block_given?
|
19
19
|
yield department
|
20
20
|
end
|
data/lib/samanage/api/groups.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
module Samanage
|
2
2
|
class Api
|
3
3
|
def get_groups(path: PATHS[:group], options: {})
|
4
|
-
|
5
|
-
path = 'groups.json?'
|
6
|
-
self.execute(path: path)
|
4
|
+
|
5
|
+
path = 'groups.json?'
|
6
|
+
self.execute(path: path, options: options)
|
7
7
|
end
|
8
8
|
|
9
9
|
def collect_groups(options: {})
|
@@ -11,10 +11,10 @@ module Samanage
|
|
11
11
|
total_pages = self.get_groups(options: options)[:total_pages]
|
12
12
|
1.upto(total_pages) do |page|
|
13
13
|
options[:page] = page
|
14
|
-
|
14
|
+
|
15
15
|
puts "Collecting Groups page: #{page}/#{total_pages}" if options[:verbose]
|
16
|
-
path = 'groups.json?'
|
17
|
-
self.execute(path: path)[:data].each do |group|
|
16
|
+
path = 'groups.json?'
|
17
|
+
self.execute(path: path, options: options)[:data].each do |group|
|
18
18
|
if block_given?
|
19
19
|
yield group
|
20
20
|
end
|
@@ -30,9 +30,9 @@ module Samanage
|
|
30
30
|
|
31
31
|
def find_group_id_by_name(group: '', options: {})
|
32
32
|
options.merge!({name: group}) if group && !options.keys.include?(:name)
|
33
|
-
|
34
|
-
path = "groups.json?"
|
35
|
-
group_api = self.execute(path: path )
|
33
|
+
|
34
|
+
path = "groups.json?"
|
35
|
+
group_api = self.execute(path: path, options: options)
|
36
36
|
# Group names are case sensitive
|
37
37
|
if !group_api[:data].empty? && group == group_api[:data].first['name']
|
38
38
|
return group_api[:data].first['id']
|
@@ -3,9 +3,9 @@ module Samanage
|
|
3
3
|
|
4
4
|
# Get hardware default path
|
5
5
|
def get_hardwares(path: PATHS[:hardware], options: {})
|
6
|
-
|
7
|
-
path = 'hardwares.json?'
|
8
|
-
self.execute(path: path)
|
6
|
+
|
7
|
+
path = 'hardwares.json?'
|
8
|
+
self.execute(path: path, options: options)
|
9
9
|
end
|
10
10
|
|
11
11
|
# Get all hardwares
|
@@ -14,10 +14,10 @@ module Samanage
|
|
14
14
|
total_pages = self.get_hardwares(options: options)[:total_pages]
|
15
15
|
1.upto(total_pages) do |page|
|
16
16
|
options[:page] = page
|
17
|
-
|
17
|
+
|
18
18
|
puts "Collecting Hardwares page: #{page}/#{total_pages}" if options[:verbose]
|
19
|
-
path = "hardwares.json
|
20
|
-
self.execute(path: path)[:data].each do |hardware|
|
19
|
+
path = "hardwares.json?"
|
20
|
+
self.execute(path: path, options: options)[:data].each do |hardware|
|
21
21
|
if block_given?
|
22
22
|
yield hardware
|
23
23
|
end
|
@@ -3,9 +3,9 @@ module Samanage
|
|
3
3
|
|
4
4
|
# Default get incident path
|
5
5
|
def get_incidents(path: PATHS[:incident], options: {})
|
6
|
-
|
7
|
-
path = 'incidents.json?'
|
8
|
-
self.execute(path: path)
|
6
|
+
|
7
|
+
path = 'incidents.json?'
|
8
|
+
self.execute(path: path,options: options)
|
9
9
|
end
|
10
10
|
|
11
11
|
|
@@ -22,8 +22,8 @@ module Samanage
|
|
22
22
|
if options[:audit_archives]
|
23
23
|
options[:page] = page
|
24
24
|
params = URI.encode_www_form(options.except(:audit_archives,:audit_archive,:layout)) # layout not needed as audit only on individual record
|
25
|
-
paginated_path = "incidents.json?"
|
26
|
-
paginated_incidents = self.execute(path: paginated_path)[:data]
|
25
|
+
paginated_path = "incidents.json?"
|
26
|
+
paginated_incidents = self.execute(path: paginated_path, options: options)[:data]
|
27
27
|
paginated_incidents.map do |incident|
|
28
28
|
params = self.set_params(options: options.except(:audit_archives,:audit_archive,:layout))
|
29
29
|
archive_uri = "incidents/#{incident['id']}.json?layout=long&audit_archive=true"
|
@@ -35,9 +35,9 @@ module Samanage
|
|
35
35
|
end
|
36
36
|
else
|
37
37
|
options[:page] = page
|
38
|
-
|
39
|
-
path = "incidents.json?"
|
40
|
-
self.execute(path: path)[:data].each do |incident|
|
38
|
+
|
39
|
+
path = "incidents.json?"
|
40
|
+
self.execute(path: path, options: options)[:data].each do |incident|
|
41
41
|
if block_given?
|
42
42
|
yield incident
|
43
43
|
end
|
@@ -57,16 +57,16 @@ module Samanage
|
|
57
57
|
# Find incident by ID
|
58
58
|
def find_incident(id: , options: {})
|
59
59
|
|
60
|
-
|
61
|
-
path = "incidents/#{id}.json?"
|
62
|
-
self.execute(path: path)
|
60
|
+
|
61
|
+
path = "incidents/#{id}.json?"
|
62
|
+
self.execute(path: path, options: options)
|
63
63
|
end
|
64
64
|
|
65
65
|
# Update an incident given id and json
|
66
66
|
def update_incident(payload: , id: , options: {})
|
67
|
-
|
68
|
-
path = "incidents/#{id}.json?"
|
69
|
-
self.execute(path: path, http_method: 'put', payload: payload)
|
67
|
+
|
68
|
+
path = "incidents/#{id}.json?"
|
69
|
+
self.execute(path: path, http_method: 'put', payload: payload, options: options)
|
70
70
|
end
|
71
71
|
|
72
72
|
def delete_incident(id: )
|
data/lib/samanage/api/mobiles.rb
CHANGED
@@ -3,9 +3,9 @@ module Samanage
|
|
3
3
|
|
4
4
|
# Get mobile default path
|
5
5
|
def get_mobiles(path: PATHS[:mobile], options: {})
|
6
|
-
|
7
|
-
path = 'mobiles.json?'
|
8
|
-
self.execute(path: path)
|
6
|
+
|
7
|
+
path = 'mobiles.json?'
|
8
|
+
self.execute(path: path, options: options)
|
9
9
|
|
10
10
|
end
|
11
11
|
|
@@ -15,10 +15,10 @@ module Samanage
|
|
15
15
|
total_pages = self.get_mobiles(options: options)[:total_pages]
|
16
16
|
1.upto(total_pages) do |page|
|
17
17
|
options[:page] = page
|
18
|
-
|
18
|
+
|
19
19
|
puts "Collecting Mobiles page: #{page}/#{total_pages}" if options[:verbose]
|
20
|
-
path = "mobiles.json
|
21
|
-
self.execute(path: path)[:data].each do |mobile|
|
20
|
+
path = "mobiles.json?"
|
21
|
+
self.execute(path: path, options: options)[:data].each do |mobile|
|
22
22
|
if block_given?
|
23
23
|
yield mobiles
|
24
24
|
end
|
@@ -3,9 +3,9 @@ module Samanage
|
|
3
3
|
|
4
4
|
# Default get other_assets path
|
5
5
|
def get_other_assets(path: PATHS[:other_asset], options: {})
|
6
|
-
|
7
|
-
path = 'other_assets.json?'
|
8
|
-
self.execute(path: path)
|
6
|
+
|
7
|
+
path = 'other_assets.json?'
|
8
|
+
self.execute(path: path, options: options)
|
9
9
|
end
|
10
10
|
|
11
11
|
# Returns all other assets
|
@@ -15,10 +15,10 @@ module Samanage
|
|
15
15
|
other_assets = []
|
16
16
|
1.upto(total_pages) do |page|
|
17
17
|
options[:page] = page
|
18
|
-
|
18
|
+
|
19
19
|
puts "Collecting Other Assets page: #{page}/#{total_pages}" if options[:verbose]
|
20
|
-
path = "other_assets.json
|
21
|
-
self.execute(path: path)[:data].each do |other_asset|
|
20
|
+
path = "other_assets.json?"
|
21
|
+
self.execute(path: path, options: options)[:data].each do |other_asset|
|
22
22
|
if block_given?
|
23
23
|
yield other_asset
|
24
24
|
end
|
@@ -3,9 +3,9 @@ module Samanage
|
|
3
3
|
|
4
4
|
# Default get problem path
|
5
5
|
def get_problems(path: PATHS[:problem], options: {})
|
6
|
-
|
7
|
-
path = 'problems.json?'
|
8
|
-
self.execute(path: path)
|
6
|
+
|
7
|
+
path = 'problems.json?'
|
8
|
+
self.execute(path: path, options: options)
|
9
9
|
end
|
10
10
|
|
11
11
|
|
@@ -18,10 +18,10 @@ module Samanage
|
|
18
18
|
total_pages = self.get_problems(options: options)[:total_pages]
|
19
19
|
1.upto(total_pages) do |page|
|
20
20
|
options[:page] = page
|
21
|
-
|
21
|
+
|
22
22
|
puts "Collecting problems page: #{page}/#{total_pages}" if options[:verbose]
|
23
|
-
path = "problems.json?"
|
24
|
-
request = self.execute(http_method: 'get', path: path)
|
23
|
+
path = "problems.json?"
|
24
|
+
request = self.execute(http_method: 'get', path: path, options: options)
|
25
25
|
request[:data].each do |problem|
|
26
26
|
if block_given?
|
27
27
|
yield problem
|
@@ -3,9 +3,9 @@ module Samanage
|
|
3
3
|
|
4
4
|
# Default get purchase_order path
|
5
5
|
def get_purchase_orders(path: PATHS[:purchase_order], options: {})
|
6
|
-
|
7
|
-
path = 'purchase_orders.json?'
|
8
|
-
self.execute(path: path)
|
6
|
+
|
7
|
+
path = 'purchase_orders.json?'
|
8
|
+
self.execute(path: path, options: options)
|
9
9
|
end
|
10
10
|
|
11
11
|
|
@@ -18,10 +18,10 @@ module Samanage
|
|
18
18
|
total_pages = self.get_purchase_orders(options: options)[:total_pages]
|
19
19
|
1.upto(total_pages) do |page|
|
20
20
|
options[:page] = page
|
21
|
-
|
21
|
+
|
22
22
|
puts "Collecting purchase_orders page: #{page}/#{total_pages}" if options[:verbose]
|
23
|
-
path = "purchase_orders.json?"
|
24
|
-
request = self.execute(http_method: 'get', path: path)
|
23
|
+
path = "purchase_orders.json?"
|
24
|
+
request = self.execute(http_method: 'get', path: path, options: options)
|
25
25
|
request[:data].each do |purchase_order|
|
26
26
|
if block_given?
|
27
27
|
yield purchase_order
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Samanage
|
2
|
+
class Api
|
3
|
+
|
4
|
+
# Default get releases path
|
5
|
+
def get_releases(path: PATHS[:release], options: {})
|
6
|
+
|
7
|
+
path = 'releases.json?'
|
8
|
+
self.execute(path: path, options: options)
|
9
|
+
end
|
10
|
+
|
11
|
+
# Returns all other assets
|
12
|
+
def collect_releases(options: {})
|
13
|
+
releases = Array.new
|
14
|
+
total_pages = self.get_releases(options: options)[:total_pages]
|
15
|
+
releases = []
|
16
|
+
1.upto(total_pages) do |page|
|
17
|
+
options[:page] = page
|
18
|
+
|
19
|
+
puts "Collecting Other Assets page: #{page}/#{total_pages}" if options[:verbose]
|
20
|
+
path = "releases.json?"
|
21
|
+
self.execute(path: path, options: options)[:data].each do |release|
|
22
|
+
if block_given?
|
23
|
+
yield release
|
24
|
+
end
|
25
|
+
releases << release
|
26
|
+
end
|
27
|
+
end
|
28
|
+
releases
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
# Create an release given json
|
33
|
+
def create_release(payload: , options: {})
|
34
|
+
self.execute(path: PATHS[:release], http_method: 'post', payload: payload)
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
# Find release by id
|
39
|
+
def find_release(id: )
|
40
|
+
path = "releases/#{id}.json"
|
41
|
+
self.execute(path: path)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Update release given json and id
|
45
|
+
def update_release(payload: , id: , options: {})
|
46
|
+
path = "releases/#{id}.json"
|
47
|
+
self.execute(path: path, http_method: 'put', payload: payload)
|
48
|
+
end
|
49
|
+
|
50
|
+
def delete_release(id: )
|
51
|
+
self.execute(path: "releases/#{id}.json", http_method: 'delete')
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
alias_method :releases, :collect_releases
|
56
|
+
end
|
57
|
+
end
|
data/lib/samanage/api/sites.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
module Samanage
|
2
2
|
class Api
|
3
3
|
def get_sites(path: PATHS[:site], options: {})
|
4
|
-
|
5
|
-
path = 'sites.json?'
|
6
|
-
self.execute(path: path)
|
4
|
+
|
5
|
+
path = 'sites.json?'
|
6
|
+
self.execute(path: path, options: options)
|
7
7
|
end
|
8
8
|
|
9
9
|
def collect_sites(options: {})
|
@@ -11,10 +11,10 @@ module Samanage
|
|
11
11
|
total_pages = self.get_sites(options: options)[:total_pages]
|
12
12
|
1.upto(total_pages) do |page|
|
13
13
|
options[:page] = page
|
14
|
-
|
14
|
+
|
15
15
|
puts "Collecting Sites page: #{page}/#{total_pages}" if options[:verbose]
|
16
|
-
path = "sites.json?"
|
17
|
-
self.execute(path: path)[:data].each do |site|
|
16
|
+
path = "sites.json?"
|
17
|
+
self.execute(path: path, options: options)[:data].each do |site|
|
18
18
|
if block_given?
|
19
19
|
yield site
|
20
20
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module Samanage
|
2
2
|
class Api
|
3
3
|
def get_solutions(path: PATHS[:solution], options: {})
|
4
|
-
|
5
|
-
path = 'solutions.json?'
|
6
|
-
self.execute(path: path)
|
4
|
+
|
5
|
+
path = 'solutions.json?'
|
6
|
+
self.execute(path: path, options: options)
|
7
7
|
end
|
8
8
|
|
9
9
|
def collect_solutions(options: {})
|
@@ -11,10 +11,10 @@ module Samanage
|
|
11
11
|
total_pages = self.get_solutions(options: options)[:total_pages]
|
12
12
|
1.upto(total_pages) do |page|
|
13
13
|
options[:page] = page
|
14
|
-
|
14
|
+
|
15
15
|
puts "Collecting Solutions page: #{page}/#{total_pages}" if options[:verbose]
|
16
|
-
path = "solutions.json?"
|
17
|
-
self.execute(http_method: 'get', path: path)[:data].each do |solution|
|
16
|
+
path = "solutions.json?"
|
17
|
+
self.execute(http_method: 'get', path: path, options: options)[:data].each do |solution|
|
18
18
|
if block_given?
|
19
19
|
yield solution
|
20
20
|
end
|
data/lib/samanage/api/users.rb
CHANGED
@@ -3,9 +3,9 @@ module Samanage
|
|
3
3
|
|
4
4
|
# Get users, using URL builder
|
5
5
|
def get_users(path: PATHS[:user], options: {})
|
6
|
-
|
7
|
-
path = 'users.json?'
|
8
|
-
self.execute(path: path)
|
6
|
+
|
7
|
+
path = 'users.json?'
|
8
|
+
self.execute(path: path, options: options)
|
9
9
|
end
|
10
10
|
|
11
11
|
# Returns all users in the account
|
@@ -14,11 +14,11 @@ module Samanage
|
|
14
14
|
total_pages = self.get_users(options: options)[:total_pages]
|
15
15
|
1.upto(total_pages) do |page|
|
16
16
|
options[:page] = page
|
17
|
-
|
18
|
-
path = "users.json?"
|
17
|
+
|
18
|
+
path = "users.json?"
|
19
19
|
puts "Collecting Users page: #{page}/#{total_pages}" if options[:verbose]
|
20
|
-
path = "users.json
|
21
|
-
self.execute(path: path)[:data].each do |user|
|
20
|
+
path = "users.json?"
|
21
|
+
self.execute(path: path, options: options)[:data].each do |user|
|
22
22
|
if block_given?
|
23
23
|
yield user
|
24
24
|
end
|
data/lib/samanage/api/vendors.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
module Samanage
|
2
2
|
class Api
|
3
3
|
def get_vendors(path: PATHS[:vendor], options: {})
|
4
|
-
|
5
|
-
path = 'vendors.json?'
|
6
|
-
self.execute(path: path)
|
4
|
+
|
5
|
+
path = 'vendors.json?'
|
6
|
+
self.execute(path: path, options: options)
|
7
7
|
end
|
8
8
|
|
9
9
|
def collect_vendors(options: {})
|
@@ -11,10 +11,10 @@ module Samanage
|
|
11
11
|
total_pages = self.get_vendors(options: options)[:total_pages]
|
12
12
|
1.upto(total_pages) do |page|
|
13
13
|
options[:page] = page
|
14
|
-
|
14
|
+
|
15
15
|
puts "Collecting vendors page: #{page}/#{total_pages}" if options[:verbose]
|
16
|
-
path = "vendors.json?"
|
17
|
-
self.execute(http_method: 'get', path: path)[:data].each do |vendor|
|
16
|
+
path = "vendors.json?"
|
17
|
+
self.execute(http_method: 'get', path: path, options: options)[:data].each do |vendor|
|
18
18
|
if block_given?
|
19
19
|
yield vendor
|
20
20
|
end
|
data/lib/samanage/version.rb
CHANGED
@@ -34,7 +34,7 @@ describe Samanage::Api do
|
|
34
34
|
|
35
35
|
expect(hardware_create[:data]['id']).to be_an(Integer)
|
36
36
|
expect(hardware_create[:data]['name']).to eq(hardware_name)
|
37
|
-
expect(hardware_create[:code]).to eq(
|
37
|
+
expect(hardware_create[:code]).to eq(200).or(201)
|
38
38
|
end
|
39
39
|
it 'create_hardware: fails if no serial' do
|
40
40
|
hardware_name = "samanage-ruby-#{(rand*10**10).ceil}"
|
@@ -74,7 +74,6 @@ describe Samanage::Api do
|
|
74
74
|
it 'update_incident: update_incident by id' do
|
75
75
|
sample_incident = @incidents.reject{|i| ['Closed','Resolved'].include? i['state']}.sample
|
76
76
|
sample_id = sample_incident['id']
|
77
|
-
name = Faker::Movie.quote
|
78
77
|
description = [Faker::String.random,Faker::Seinfeld.quote,Faker::Lorem.paragraph].sample
|
79
78
|
incident_json = {
|
80
79
|
:incident => {
|
@@ -106,6 +105,24 @@ describe Samanage::Api do
|
|
106
105
|
incident_delete = @samanage.delete_incident(id: sample_incident_id)
|
107
106
|
expect(incident_delete[:code]).to eq(200).or(201)
|
108
107
|
end
|
108
|
+
it 'Sends an email if add_callbacks=true in params' do
|
109
|
+
sample_id = @samanage.get_incidents[:data].sample['id']
|
110
|
+
audits_req = @samanage.find_incident(id: sample_id, options: {layout: 'long'})
|
111
|
+
|
112
|
+
initial_email_audits = audits_req.dig(:data,'audits').select{|audit| audit['message'].match(/was sent./) }.count
|
113
|
+
incident_json = {
|
114
|
+
:incident => {
|
115
|
+
due_at: Date.new(2019,rand(11) + 1, rand(27) + 1), # need to configure email notifications for due date change
|
116
|
+
assignee: {email: @users.find{|u| u.dig('role','name') == 'Administrator'}.dig('email')}
|
117
|
+
}
|
118
|
+
}
|
119
|
+
|
120
|
+
@samanage.update_incident(payload: incident_json, id: sample_id, options: {add_callbacks: true})
|
121
|
+
sleep 5 # Wait for email to send
|
122
|
+
final_audits_req = @samanage.find_incident(id: sample_id, options: {layout: 'long'})
|
123
|
+
final_email_audits = final_audits_req.dig(:data,'audits').select{|audit| audit['message'].match(/was sent./) }.count
|
124
|
+
expect(initial_email_audits).to be < final_email_audits
|
125
|
+
end
|
109
126
|
end
|
110
127
|
end
|
111
128
|
end
|
@@ -8,6 +8,7 @@ describe Samanage::Api do
|
|
8
8
|
@samanage = Samanage::Api.new(token: TOKEN)
|
9
9
|
@purchase_orders = @samanage.purchase_orders
|
10
10
|
@users = @samanage.get_users[:data]
|
11
|
+
@vendors = @samanage.get_vendors[:data]
|
11
12
|
end
|
12
13
|
it 'get_purchase_orders: it returns API call of purchase_orders' do
|
13
14
|
api_call = @samanage.get_purchase_orders
|
@@ -23,13 +24,13 @@ describe Samanage::Api do
|
|
23
24
|
expect(@purchase_orders.size).to eq(purchase_order_count)
|
24
25
|
end
|
25
26
|
it 'create_purchase_order(payload: json): creates a purchase_order' do
|
26
|
-
users_email = @
|
27
|
+
users_email = @users.find{|u| u['role']['name']=='Administrator'}.to_h['email']
|
27
28
|
purchase_order_name = Faker::Book.title
|
28
29
|
json = {
|
29
30
|
purchase_order: {
|
30
31
|
buyer: {email: users_email},
|
31
32
|
name: purchase_order_name,
|
32
|
-
vendor: {name: '
|
33
|
+
vendor: {name: @vendors.sample['name']}
|
33
34
|
}
|
34
35
|
}
|
35
36
|
purchase_order_create = @samanage.create_purchase_order(payload: json)
|
@@ -37,7 +38,7 @@ describe Samanage::Api do
|
|
37
38
|
expect(purchase_order_create[:data]['name']).to eq(purchase_order_name)
|
38
39
|
expect(purchase_order_create[:code]).to eq(200).or(201)
|
39
40
|
end
|
40
|
-
it 'create_purchase_order: fails if no
|
41
|
+
it 'create_purchase_order: fails if no vendor' do
|
41
42
|
users_email = @users.sample['email']
|
42
43
|
json = {
|
43
44
|
:purchase_order => {
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'samanage'
|
2
|
+
|
3
|
+
describe Samanage::Api do
|
4
|
+
context 'Other Assets' 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
|
+
@releases = @samanage.get_releases[:data]
|
10
|
+
@users = @samanage.get_users[:data]
|
11
|
+
|
12
|
+
end
|
13
|
+
it 'get_releases: it returns API call of releases' do
|
14
|
+
api_call = @samanage.get_releases
|
15
|
+
expect(api_call).to be_a(Hash)
|
16
|
+
expect(api_call[:total_count]).to be_an(Integer)
|
17
|
+
expect(api_call).to have_key(:response)
|
18
|
+
expect(api_call).to have_key(:code)
|
19
|
+
end
|
20
|
+
it 'collect_releases: collects array of releases' do
|
21
|
+
expect(@releases).to be_an(Array)
|
22
|
+
end
|
23
|
+
it 'create_release(payload: json): creates a release' do
|
24
|
+
7.times do |time|
|
25
|
+
release_name = "samanage-ruby-#{(rand*10**10).ceil}"
|
26
|
+
json = {
|
27
|
+
:release => {
|
28
|
+
name: release_name,
|
29
|
+
requester: {email: @users.sample['email']},
|
30
|
+
state: 'Open'
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
release_create = @samanage.create_release(payload: json)
|
35
|
+
expect(release_create[:data]['id']).to be_an(Integer)
|
36
|
+
expect(release_create[:data]['name']).to eq(release_name)
|
37
|
+
expect(release_create[:code]).to eq(200).or(201)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
it 'create_release: fails if wrong fields' do
|
41
|
+
release_name = "samanage-ruby-#{(rand*10**10).ceil}"
|
42
|
+
json = {
|
43
|
+
:release => {
|
44
|
+
name: release_name,
|
45
|
+
}
|
46
|
+
}
|
47
|
+
expect{@samanage.create_release(payload: json)}.to raise_error(Samanage::InvalidRequest)
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'find_release: returns an release card by known id' do
|
51
|
+
sample_id = @releases.sample['id']
|
52
|
+
release = @samanage.find_release(id: sample_id)
|
53
|
+
|
54
|
+
expect(release[:data]['id']).to eq(sample_id) # id should match found release
|
55
|
+
expect(release[:data]).to have_key('name')
|
56
|
+
expect(release[:data]).to have_key('id')
|
57
|
+
end
|
58
|
+
it 'find_release: returns nothing for an invalid id' do
|
59
|
+
sample_id = (0..10).entries.sample
|
60
|
+
expect{@samanage.find_release(id: sample_id)}.to raise_error(Samanage::NotFound) # id should match found release
|
61
|
+
end
|
62
|
+
it 'update_release: update_release by id' do
|
63
|
+
sample_id = @releases.sample['id']
|
64
|
+
new_name = (0...50).map { ('a'..'z').to_a[rand(26)] }.join
|
65
|
+
json = {
|
66
|
+
:release => {
|
67
|
+
:name => new_name
|
68
|
+
}
|
69
|
+
}
|
70
|
+
release_update = @samanage.update_release(payload: json, id: sample_id)
|
71
|
+
expect(release_update[:data]["name"]).to eq(new_name)
|
72
|
+
expect(release_update[:code]).to eq(200).or(201)
|
73
|
+
end
|
74
|
+
it 'deletes a valid release' do
|
75
|
+
sample_release_id = @releases.sample['id']
|
76
|
+
release_delete = @samanage.delete_release(id: sample_release_id)
|
77
|
+
expect(release_delete[:code]).to eq(200).or(201)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -8,6 +8,13 @@ describe Samanage::Api do
|
|
8
8
|
@samanage = Samanage::Api.new(token: TOKEN)
|
9
9
|
@incidents = @samanage.incidents
|
10
10
|
end
|
11
|
+
it 'Returns empty when no time tracks for valid incident' do
|
12
|
+
incidents_without_time_tracks = @incidents.select{|incident| incident['time_tracks'].to_a.empty?}
|
13
|
+
incident_id = incidents_without_time_tracks.sample.dig('id')
|
14
|
+
time_tracks = @samanage.time_tracks(incident_id: incident_id)
|
15
|
+
expect(time_tracks).to be_an(Array)
|
16
|
+
expect(time_tracks).to be_empty
|
17
|
+
end
|
11
18
|
it 'creates a time_track' do
|
12
19
|
incident_id = @incidents.sample.dig('id')
|
13
20
|
name = [Faker::NatoPhoneticAlphabet.code_word,Faker::NatoPhoneticAlphabet.code_word,Faker::NatoPhoneticAlphabet.code_word].join(' ')
|
@@ -43,13 +50,6 @@ describe Samanage::Api do
|
|
43
50
|
})
|
44
51
|
expect(request[:code]).to eq(200).or(201)
|
45
52
|
end
|
46
|
-
it 'Returns empty when no time tracks for valid incident' do
|
47
|
-
incidents_without_time_tracks = @incidents.reject{|incident| !incident['time_tracks'].to_a.empty?}
|
48
|
-
incident_id = incidents_without_time_tracks.sample.dig('id')
|
49
|
-
time_tracks = @samanage.time_tracks(incident_id: incident_id)
|
50
|
-
expect(time_tracks).to be_an(Array)
|
51
|
-
expect(time_tracks).to be_empty
|
52
|
-
end
|
53
53
|
it 'fails when invalid incident' do
|
54
54
|
expect { @samanage.time_tracks(incident_id: rand(100)) }.to raise_error(Samanage::NotFound)
|
55
55
|
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.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Walls
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -68,6 +68,7 @@ files:
|
|
68
68
|
- lib/samanage/api/other_assets.rb
|
69
69
|
- lib/samanage/api/problems.rb
|
70
70
|
- lib/samanage/api/purchase_orders.rb
|
71
|
+
- lib/samanage/api/releases.rb
|
71
72
|
- lib/samanage/api/requester.rb
|
72
73
|
- lib/samanage/api/sites.rb
|
73
74
|
- lib/samanage/api/solutions.rb
|
@@ -97,6 +98,7 @@ files:
|
|
97
98
|
- spec/api/samanage_other_asset_spec.rb
|
98
99
|
- spec/api/samanage_problem_spec.rb
|
99
100
|
- spec/api/samanage_purchase_order_spec.rb
|
101
|
+
- spec/api/samanage_release_spec.rb
|
100
102
|
- spec/api/samanage_site_spec.rb
|
101
103
|
- spec/api/samanage_solution_spec.rb
|
102
104
|
- spec/api/samanage_time_tracks_spec.rb
|