samanage 2.1.09 → 2.1.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/changelog.md +4 -0
- data/lib/samanage/api.rb +4 -2
- data/lib/samanage/api/attachments.rb +4 -3
- data/lib/samanage/version.rb +1 -1
- data/spec/api/samanage_attachment_spec.rb +35 -35
- 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: 439421b219ee958f5a42756436880b91c47e2132
|
4
|
+
data.tar.gz: 91cb5850c80ecbd66f10940d72764dcecb0f8b9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3ce720d571f2623e31255828e2e8e9432cb586ae287a06e5ef8e23ccbf80ac3485b6d88474ed7eb35a3bd3d8cc1a15b2c72c2df728f7becb07523124495bbdf
|
7
|
+
data.tar.gz: 163f88a491b6e918f7732af08e63c7c8273d35e09b62ef77083f4de4a1d81cf7052c96fc122a89d062c487e626eac2f1ef6b77c21ac52904ba358a2b3f991bd3
|
data/changelog.md
CHANGED
data/lib/samanage/api.rb
CHANGED
@@ -58,7 +58,9 @@ module Samanage
|
|
58
58
|
def execute(http_method: 'get', path: nil, payload: nil, verbose: nil, headers: {})
|
59
59
|
if payload.class == Hash && self.content_type == 'json'
|
60
60
|
begin
|
61
|
-
|
61
|
+
if path != 'attachments.json'
|
62
|
+
payload = payload.to_json
|
63
|
+
end
|
62
64
|
rescue => e
|
63
65
|
puts "Invalid JSON: #{payload.inspect}"
|
64
66
|
raise Samanage::Error.new(error: e, response: nil)
|
@@ -93,7 +95,7 @@ module Samanage
|
|
93
95
|
else
|
94
96
|
raise Samanage::Error.new(response: {response: 'Unknown HTTP method'})
|
95
97
|
end
|
96
|
-
rescue Errno::ECONNREFUSED, Net::OpenTimeout, Errno::ETIMEDOUT, OpenSSL::SSL::SSLError, Errno::ENETDOWN, Errno::ECONNRESET, Errno::ENOENT, EOFError, Net::HTTPTooManyRequests => e
|
98
|
+
rescue Errno::ECONNREFUSED, Net::OpenTimeout, Errno::ETIMEDOUT, OpenSSL::SSL::SSLError, Errno::ENETDOWN, Errno::ECONNRESET, Errno::ENOENT, EOFError, Net::HTTPTooManyRequests, SocketError => e
|
97
99
|
puts "[Warning] #{e.class}: #{e} - Retry: #{retries}/#{self.max_retries}"
|
98
100
|
sleep 5
|
99
101
|
retries += 1
|
@@ -23,9 +23,10 @@ module Samanage
|
|
23
23
|
puts "Cannot find filepath: '#{filepath.inspect}'"
|
24
24
|
return
|
25
25
|
end
|
26
|
-
self.
|
27
|
-
|
28
|
-
|
26
|
+
self.execute(
|
27
|
+
path: 'attachments.json',
|
28
|
+
http_method: 'post',
|
29
|
+
payload: {
|
29
30
|
'file[attachable_type]' => attachable_type,
|
30
31
|
'file[attachable_id]' => attachable_id,
|
31
32
|
'file[attachment]' => File.open(filepath, 'r')
|
data/lib/samanage/version.rb
CHANGED
@@ -3,41 +3,41 @@ require 'samanage'
|
|
3
3
|
describe Samanage::Api do
|
4
4
|
context 'Attachments' do
|
5
5
|
describe 'API Functions' do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
before(:all) do
|
7
|
+
TOKEN ||= ENV['SAMANAGE_TEST_API_TOKEN']
|
8
|
+
@samanage = Samanage::Api.new(token: TOKEN)
|
9
|
+
@users = @samanage.get_users[:data]
|
10
|
+
@incidents = @samanage.incidents
|
11
|
+
end
|
12
|
+
it 'uploads an attachment' do
|
13
|
+
filename = 'sample_file.txt'
|
14
|
+
filepath = File.join(Dir.pwd, filename)
|
15
|
+
incident_id = @incidents.sample.dig('id')
|
16
|
+
attach = @samanage.create_attachment(
|
17
|
+
filepath: filepath,
|
18
|
+
attachable_id: incident_id,
|
19
|
+
attachable_type: 'Incident'
|
20
|
+
)
|
21
|
+
expect(attach[:code]).to eq(200).or(201)
|
22
|
+
expect(filename).to eq(attach[:data]['filename'])
|
23
|
+
expect(File.open(filepath).size).to eq(attach[:data]['size'])
|
24
|
+
end
|
25
|
+
it 'downloads an attachment' do
|
26
|
+
incident_id = @incidents.sample.dig('id')
|
27
|
+
filename = 'sample_file.txt'
|
28
|
+
filepath = File.join(Dir.pwd, filename)
|
29
|
+
attach = @samanage.create_attachment(
|
30
|
+
filepath: filepath,
|
31
|
+
attachable_id: incident_id,
|
32
|
+
attachable_type: 'Incident'
|
33
|
+
)
|
34
|
+
expect(attach[:code]).to eq(200).or(201)
|
35
|
+
attachable_incident_id = incident_id # Need filter for has attachment?
|
36
|
+
incident = @samanage.find_incident(id: attachable_incident_id, options: {layout: 'long'})
|
37
|
+
attachment = @samanage.download_attachment(attachment: incident[:data]['attachments'].first)
|
38
|
+
expect(attachment.class).to be(File)
|
39
|
+
expect(attachment.path.split('/').last).to eq(filename)
|
40
|
+
end
|
11
41
|
end
|
12
|
-
# it 'uploads an attachment' do
|
13
|
-
# filename = 'sample_file.txt'
|
14
|
-
# attachment = File.open(filename)
|
15
|
-
# incident_id = @incidents.sample.dig('id')
|
16
|
-
# attach = @samanage.upload_attachment(
|
17
|
-
# attachment: attachment,
|
18
|
-
# attachable_id: incident_id,
|
19
|
-
# attachable_type: 'Incident'
|
20
|
-
# )
|
21
|
-
# expect(attach[:code]).to eq(200).or(201)
|
22
|
-
# expect(filename).to eq(attach[:data]['filename'])
|
23
|
-
# expect(attachment.size).to eq(attach[:data]['size'])
|
24
|
-
# end
|
25
|
-
# it 'downloads an attachment' do
|
26
|
-
# incident_id = @incidents.sample.dig('id')
|
27
|
-
# filename = 'sample_file.txt'
|
28
|
-
# attachment = File.open(filename)
|
29
|
-
# attach = @samanage.upload_attachment(
|
30
|
-
# attachment: attachment,
|
31
|
-
# attachable_id: incident_id,
|
32
|
-
# attachable_type: 'Incident'
|
33
|
-
# )
|
34
|
-
# attachable_incident_id = incident_id # Need filter for has attachment?
|
35
|
-
# incident = @samanage.find_incident(id: attachable_incident_id, options: {layout: 'long'})
|
36
|
-
# attachment = @samanage.download_attachment(attachment: incident[:data]['attachments'].first)
|
37
|
-
# expect(attachment.class).to be(File)
|
38
|
-
# expect(attach[:code]).to eq(200)
|
39
|
-
# expect(attachment.path.split('/').last).to eq(filename)
|
40
|
-
# end
|
41
|
-
end
|
42
42
|
end
|
43
43
|
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.10
|
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-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|