samanage 1.8.7 → 1.8.8
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 +5 -0
- data/lib/samanage/api.rb +8 -4
- data/lib/samanage/api/incidents.rb +16 -6
- data/lib/samanage/error.rb +2 -3
- data/lib/samanage/version.rb +1 -1
- data/spec/api/samanage_comments_spec.rb +4 -4
- data/spec/api/samanage_incident_spec.rb +12 -2
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4cedeeea723b8028baf7e86f24cd0fdc19e92ab1
|
|
4
|
+
data.tar.gz: e5c30e6130bed20c7ab1307af38fad03ecaad412
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 80188be6d78b1eab07e99d5a076485fed80ddd2ba7c2cfc400817a0df3173d7ec45252e7fdb88f096e61f0abcc4e9ad5b64652fcefbaa15a7695b1483cd9a12f
|
|
7
|
+
data.tar.gz: fda39d8acf665d196c624102ddb1aa50fdd6d01dcba93eb9e640a4a34894f4968d6a7186ea96e608f704cb6ecbec4d506199da70f09968391a80557e89777f3f
|
data/changelog.md
CHANGED
data/lib/samanage/api.rb
CHANGED
|
@@ -20,9 +20,8 @@ module Samanage
|
|
|
20
20
|
|
|
21
21
|
# Development mode forzes authorization & prepopulates custom forms/fields and admins
|
|
22
22
|
# datacenter should equal 'eu' or blank
|
|
23
|
-
def initialize(token:
|
|
24
|
-
self.
|
|
25
|
-
self.token = token if token
|
|
23
|
+
def initialize(token: , datacenter: nil, development_mode: false, max_retries: MAX_RETRIES)
|
|
24
|
+
self.token = token
|
|
26
25
|
if !datacenter.nil? && datacenter.to_s.downcase != 'eu'
|
|
27
26
|
datacenter = nil
|
|
28
27
|
end
|
|
@@ -30,6 +29,7 @@ module Samanage
|
|
|
30
29
|
self.base_url = "https://api#{self.datacenter.to_s.downcase}.samanage.com/"
|
|
31
30
|
self.content_type = 'json'
|
|
32
31
|
self.admins = []
|
|
32
|
+
self.max_retries = max_retries
|
|
33
33
|
if development_mode
|
|
34
34
|
if self.authorized? != true
|
|
35
35
|
self.authorize
|
|
@@ -87,8 +87,12 @@ module Samanage
|
|
|
87
87
|
api_call = self.class.post(full_path, query: payload, headers: headers)
|
|
88
88
|
when 'put'
|
|
89
89
|
api_call = self.class.put(full_path, query: payload, headers: headers)
|
|
90
|
+
when 'delete'
|
|
91
|
+
api_call = self.class.put(full_path, query: payload, headers: headers)
|
|
92
|
+
else
|
|
93
|
+
raise Samanage::Error.new(response: {response: 'Unknown HTTP method'})
|
|
90
94
|
end
|
|
91
|
-
rescue Errno::ECONNREFUSED, Net::OpenTimeout => e
|
|
95
|
+
rescue Errno::ECONNREFUSED, Net::OpenTimeout, Errno::ETIMEDOUT => e
|
|
92
96
|
puts "#{e} - #{e.class}"
|
|
93
97
|
puts "Retry: #{retries}/#{self.max_retries}"
|
|
94
98
|
retries += 1
|
|
@@ -8,15 +8,25 @@ module Samanage
|
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
# Returns all incidents
|
|
11
|
+
# Returns all incidents.
|
|
12
|
+
# Options:
|
|
13
|
+
# - audit_archives: true
|
|
14
|
+
# - layout: 'long'
|
|
12
15
|
def collect_incidents(options: {})
|
|
13
|
-
page = 1
|
|
14
16
|
incidents = Array.new
|
|
15
17
|
total_pages = self.get_incidents[:total_pages]
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
1.upto(total_pages) do |page|
|
|
19
|
+
if options[:audit_archives]
|
|
20
|
+
archives = 'layout=long&audit_archive=true'
|
|
21
|
+
paginated_incidents = self.execute(path: "incidents.json?page=#{page}")[:data]
|
|
22
|
+
paginated_incidents.map do |incident|
|
|
23
|
+
archive_path = "incidents/#{incident['id']}.json?#{archives}"
|
|
24
|
+
incidents << self.execute(path: archive_path)[:data]
|
|
25
|
+
end
|
|
26
|
+
else
|
|
27
|
+
layout = options[:layout] == 'long' ? '&layout=long' : nil
|
|
28
|
+
incidents += self.execute(http_method: 'get', path: "incidents.json?page=#{page}#{layout}")[:data]
|
|
29
|
+
end
|
|
20
30
|
end
|
|
21
31
|
incidents
|
|
22
32
|
end
|
data/lib/samanage/error.rb
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
module Samanage
|
|
2
|
-
# Errors in gem
|
|
3
2
|
class Error < StandardError
|
|
4
3
|
attr_accessor :status_code, :response, :error
|
|
4
|
+
|
|
5
5
|
def initialize(error: nil, response: {})
|
|
6
|
+
self.error = error
|
|
6
7
|
if response.class == Hash
|
|
7
8
|
self.status_code = response[:code]
|
|
8
9
|
self.response = response[:data] ||= response[:response]
|
|
@@ -11,10 +12,8 @@ module Samanage
|
|
|
11
12
|
self.response = response
|
|
12
13
|
end
|
|
13
14
|
|
|
14
|
-
self.error = error
|
|
15
15
|
puts "[Error] #{self.status_code}: #{self.response}"
|
|
16
16
|
end
|
|
17
|
-
|
|
18
17
|
end
|
|
19
18
|
|
|
20
19
|
# API Errors
|
data/lib/samanage/version.rb
CHANGED
|
@@ -26,10 +26,10 @@ describe Samanage::Api do
|
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
it 'collects all comments' do
|
|
29
|
-
incident_id = @controller.get_incidents()[:data].sample.dig('id')
|
|
30
|
-
incident_id = 19394209
|
|
31
|
-
comments_api = @controller.get_comments(incident_id: incident_id)
|
|
32
|
-
comments_found = @controller.collect_comments(incident_id: incident_id)
|
|
29
|
+
## incident_id = @controller.get_incidents()[:data].sample.dig('id')
|
|
30
|
+
# incident_id = 19394209
|
|
31
|
+
# comments_api = @controller.get_comments(incident_id: incident_id)
|
|
32
|
+
# comments_found = @controller.collect_comments(incident_id: incident_id)
|
|
33
33
|
|
|
34
34
|
# Total count bug
|
|
35
35
|
# expect(comments_api[:total_count]).to eq(comments_found.size)
|
|
@@ -74,10 +74,20 @@ describe Samanage::Api do
|
|
|
74
74
|
expect(incident_update[:code]).to eq(200).or(201)
|
|
75
75
|
end
|
|
76
76
|
it 'finds more data for option[:layout] = "long"' do
|
|
77
|
+
full_layout_incident_keys = @controller.incidents(options: {layout: 'long'}).first.keys
|
|
78
|
+
basic_incident_keys = @controller.incidents.sample.keys
|
|
79
|
+
expect(basic_incident_keys.size).to be < full_layout_incident_keys.size
|
|
80
|
+
end
|
|
81
|
+
it 'finds more audit archives for option[:audit_archives] = true' do
|
|
82
|
+
incident_keys = @controller.incidents(options: {audit_archives: true}).sample.keys
|
|
83
|
+
expect(incident_keys).to include('audits')
|
|
84
|
+
end
|
|
85
|
+
it 'finds audit archives for options: {audit_archives: true, layout: "long"}' do
|
|
86
|
+
full_incident_keys = @controller.incidents(options: {audit_archives: true}).sample.keys
|
|
77
87
|
basic_incident_keys = @controller.incidents.sample.keys
|
|
78
|
-
full_incident_keys = @controller.incidents(options: {layout: 'long'}).sample.keys
|
|
79
88
|
expect(basic_incident_keys.size).to be < full_incident_keys.size
|
|
89
|
+
expect(full_incident_keys).to include('audits')
|
|
80
90
|
end
|
|
81
91
|
end
|
|
82
92
|
end
|
|
83
|
-
end
|
|
93
|
+
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: 1.8.
|
|
4
|
+
version: 1.8.8
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Chris Walls
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2018-01-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: httparty
|