samanage 1.4

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.
@@ -0,0 +1,16 @@
1
+ require 'samanage'
2
+
3
+ describe Samanage::Api do
4
+ context 'Custom Field' do
5
+ describe 'API Functions' do
6
+ before(:each) do
7
+ TOKEN ||= ENV['SAMANAGE_TEST_API_TOKEN']
8
+ @controller = Samanage::Api.new(token: TOKEN)
9
+ end
10
+ it 'collects all custom fields' do
11
+ api_call = @controller.collect_custom_fields
12
+ expect(api_call).to be_a(Array)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,28 @@
1
+ require 'samanage'
2
+
3
+ describe Samanage::Api do
4
+ context 'Custom Form' do
5
+ describe 'API Functions' do
6
+ before(:each) do
7
+ TOKEN ||= ENV['SAMANAGE_TEST_API_TOKEN']
8
+ @controller = Samanage::Api.new(token: TOKEN, development_mode: true)
9
+ end
10
+ it 'collects all custom forms' do
11
+ api_call = @controller.collect_custom_forms
12
+ expect(api_call).to be_a(Array)
13
+ end
14
+ it 'Organizes custom forms by module' do
15
+ api_call = @controller.organize_forms
16
+ expect(api_call).to be_a(Hash)
17
+ expect(api_call.keys).to be_an(Array)
18
+ expect(api_call[api_call.keys.sample].sample).to be_a(Hash)
19
+ end
20
+ it 'Finds the forms for an object_type' do
21
+ object_types = ['incident', 'user','other_asset','hardware','configuration_item']
22
+ form = @controller.form_for(object_type: object_types.sample)
23
+ expect(form).to be_an(Array)
24
+ expect(form.sample.keys).to include('custom_form_fields')
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,76 @@
1
+ require 'samanage'
2
+
3
+ describe Samanage::Api do
4
+ context 'Hardware' do
5
+ describe 'API Functions' do
6
+ before(:each) do
7
+ TOKEN ||= ENV['SAMANAGE_TEST_API_TOKEN']
8
+ @controller = Samanage::Api.new(token: TOKEN)
9
+ end
10
+ it 'get_hardwares: it returns API call of hardwares' do
11
+ api_call = @controller.get_hardwares
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 'collect_hardwares: collects array of hardwares' do
18
+ hardwares = @controller.collect_hardwares
19
+ hardware_count = @controller.get_hardwares[:total_count]
20
+ expect(hardwares).to be_an(Array)
21
+ expect(hardwares.size).to eq(hardware_count)
22
+ end
23
+ it 'create_hardware(payload: json): creates a hardware' do
24
+ hardware_name = "samanage-ruby-#{(rand*10**10).ceil}"
25
+ serial_number = (0...50).map { ('a'..'z').to_a[rand(26)] }.join
26
+ json = {
27
+ :hardware => {
28
+ :name => hardware_name,
29
+ :bio => {:ssn => serial_number},
30
+ }
31
+ }
32
+ hardware_create = @controller.create_hardware(payload: json.to_json)
33
+
34
+ expect(hardware_create[:data]['id']).to be_an(Integer)
35
+ expect(hardware_create[:data]['name']).to eq(hardware_name)
36
+ expect(hardware_create[:code]).to eq(201).or(200)
37
+ end
38
+ it 'create_hardware: fails if no serial' do
39
+ hardware_name = "samanage-ruby-#{(rand*10**10).ceil}"
40
+ json = {
41
+ :hardware => {
42
+ :name => hardware_name,
43
+ }
44
+ }
45
+ expect{@controller.create_hardware(payload: json.to_json)}.to raise_error(Samanage::InvalidRequest)
46
+ end
47
+ it 'find_hardware: returns a hardware card by known id' do
48
+ hardwares = @controller.collect_hardwares
49
+ sample_id = hardwares.sample['id']
50
+ hardware = @controller.find_hardware(id: sample_id)
51
+
52
+ expect(hardware[:data]['id']).to eq(sample_id) # id should match found hardware
53
+ expect(hardware[:data]).to have_key('name')
54
+ expect(hardware[:data]).to have_key('serial_number')
55
+ expect(hardware[:data]).to have_key('id')
56
+ end
57
+ it 'find_hardware: returns nothing for an invalid id' do
58
+ sample_id = (0..10).entries.sample
59
+ expect{@controller.find_hardware(id: sample_id)}.to raise_error(Samanage::NotFound) # id should match found hardware
60
+ end
61
+ it 'update_hardware: update_hardware by id' do
62
+ hardwares = @controller.collect_hardwares
63
+ sample_id = hardwares.sample['id']
64
+ new_name = (0...50).map { ('a'..'z').to_a[rand(26)] }.join
65
+ json = {
66
+ :hardware => {
67
+ :name => new_name
68
+ }
69
+ }
70
+ hardware_update = @controller.update_hardware(payload: json.to_json, id: sample_id)
71
+ expect(hardware_update[:data]["name"]).to eq(new_name)
72
+ expect(hardware_update[:code]).to eq(200).or(201)
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,79 @@
1
+ require 'samanage'
2
+
3
+ describe Samanage::Api do
4
+ context 'Incidents' do
5
+ describe 'API Functions' do
6
+ before(:each) do
7
+ TOKEN ||= ENV['SAMANAGE_TEST_API_TOKEN']
8
+ @controller = Samanage::Api.new(token: TOKEN)
9
+ end
10
+ it 'get_incidents: it returns API call of incidents' do
11
+ api_call = @controller.get_incidents
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 'collect_incidents: collects array of incidents' do
18
+ incidents = @controller.collect_incidents
19
+ incident_count = @controller.get_incidents[:total_count]
20
+ expect(incidents).to be_an(Array)
21
+ expect(incidents.size).to eq(incident_count)
22
+ end
23
+ it 'create_incident(payload: json): creates a incident' do
24
+ users_email = @controller.collect_users.sample['email']
25
+ serial_number = (0...50).map { ('a'..'z').to_a[rand(26)] }.join
26
+ incident_name = "Samanage Ruby Incident"
27
+ json = {
28
+ :incident => {
29
+ :requester => {:email => users_email},
30
+ :name => incident_name,
31
+ :description => "Description"
32
+ }
33
+ }
34
+ incident_create = @controller.create_incident(payload: json.to_json)
35
+
36
+ expect(incident_create[:data]['id']).to be_an(Integer)
37
+ expect(incident_create[:data]['name']).to eq(incident_name)
38
+ expect(incident_create[:code]).to eq(200).or(201)
39
+ end
40
+ it 'create_incident: fails if no name/title' do
41
+ users_email = @controller.collect_users.sample['email']
42
+ json = {
43
+ :incident => {
44
+ :requester => {:email => users_email},
45
+ :description => "Description"
46
+ }
47
+ }
48
+ expect{@controller.create_incident(payload: json.to_json)}.to raise_error(Samanage::InvalidRequest)
49
+ end
50
+ it 'find_incident: returns a incident card by known id' do
51
+ incidents = @controller.collect_incidents
52
+ sample_id = incidents.sample['id']
53
+ incident = @controller.find_incident(id: sample_id)
54
+
55
+ expect(incident[:data]['id']).to eq(sample_id) # id should match found incident
56
+ expect(incident[:data]).to have_key('name')
57
+ expect(incident[:data]).to have_key('requester')
58
+ expect(incident[:data]).to have_key('id')
59
+ end
60
+ it 'find_incident: returns nothing for an invalid id' do
61
+ sample_id = (0..10).entries.sample
62
+ expect{@controller.find_incident(id: sample_id)}.to raise_error(Samanage::NotFound) # id should match found incident
63
+ end
64
+ it 'update_incident: update_incident by id' do
65
+ incidents = @controller.collect_incidents
66
+ sample_id = incidents.sample['id']
67
+ new_name = (0...50).map { ('a'..'z').to_a[rand(26)] }.join
68
+ json = {
69
+ :incident => {
70
+ :name => new_name
71
+ }
72
+ }
73
+ incident_update = @controller.update_incident(payload: json.to_json, id: sample_id)
74
+ expect(incident_update[:data]["name"]).to eq(new_name)
75
+ expect(incident_update[:code]).to eq(200).or(201)
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,84 @@
1
+ require 'samanage'
2
+
3
+ describe Samanage::Api do
4
+ context 'Other Assets' do
5
+ describe 'API Functions' do
6
+ before(:each) do
7
+ TOKEN ||= ENV['SAMANAGE_TEST_API_TOKEN']
8
+ @controller = Samanage::Api.new(token: TOKEN)
9
+ end
10
+ it 'get_other_assets: it returns API call of other_assets' do
11
+ api_call = @controller.get_other_assets
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 'collect_other_assets: collects array of other_assets' do
18
+ other_assets = @controller.collect_other_assets
19
+ expect(other_assets).to be_an(Array)
20
+ end
21
+ it 'create_other_asset(payload: json): creates a other_asset' do
22
+ other_asset_name = "samanage-ruby-#{(rand*10**10).ceil}"
23
+ json = {
24
+ :other_asset => {
25
+ :name => other_asset_name,
26
+ :manufacturer => 'Samanage',
27
+ :asset_type => {:name => "Asset"},
28
+ :status => {:name => "Operational"}
29
+ }
30
+ }
31
+
32
+ other_asset_create = @controller.create_other_asset(payload: json.to_json)
33
+ expect(other_asset_create[:data]['id']).to be_an(Integer)
34
+ expect(other_asset_create[:data]['name']).to eq(other_asset_name)
35
+ expect(other_asset_create[:code]).to eq(200).or(201)
36
+ end
37
+ it 'create_other_asset: fails if wrong fields' do
38
+ other_asset_name = "samanage-ruby-#{(rand*10**10).ceil}"
39
+ json = {
40
+ :other_asset => {
41
+ :name => other_asset_name,
42
+ :manufacturer => 'Samanage',
43
+ :asset_type => {:name => "Asset"},
44
+ :status => {:name => "Operational"}
45
+ }
46
+ }
47
+ json[:other_asset].delete(json[:other_asset].keys.sample) # Delete random sample from the examples above
48
+ expect{@controller.create_other_asset(payload: json.to_json)}.to raise_error(Samanage::InvalidRequest)
49
+ end
50
+
51
+ it 'find_other_asset: returns an other_asset card by known id' do
52
+ other_assets = @controller.collect_other_assets
53
+ puts "Found ##{other_assets.size} other assets"
54
+ puts ".sample ##{other_assets.sample}"
55
+ puts ".sample['id'] ##{other_assets.sample['id']}"
56
+ sample_id = other_assets.sample['id']
57
+
58
+ other_asset = @controller.find_other_asset(id: sample_id)
59
+
60
+ expect(other_asset[:data]['id']).to eq(sample_id) # id should match found other_asset
61
+ expect(other_asset[:data]).to have_key('name')
62
+ expect(other_asset[:data]).to have_key('serial_number')
63
+ expect(other_asset[:data]).to have_key('id')
64
+ end
65
+ it 'find_other_asset: returns nothing for an invalid id' do
66
+ sample_id = (0..10).entries.sample
67
+ expect{@controller.find_other_asset(id: sample_id)}.to raise_error(Samanage::NotFound) # id should match found other_asset
68
+ end
69
+ it 'update_other_asset: update_other_asset by id' do
70
+ other_assets = @controller.collect_other_assets
71
+ sample_id = other_assets.sample['id']
72
+ new_name = (0...50).map { ('a'..'z').to_a[rand(26)] }.join
73
+ json = {
74
+ :other_asset => {
75
+ :name => new_name
76
+ }
77
+ }
78
+ other_asset_update = @controller.update_other_asset(payload: json.to_json, id: sample_id)
79
+ expect(other_asset_update[:data]["name"]).to eq(new_name)
80
+ expect(other_asset_update[:code]).to eq(200).or(201)
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,74 @@
1
+ require 'samanage'
2
+
3
+ describe Samanage::Api do
4
+ context 'Users' do
5
+ before(:each) do
6
+ TOKEN ||= ENV['SAMANAGE_TEST_API_TOKEN']
7
+ @controller = Samanage::Api.new(token: TOKEN)
8
+ end
9
+ describe 'API Functions' do
10
+ it 'get_users: it returns API call of users' do
11
+ api_call = @controller.get_users
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 'collect_users: collects array of users' do
18
+ users = @controller.collect_users
19
+ user_count = @controller.get_users[:total_count]
20
+ expect(users).to be_an(Array)
21
+ expect(users.size).to eq(user_count)
22
+ end
23
+ it 'create_user(payload: json): creates a user' do
24
+ user_name = "samanage-ruby-#{(rand*10**10).ceil}"
25
+ email = user_name + "@samanage.com"
26
+ json = {
27
+ :user => {
28
+ :name => user_name,
29
+ :email => email,
30
+ }
31
+ }
32
+ user_create = @controller.create_user(payload: json.to_json)
33
+ expect(user_create[:data]['email']).to eq(email)
34
+ expect(user_create[:data]['id']).to be_an(Integer)
35
+ expect(user_create[:data]['name']).to eq(user_name)
36
+ expect(user_create[:code]).to eq(200).or(201)
37
+ end
38
+ it 'create_user: fails if no email' do
39
+ user_name = "samanage-ruby-#{(rand*10**10).ceil}"
40
+ json = {
41
+ :user => {
42
+ :name => user_name,
43
+ }
44
+ }
45
+ expect{@controller.create_user(payload: json.to_json)}.to raise_error(Samanage::InvalidRequest)
46
+ end
47
+ it 'find_user: returns a user card by known id' do
48
+ users = @controller.collect_users
49
+ sample_id = users.sample['id']
50
+ user = @controller.find_user(id: sample_id)
51
+ expect(user[:data]['id']).to eq(sample_id) # id should match found user
52
+ expect(user[:data]).to have_key('email')
53
+ expect(user[:data]).to have_key('name')
54
+ end
55
+ it 'find_user: returns nothing for an invalid id' do
56
+ sample_id = (0..10).entries.sample
57
+ expect{@controller.find_user(id: sample_id)}.to raise_error(Samanage::NotFound) # id should match found user
58
+ end
59
+ it 'update_user: update_user by id' do
60
+ users = @controller.collect_users
61
+ sample_id = users.sample['id']
62
+ new_name = (0...25).map { ('a'..'z').to_a[rand(26)] }.join
63
+ json = {
64
+ :user => {
65
+ :name => new_name
66
+ }
67
+ }
68
+ user_update = @controller.update_user(payload: json.to_json, id: sample_id)
69
+ expect(user_update[:data]["name"]).to eq(new_name)
70
+ expect(user_update[:code]).to eq(200).or(201)
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+ describe Samanage do
3
+ describe 'API Controller' do
4
+ before(:each) do
5
+ TOKEN ||= ENV['SAMANAGE_TEST_API_TOKEN']
6
+ end
7
+ context 'on creation' do
8
+ it 'Requires Email & Token' do
9
+ expect{ Samanage::Api.new() }.to raise_error(ArgumentError)
10
+ expect{ Samanage::Api.new(token: "invalid token") }.to raise_error(Samanage::AuthorizationError)
11
+ expect{ Samanage::Api.new(token: TOKEN) }.to_not raise_error
12
+ end
13
+
14
+ it 'Validates Credentials on Creation' do
15
+ # Valid Credentials
16
+ expect(Samanage::Api.new(token: TOKEN)).to be_an_instance_of(Samanage::Api)
17
+ # Invalid / Reversed Credentials
18
+ expect{Samanage::Api.new(token: 'invalid')}.to raise_error(Samanage::AuthorizationError)
19
+ expect(Samanage::Api.new(token: TOKEN).custom_forms).to be(nil)
20
+ end
21
+
22
+ it 'Finds all custom forms in development mode' do
23
+ api_controller = Samanage::Api.new(token: TOKEN, development_mode: true)
24
+ expect(api_controller).to be_an_instance_of(Samanage::Api)
25
+ expect(api_controller.custom_forms).not_to be(nil)
26
+ expect(api_controller.custom_forms).to be_a(Hash)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,18 @@
1
+ require 'samanage'
2
+ describe Samanage::UrlBuilder do
3
+ context 'Url Builder' do
4
+ it 'Strips down to id' do
5
+ path = ['users.json','hardwares/1234']
6
+ options = [
7
+ {:id => '1234'},
8
+ {:id => 12345, :email => 'abc@company.com'},
9
+ {:email => 'abc', :name => 'Joe Doe'},
10
+ {:site => 0001, :id => 1234}
11
+ ]
12
+ 25.times {
13
+ url = Samanage::UrlBuilder.new(path: path.sample, options: options.sample).url
14
+ expect(url).to be_a(String)
15
+ }
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,9 @@
1
+ spec_dir = File.expand_path(File.dirname(__FILE__))
2
+ root_dir = File.expand_path(File.join(spec_dir, '..'))
3
+ lib_dir = File.expand_path(File.join(root_dir, 'lib'))
4
+
5
+ $LOAD_PATH.unshift(spec_dir)
6
+ $LOAD_PATH.unshift(lib_dir)
7
+ $LOAD_PATH.uniq!
8
+
9
+ require 'samanage'
data/test.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'samanage'
2
+
3
+ api_controller = Samanage::Api.new(token: 'SAMANAGE_TEST_API_TOKEN')
4
+ puts api_controller
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: samanage
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.4'
5
+ platform: ruby
6
+ authors:
7
+ - Chris Walls
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-01-01 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Connect to Samanage using Ruby!
14
+ email: chris.walls@samanage.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - ".DS_Store"
20
+ - ".gitignore"
21
+ - Gemfile
22
+ - Gemfile.lock
23
+ - Guardfile
24
+ - LICENSE
25
+ - README.md
26
+ - lib/.DS_Store
27
+ - lib/samanage.rb
28
+ - lib/samanage/.DS_Store
29
+ - lib/samanage/api.rb
30
+ - lib/samanage/api/custom_fields.rb
31
+ - lib/samanage/api/custom_forms.rb
32
+ - lib/samanage/api/hardwares.rb
33
+ - lib/samanage/api/incidents.rb
34
+ - lib/samanage/api/other_assets.rb
35
+ - lib/samanage/api/requester.rb
36
+ - lib/samanage/api/users.rb
37
+ - lib/samanage/error.rb
38
+ - lib/samanage/url_builder.rb
39
+ - lib/test.rb
40
+ - samanage.gemspec
41
+ - spec/api/samanage_custom_field_spec.rb
42
+ - spec/api/samanage_custom_form_spec.rb
43
+ - spec/api/samanage_hardware_spec.rb
44
+ - spec/api/samanage_incident_spec.rb
45
+ - spec/api/samanage_other_asset_spec.rb
46
+ - spec/api/samanage_user_spec.rb
47
+ - spec/samanage_api_spec.rb
48
+ - spec/samanage_url_builder_spec.rb
49
+ - spec/spec_helper.rb
50
+ - test.rb
51
+ homepage: http://rubygems.org/gems/samanage
52
+ licenses:
53
+ - MIT
54
+ metadata: {}
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubyforge_project:
71
+ rubygems_version: 2.5.2
72
+ signing_key:
73
+ specification_version: 4
74
+ summary: Samanage Ruby Gem
75
+ test_files: []