samanage 1.7.4 → 1.7.5

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: 3f1d8d58d2635821d87dfa526d8516973be2151d
4
- data.tar.gz: 0377f011822eff410a4011a8219c83aac5e4ba1f
3
+ metadata.gz: 830811e5f34c766e6daf4366e1367a5d1a25bb2e
4
+ data.tar.gz: 0d0d2823495fefb862cde5acc354a44f733491e0
5
5
  SHA512:
6
- metadata.gz: 324b41e8934a09c5b37736d50d3954397fe136b1752c7c7f8afbed73d2b9aee72ada034c1ca9b1eb000cbf3d8e66b51bd6eaf0eb08f4d3db375fe63b56d7a138
7
- data.tar.gz: 354e201555b3d61efd7dd9ee4a45d2a8e8729b94fb690b3bc76d8c004c2b84d38163a69c87cf43b56cc17fa57ec3289eb71dcfc49626ae2433500bbf2d06b935
6
+ metadata.gz: 431ad262a4afbf8423f0f5f6250e6090b1f60c1f959374e5a1356bcb58932c2d49242fb97cb8c0fbd95eac78280a905369de93ae39a88389c365abeb18669a3e
7
+ data.tar.gz: 913374957d83cebed467421d8d488f1375a347943e92c72cc6a663a9ede29fbb627e8a513723d9534af2a4139ad9351e09c64c8d2909660d8f978411ee39f84c
data/changelog.md CHANGED
@@ -1,5 +1,5 @@
1
- #2.0.0
2
- - Refactoring collection methods (Samanage::Api.collect_users => Samanage::Api.users)
1
+ #1.7.5
2
+ - Adding site, department, group creation
3
3
 
4
4
  #1.7.4
5
5
  - Solving admin listing issue
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
@@ -29,6 +29,12 @@ module Samanage
29
29
  url += 'custom_forms'
30
30
  when /mobile/
31
31
  url += 'mobiles'
32
+ when /site/
33
+ url += 'sites'
34
+ when /department/
35
+ url += 'departments'
36
+ when /group/
37
+ url += 'groups'
32
38
  end
33
39
 
34
40
  if path.match(/(\d)+/)
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'
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
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-05 00:00:00.000000000 Z
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