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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1b27ba531435e04046290dc044b89fc0e2f51125
4
- data.tar.gz: 203d7b74e6757cc0e8e97344e0e79b7fc97851de
3
+ metadata.gz: 439421b219ee958f5a42756436880b91c47e2132
4
+ data.tar.gz: 91cb5850c80ecbd66f10940d72764dcecb0f8b9f
5
5
  SHA512:
6
- metadata.gz: e44d497c9ff424afe653e29344904dae7290cec74af9c6f3695c00ae376db34136b47f179f83ad9025f46c35e82a31e342deee7a9216640618627fef1112da3b
7
- data.tar.gz: 63f2235a968316f2c4617401c15f5e7fef12cf3e463c00621a7baa8e3d2c9d13b37ba89d4331ed4f3daa8853c4154c18e5164ff696c590d80ca6a4995e331a69
6
+ metadata.gz: c3ce720d571f2623e31255828e2e8e9432cb586ae287a06e5ef8e23ccbf80ac3485b6d88474ed7eb35a3bd3d8cc1a15b2c72c2df728f7becb07523124495bbdf
7
+ data.tar.gz: 163f88a491b6e918f7732af08e63c7c8273d35e09b62ef77083f4de4a1d81cf7052c96fc122a89d062c487e626eac2f1ef6b77c21ac52904ba358a2b3f991bd3
data/changelog.md CHANGED
@@ -1,3 +1,7 @@
1
+ ### 2.1.10
2
+ - Attachments for Windows
3
+ - Handle Socket Errors
4
+
1
5
  ### 2.1.09
2
6
  - Updated HTTParty to 0.16.4
3
7
  - Optimize heavy audit+layout incident collection
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
- payload = payload.to_json
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.class.post(
27
- self.base_url + 'attachments.json',
28
- body: {
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')
@@ -1,3 +1,3 @@
1
1
  module Samanage
2
- VERSION = '2.1.09'
2
+ VERSION = '2.1.10'
3
3
  end
@@ -3,41 +3,41 @@ require 'samanage'
3
3
  describe Samanage::Api do
4
4
  context 'Attachments' do
5
5
  describe 'API Functions' do
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
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.09
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-03-28 00:00:00.000000000 Z
11
+ date: 2019-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty