samanage 2.1.11 → 2.1.12
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.rb +1 -0
- data/lib/samanage/api.rb +2 -0
- data/lib/samanage/api/attachments.rb +4 -2
- data/lib/samanage/api/vendors.rb +41 -0
- data/lib/samanage/version.rb +1 -1
- data/spec/api/samanage_vendors_spec.rb +47 -0
- 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: 1ec372d3885f312e767a2ed4f28fb7642fda6f3e
|
4
|
+
data.tar.gz: 716ebc7f35ce2e54d567b64c20845c2c66d3a41c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bed2128b2c832f60cb4e66513ed33e39a79e3ebb22d840b4b7da8e6d0365d147dc7ba116806143e8b1181f2eb93528c16b919b7e16838f14a057cf5fc067584d
|
7
|
+
data.tar.gz: dcb13662ecdd823d296c1070bb1cb3f1c82a03e3d684176ad298879497fa491046fa50db46ee919da3331c7a3b2e9c154757860ad97dcbfc41eb937b26b50c1e
|
data/changelog.md
CHANGED
data/lib/samanage.rb
CHANGED
data/lib/samanage/api.rb
CHANGED
@@ -6,6 +6,7 @@ module Samanage
|
|
6
6
|
attr_accessor :datacenter, :content_type, :base_url, :token, :custom_forms, :authorized, :admins, :max_retries
|
7
7
|
MAX_RETRIES = 3
|
8
8
|
PATHS = {
|
9
|
+
attachment: 'attachments.json',
|
9
10
|
category: 'categories.json',
|
10
11
|
change: 'changes.json',
|
11
12
|
contract: 'contracts.json',
|
@@ -22,6 +23,7 @@ module Samanage
|
|
22
23
|
site: 'sites.json',
|
23
24
|
solution: 'solutions.json',
|
24
25
|
user: 'users.json',
|
26
|
+
vendor: 'vendors.json',
|
25
27
|
}
|
26
28
|
# Development mode forces authorization & pre-populates admins and custom forms / fields
|
27
29
|
# datacenter should equal 'eu' or blank
|
@@ -23,19 +23,21 @@ module Samanage
|
|
23
23
|
puts "Cannot find filepath: '#{filepath.inspect}'"
|
24
24
|
return
|
25
25
|
end
|
26
|
-
self.execute(
|
26
|
+
req = self.execute(
|
27
27
|
path: 'attachments.json',
|
28
28
|
http_method: 'post',
|
29
29
|
payload: {
|
30
30
|
'file[attachable_type]' => attachable_type,
|
31
31
|
'file[attachable_id]' => attachable_id,
|
32
|
-
'file[attachment]' => File.open(filepath, 'r')
|
32
|
+
'file[attachment]' => file = File.open(filepath, 'r')
|
33
33
|
},
|
34
34
|
headers: {
|
35
35
|
'Content-Type' => 'multipart/form-data',
|
36
36
|
'X-Samanage-Authorization' => 'Bearer ' + self.token
|
37
37
|
}
|
38
38
|
)
|
39
|
+
file.close
|
40
|
+
req
|
39
41
|
end
|
40
42
|
|
41
43
|
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Samanage
|
2
|
+
class Api
|
3
|
+
def get_vendors(path: PATHS[:vendor], options: {})
|
4
|
+
params = self.set_params(options: options)
|
5
|
+
path = 'vendors.json?' + params
|
6
|
+
self.execute(path: path)
|
7
|
+
end
|
8
|
+
|
9
|
+
def collect_vendors(options: {})
|
10
|
+
vendors = Array.new
|
11
|
+
total_pages = self.get_vendors(options: options)[:total_pages]
|
12
|
+
1.upto(total_pages) do |page|
|
13
|
+
options[:page] = page
|
14
|
+
params = self.set_params(options: options)
|
15
|
+
puts "Collecting vendors page: #{page}/#{total_pages}" if options[:verbose]
|
16
|
+
path = "vendors.json?" + params
|
17
|
+
self.execute(http_method: 'get', path: path)[:data].each do |vendor|
|
18
|
+
if block_given?
|
19
|
+
yield vendor
|
20
|
+
end
|
21
|
+
vendors << vendor
|
22
|
+
end
|
23
|
+
end
|
24
|
+
vendors
|
25
|
+
end
|
26
|
+
|
27
|
+
def create_vendor(payload: , options: {})
|
28
|
+
self.execute(path: PATHS[:vendor], http_method: 'post', payload: payload)
|
29
|
+
end
|
30
|
+
|
31
|
+
def update_vendor(id: ,payload: , options: {})
|
32
|
+
self.execute(path: "vendors/#{id}.json", http_method: 'put', payload: payload)
|
33
|
+
end
|
34
|
+
|
35
|
+
def delete_vendor(id: )
|
36
|
+
self.execute(path: "vendors/#{id}.json", http_method: 'delete')
|
37
|
+
end
|
38
|
+
|
39
|
+
alias_method :vendors, :collect_vendors
|
40
|
+
end
|
41
|
+
end
|
data/lib/samanage/version.rb
CHANGED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'samanage'
|
2
|
+
require 'faker'
|
3
|
+
describe Samanage::Api do
|
4
|
+
context 'vendor' do
|
5
|
+
before(:all) do
|
6
|
+
TOKEN ||= ENV['SAMANAGE_TEST_API_TOKEN']
|
7
|
+
@samanage = Samanage::Api.new(token: TOKEN)
|
8
|
+
@vendors = @samanage.vendors
|
9
|
+
end
|
10
|
+
it 'get_users: it returns API call of users' do
|
11
|
+
api_call = @samanage.get_vendors
|
12
|
+
expect(api_call).to be_a(Hash)
|
13
|
+
expect(api_call[:total_count]).to be_an(Integer)
|
14
|
+
expect(api_call).to have_key(:response)
|
15
|
+
expect(api_call).to have_key(:code)
|
16
|
+
end
|
17
|
+
it 'collects all vendors' do
|
18
|
+
vendors = @vendors
|
19
|
+
vendor_count = @samanage.get_vendors[:total_count]
|
20
|
+
expect(vendors).to be_an(Array)
|
21
|
+
expect(vendors.size).to eq(vendor_count)
|
22
|
+
end
|
23
|
+
it 'creates a vendor' do
|
24
|
+
vendor_name = Faker::Music.album
|
25
|
+
payload = {
|
26
|
+
vendor: {
|
27
|
+
name: vendor_name,
|
28
|
+
vendor_type: {name: 'SaaS Vendor'}
|
29
|
+
}
|
30
|
+
}
|
31
|
+
vendor_create = @samanage.create_vendor(payload: payload)
|
32
|
+
|
33
|
+
expect(vendor_create[:data]['id']).to be_an(Integer)
|
34
|
+
expect(vendor_create[:data]['name']).to eq(vendor_name)
|
35
|
+
expect(vendor_create[:code]).to eq(200)
|
36
|
+
end
|
37
|
+
it 'updates a valid vendor' do
|
38
|
+
sample_vendor_id = @vendors.sample['id']
|
39
|
+
new_name = Faker::Movie.quote
|
40
|
+
payload = {vendor: {name: new_name}}
|
41
|
+
vendor_update = @samanage.update_vendor(id: sample_vendor_id, payload: payload)
|
42
|
+
|
43
|
+
expect(new_name).to eq(vendor_update.dig(:data,'name'))
|
44
|
+
expect(vendor_update[:code]).to eq(200)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
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.12
|
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-04-
|
11
|
+
date: 2019-04-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -74,6 +74,7 @@ files:
|
|
74
74
|
- lib/samanage/api/time_tracks.rb
|
75
75
|
- lib/samanage/api/users.rb
|
76
76
|
- lib/samanage/api/utils.rb
|
77
|
+
- lib/samanage/api/vendors.rb
|
77
78
|
- lib/samanage/error.rb
|
78
79
|
- lib/samanage/language.rb
|
79
80
|
- lib/samanage/url_builder.rb
|
@@ -101,6 +102,7 @@ files:
|
|
101
102
|
- spec/api/samanage_time_tracks_spec.rb
|
102
103
|
- spec/api/samanage_user_spec.rb
|
103
104
|
- spec/api/samanage_util_spec.rb
|
105
|
+
- spec/api/samanage_vendors_spec.rb
|
104
106
|
- spec/samanage_api_spec.rb
|
105
107
|
- spec/samanage_category_spec.rb
|
106
108
|
- spec/samanage_language_spec.rb
|