samanage 1.9.31 → 1.9.32

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bd9c36e5b7dcfa8533463d1efaaf094aaca7c142
4
- data.tar.gz: 2d262cf6d6080c799332dbd2121e744b54c829dd
3
+ metadata.gz: 5352f9f97dd2e91219b8de06c37ff87ef8000d52
4
+ data.tar.gz: 82c4b86815ce77da711c3c136d60d04a5e8f7e43
5
5
  SHA512:
6
- metadata.gz: d04babd705aea3f93c6bbbaf08c61c1adde2dee78748025996a4d0ad236bc5b6111bb7cb98289ce2798f187d03151ad95dded037a5c5b6ade657904f3acaf32b
7
- data.tar.gz: 0a398b707e8dd4629f6d81ce06eb59523a1f94a68882ecf06d5cd517dd06bb683d467b63d78aa7a1f285f15289361d6279c31ec43d70e643700fd763d6a2c630
6
+ metadata.gz: 3f4d0176ff08ad9905ca27f90470c18c11357a8193501041bb4ee4ce80e33daf9eb49297b900269cd8b4e0d5997b7e68fe56392b64f42adef2de5bada0e7f98d
7
+ data.tar.gz: a89980454bba19c7ea6312e48bb26d31c230c8e53fa72c7845db032237904bdac594217dbdca3d045980c07621e58a8544f87671102ee4648cb7301fa89a8b4a
data/changelog.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 1.9.32
2
+ - Adding layout long for single incident
3
+ - Adding attachment downloads
4
+
1
5
  # 1.9.31
2
6
  - Alias original comment method
3
7
  - Remove (keyword: nil)
data/lib/samanage/api.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'open-uri'
1
2
  module Samanage
2
3
  class Api
3
4
  include HTTParty
@@ -40,8 +40,11 @@ module Samanage
40
40
  end
41
41
 
42
42
  # Find incident by ID
43
- def find_incident(id: )
43
+ def find_incident(id: , options: {})
44
44
  path = "incidents/#{id}.json"
45
+ if options[:layout] == 'long'
46
+ path += '?layout=long'
47
+ end
45
48
  self.execute(path: path)
46
49
  end
47
50
 
@@ -1,3 +1,5 @@
1
+ require 'open-uri'
2
+ require 'fileutils'
1
3
  module Samanage
2
4
  class Api
3
5
  def send_activation_email(email: )
@@ -5,5 +7,24 @@ module Samanage
5
7
  raise Samanage::Error.new(error: 'Invalid Email', response: {}) unless user_id
6
8
  self.execute(http_method: 'put', path: "users/#{user_id}.json?send_activation_email=1&add_callbacks=1")
7
9
  end
10
+
11
+ # Downloads a Samanage Attachment object can overwrite default filename and path (Object/ObjectID/Original_Filename)
12
+ def download_attachment(attachment: {}, filename: nil, path: nil)
13
+ attachable_type = attachment['attachable_type']
14
+ attachable_id = attachment['attachable_id'].to_s
15
+ filename = filename || attachment['filename']
16
+ url = attachment['url']
17
+
18
+ file_path = path ? path : File.join(Dir.pwd,attachable_type,attachable_id)
19
+ unless File.directory?(file_path)
20
+ FileUtils.mkpath(file_path)
21
+ end
22
+
23
+ exact_path = File.join(file_path,filename)
24
+ downloaded_attachment = open(exact_path, "wb+") do |file|
25
+ file << open(url).read
26
+ end
27
+ downloaded_attachment
28
+ end
8
29
  end
9
30
  end
@@ -1,3 +1,3 @@
1
1
  module Samanage
2
- VERSION = '1.9.31'
2
+ VERSION = '1.9.32'
3
3
  end
@@ -57,6 +57,15 @@ describe Samanage::Api do
57
57
  expect(incident[:data]).to have_key('requester')
58
58
  expect(incident[:data]).to have_key('id')
59
59
  end
60
+ it 'find_incident: returns more keys with layout=long' do
61
+ sample_id = @incidents.sample['id']
62
+ layout_regular_incident = @samanage.find_incident(id: sample_id)
63
+ layout_long_incident = @samanage.find_incident(id: sample_id, options: {layout: 'long'})
64
+
65
+ expect(layout_long_incident[:data]['id']).to eq(sample_id) # id should match found incident
66
+ expect(layout_long_incident[:data].keys.size).to be > (layout_regular_incident.keys.size)
67
+ expect(layout_long_incident[:data].keys - layout_regular_incident[:data].keys).to_not be([])
68
+ end
60
69
  it 'find_incident: returns nothing for an invalid id' do
61
70
  sample_id = (0..10).entries.sample
62
71
  expect{@samanage.find_incident(id: sample_id)}.to raise_error(Samanage::NotFound) # id should match found incident
@@ -16,6 +16,12 @@ describe Samanage::Api do
16
16
  invalid_email = @samanage.users.sample['email'].gsub!('@','$')
17
17
  expect{@samanage.send_activation_email(email: invalid_email)}.to raise_error(Samanage::Error)
18
18
  end
19
+ it 'downloads an attachment' do
20
+ attachable_incident_id = 22215549 # Need filter for has attachment?
21
+ incident = @samanage.find_incident(id: attachable_incident_id, options: {layout: 'long'})
22
+ attachment = @samanage.download_attachment(attachment: incident[:data]['attachments'].first)
23
+ expect(attachment.class).to be(File)
24
+ end
19
25
  end
20
26
  end
21
27
  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.9.31
4
+ version: 1.9.32
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-31 00:00:00.000000000 Z
11
+ date: 2018-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty