samanage 1.7.4 → 1.7.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/changelog.md +2 -2
- data/lib/samanage.rb +3 -0
- data/lib/samanage/api.rb +3 -0
- data/lib/samanage/api/departments.rb +23 -0
- data/lib/samanage/api/groups.rb +30 -0
- data/lib/samanage/api/sites.rb +23 -0
- data/lib/samanage/url_builder.rb +6 -0
- data/samanage.gemspec +1 -1
- data/spec/api/samanage_department_spec.rb +38 -0
- data/spec/api/samanage_group_spec.rb +45 -0
- data/spec/api/samanage_site_spec.rb +40 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 830811e5f34c766e6daf4366e1367a5d1a25bb2e
|
4
|
+
data.tar.gz: 0d0d2823495fefb862cde5acc354a44f733491e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 431ad262a4afbf8423f0f5f6250e6090b1f60c1f959374e5a1356bcb58932c2d49242fb97cb8c0fbd95eac78280a905369de93ae39a88389c365abeb18669a3e
|
7
|
+
data.tar.gz: 913374957d83cebed467421d8d488f1375a347943e92c72cc6a663a9ede29fbb627e8a513723d9534af2a4139ad9351e09c64c8d2909660d8f978411ee39f84c
|
data/changelog.md
CHANGED
data/lib/samanage.rb
CHANGED
@@ -11,6 +11,9 @@ require 'samanage/api/incidents'
|
|
11
11
|
require 'samanage/api/comments'
|
12
12
|
require 'samanage/api/custom_fields'
|
13
13
|
require 'samanage/api/custom_forms'
|
14
|
+
require 'samanage/api/groups'
|
15
|
+
require 'samanage/api/sites'
|
16
|
+
require 'samanage/api/departments'
|
14
17
|
require 'samanage/error'
|
15
18
|
require 'samanage/url_builder'
|
16
19
|
module Samanage
|
data/lib/samanage/api.rb
CHANGED
@@ -12,6 +12,9 @@ module Samanage
|
|
12
12
|
mobile: 'mobiles.json',
|
13
13
|
custom_fields: 'custom_fields.json',
|
14
14
|
custom_forms: 'custom_forms.json',
|
15
|
+
site: 'sites.json',
|
16
|
+
department: 'departments.json',
|
17
|
+
group: 'groups.json'
|
15
18
|
}
|
16
19
|
attr_accessor :datacenter, :content_type, :base_url, :token, :custom_forms, :authorized, :admins
|
17
20
|
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Samanage
|
2
|
+
class Api
|
3
|
+
def get_departments(path: PATHS[:department], options: {})
|
4
|
+
url = Samanage::UrlBuilder.new(path: path, options: options).url
|
5
|
+
self.execute(path: url)
|
6
|
+
end
|
7
|
+
|
8
|
+
def collect_departments
|
9
|
+
page = 1
|
10
|
+
departments = Array.new
|
11
|
+
total_pages = self.get_departments[:total_pages]
|
12
|
+
while page <= total_pages
|
13
|
+
departments += self.execute(http_method: 'get', path: "departments.json?page=#{page}")[:data]
|
14
|
+
page += 1
|
15
|
+
end
|
16
|
+
departments
|
17
|
+
end
|
18
|
+
|
19
|
+
def create_department(payload: nil, options: {})
|
20
|
+
self.execute(path: PATHS[:department], http_method: 'post', payload: payload)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Samanage
|
2
|
+
class Api
|
3
|
+
|
4
|
+
def get_groups(path: PATHS[:group], options: {})
|
5
|
+
url = Samanage::UrlBuilder.new(path: path, options: options).url
|
6
|
+
self.execute(path: url)
|
7
|
+
end
|
8
|
+
|
9
|
+
def collect_groups
|
10
|
+
page = 1
|
11
|
+
groups = Array.new
|
12
|
+
total_pages = self.get_groups[:total_pages]
|
13
|
+
while page <= total_pages
|
14
|
+
groups += self.execute(http_method: 'get', path: "groups.json?page=#{page}")[:data]
|
15
|
+
page += 1
|
16
|
+
end
|
17
|
+
groups
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_group(payload: nil, options: {})
|
21
|
+
self.execute(path: PATHS[:group], http_method: 'post', payload: payload)
|
22
|
+
end
|
23
|
+
|
24
|
+
def add_member_to_group(email: nil, group_id: nil)
|
25
|
+
user_id = self.find_user_id_by_email(email: email)
|
26
|
+
member_path = "memberships.json?group_id=#{group_id}.json&user_ids=#{user_id}"
|
27
|
+
self.execute(path: member_path, http_method: 'post')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Samanage
|
2
|
+
class Api
|
3
|
+
def get_sites(path: PATHS[:site], options: {})
|
4
|
+
url = Samanage::UrlBuilder.new(path: path, options: options).url
|
5
|
+
self.execute(path: url)
|
6
|
+
end
|
7
|
+
|
8
|
+
def collect_sites
|
9
|
+
page = 1
|
10
|
+
sites = Array.new
|
11
|
+
total_pages = self.get_sites[:total_pages]
|
12
|
+
while page <= total_pages
|
13
|
+
sites += self.execute(http_method: 'get', path: "sites.json?page=#{page}")[:data]
|
14
|
+
page += 1
|
15
|
+
end
|
16
|
+
sites
|
17
|
+
end
|
18
|
+
|
19
|
+
def create_site(payload: nil, options: {})
|
20
|
+
self.execute(path: PATHS[:site], http_method: 'post', payload: payload)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/samanage/url_builder.rb
CHANGED
data/samanage.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
$:.push File.expand_path("../lib", __FILE__)
|
2
2
|
Gem::Specification.new do |s|
|
3
3
|
s.name = 'samanage'
|
4
|
-
s.version = '1.7.
|
4
|
+
s.version = '1.7.5'
|
5
5
|
s.date = Date.today.strftime("%Y-%m-%d")
|
6
6
|
s.summary = "Samanage Ruby Gem"
|
7
7
|
s.description = "Connect to Samanage using Ruby!"
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'samanage'
|
2
|
+
describe Samanage::Api do
|
3
|
+
context 'department' do
|
4
|
+
before(:each) do
|
5
|
+
TOKEN ||= ENV['SAMANAGE_TEST_API_TOKEN']
|
6
|
+
@controller = Samanage::Api.new(token: TOKEN)
|
7
|
+
end
|
8
|
+
it 'get_users: it returns API call of users' do
|
9
|
+
api_call = @controller.get_departments
|
10
|
+
expect(api_call).to be_a(Hash)
|
11
|
+
expect(api_call[:total_count]).to be_an(Integer)
|
12
|
+
expect(api_call).to have_key(:response)
|
13
|
+
expect(api_call).to have_key(:code)
|
14
|
+
end
|
15
|
+
it 'collects all departments' do
|
16
|
+
departments = @controller.collect_departments
|
17
|
+
department_count = @controller.get_departments[:total_count]
|
18
|
+
expect(departments).to be_an(Array)
|
19
|
+
expect(departments.size).to eq(department_count)
|
20
|
+
end
|
21
|
+
it 'creates a department' do
|
22
|
+
department_name = "department ##{(rand*10**4).ceil}"
|
23
|
+
department_location = "Location #{(rand*10**4).ceil}"
|
24
|
+
department_description = "Location #{(rand*10**4).ceil}"
|
25
|
+
payload = {
|
26
|
+
department: {
|
27
|
+
name: department_name,
|
28
|
+
description: department_description
|
29
|
+
}
|
30
|
+
}
|
31
|
+
department_create = @controller.create_department(payload: payload)
|
32
|
+
|
33
|
+
expect(department_create[:data]['id']).to be_an(Integer)
|
34
|
+
expect(department_create[:data]['name']).to eq(department_name)
|
35
|
+
expect(department_create[:code]).to eq(201).or(200)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'samanage'
|
2
|
+
|
3
|
+
describe Samanage::Api do
|
4
|
+
context 'group' do
|
5
|
+
before(:each) do
|
6
|
+
TOKEN ||= ENV['SAMANAGE_TEST_API_TOKEN']
|
7
|
+
@controller = Samanage::Api.new(token: TOKEN)
|
8
|
+
end
|
9
|
+
it 'get_users: it returns API call of users' do
|
10
|
+
api_call = @controller.get_groups
|
11
|
+
expect(api_call).to be_a(Hash)
|
12
|
+
expect(api_call[:total_count]).to be_an(Integer)
|
13
|
+
expect(api_call).to have_key(:response)
|
14
|
+
expect(api_call).to have_key(:code)
|
15
|
+
end
|
16
|
+
it 'collects all groups' do
|
17
|
+
groups = @controller.collect_groups
|
18
|
+
group_count = @controller.get_groups[:total_count]
|
19
|
+
expect(groups).to be_an(Array)
|
20
|
+
expect(groups.size).to eq(group_count)
|
21
|
+
end
|
22
|
+
it 'creates a group' do
|
23
|
+
group_name = "Group Name ##{(rand*10**4).ceil}"
|
24
|
+
group_description = "Description #{(rand*10**4).ceil}"
|
25
|
+
payload = {
|
26
|
+
group: {
|
27
|
+
name: group_name,
|
28
|
+
description: group_description
|
29
|
+
}
|
30
|
+
}
|
31
|
+
group_create = @controller.create_group(payload: payload)
|
32
|
+
|
33
|
+
expect(group_create[:data]['id']).to be_an(Integer)
|
34
|
+
expect(group_create[:data]['name']).to eq(group_name)
|
35
|
+
expect(group_create[:code]).to eq(200).or(201)
|
36
|
+
end
|
37
|
+
it 'adds member to group' do
|
38
|
+
random_group_id = @controller.collect_groups.sample['id']
|
39
|
+
random_user_email = @controller.collect_users.sample['email']
|
40
|
+
|
41
|
+
add_user_to_group = @controller.add_member_to_group(email: random_user_email, group_id: random_group_id)
|
42
|
+
expect(add_user_to_group[:code]).to eq(200).or(201)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'samanage'
|
2
|
+
describe Samanage::Api do
|
3
|
+
context 'Site' do
|
4
|
+
before(:each) do
|
5
|
+
TOKEN ||= ENV['SAMANAGE_TEST_API_TOKEN']
|
6
|
+
@controller = Samanage::Api.new(token: TOKEN)
|
7
|
+
end
|
8
|
+
it 'get_users: it returns API call of users' do
|
9
|
+
api_call = @controller.get_sites
|
10
|
+
expect(api_call).to be_a(Hash)
|
11
|
+
expect(api_call[:total_count]).to be_an(Integer)
|
12
|
+
expect(api_call).to have_key(:response)
|
13
|
+
expect(api_call).to have_key(:code)
|
14
|
+
end
|
15
|
+
it 'collects all sites' do
|
16
|
+
sites = @controller.collect_sites
|
17
|
+
site_count = @controller.get_sites[:total_count]
|
18
|
+
expect(sites).to be_an(Array)
|
19
|
+
expect(sites.size).to eq(site_count)
|
20
|
+
end
|
21
|
+
it 'creates a site' do
|
22
|
+
site_name = "Site ##{(rand*10**4).ceil}"
|
23
|
+
site_location = "Location #{(rand*10**4).ceil}"
|
24
|
+
site_description = "Descrption #{(rand*10**4).ceil}"
|
25
|
+
payload = {
|
26
|
+
site: {
|
27
|
+
name: site_name,
|
28
|
+
location: site_location,
|
29
|
+
description: site_description
|
30
|
+
}
|
31
|
+
}
|
32
|
+
puts "Payload: #{payload.inspect}"
|
33
|
+
site_create = @controller.create_site(payload: payload)
|
34
|
+
|
35
|
+
expect(site_create[:data]['id']).to be_an(Integer)
|
36
|
+
expect(site_create[:data]['name']).to eq(site_name)
|
37
|
+
expect(site_create[:code]).to eq(201).or(200)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
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.7.
|
4
|
+
version: 1.7.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Walls
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-12-
|
11
|
+
date: 2017-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -57,11 +57,14 @@ files:
|
|
57
57
|
- lib/samanage/api/comments.rb
|
58
58
|
- lib/samanage/api/custom_fields.rb
|
59
59
|
- lib/samanage/api/custom_forms.rb
|
60
|
+
- lib/samanage/api/departments.rb
|
61
|
+
- lib/samanage/api/groups.rb
|
60
62
|
- lib/samanage/api/hardwares.rb
|
61
63
|
- lib/samanage/api/incidents.rb
|
62
64
|
- lib/samanage/api/mobiles.rb
|
63
65
|
- lib/samanage/api/other_assets.rb
|
64
66
|
- lib/samanage/api/requester.rb
|
67
|
+
- lib/samanage/api/sites.rb
|
65
68
|
- lib/samanage/api/users.rb
|
66
69
|
- lib/samanage/error.rb
|
67
70
|
- lib/samanage/url_builder.rb
|
@@ -69,10 +72,13 @@ files:
|
|
69
72
|
- spec/api/comments_spec.rb
|
70
73
|
- spec/api/samanage_custom_field_spec.rb
|
71
74
|
- spec/api/samanage_custom_form_spec.rb
|
75
|
+
- spec/api/samanage_department_spec.rb
|
76
|
+
- spec/api/samanage_group_spec.rb
|
72
77
|
- spec/api/samanage_hardware_spec.rb
|
73
78
|
- spec/api/samanage_incident_spec.rb
|
74
79
|
- spec/api/samanage_mobile_spec.rb
|
75
80
|
- spec/api/samanage_other_asset_spec.rb
|
81
|
+
- spec/api/samanage_site_spec.rb
|
76
82
|
- spec/api/samanage_user_spec.rb
|
77
83
|
- spec/samanage_api_spec.rb
|
78
84
|
- spec/samanage_url_builder_spec.rb
|