samanage 1.8.1 → 1.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Guardfile +2 -1
- data/changelog.md +4 -1
- data/lib/samanage/api/category.rb +26 -0
- data/lib/samanage/api.rb +9 -8
- data/lib/samanage.rb +2 -1
- data/spec/api/samanage_category_spec.rb +30 -0
- data/spec/api/{comments_spec.rb → samanage_comments_spec.rb} +0 -0
- data/spec/api/samanage_custom_form_spec.rb +1 -1
- data/spec/samanage_api_spec.rb +3 -3
- data/spec/samanage_category_spec.rb +31 -0
- data/spec/samanage_url_builder_spec.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e3b9e74fc9dd73dbe2989f205691068facee01d
|
4
|
+
data.tar.gz: e3114f63ef4ee17a0c3546da722f9a9ba0bce80b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80cbe3721a4b62f9512501c9cd83d30a6a3eed9a2e7b2d752cf93b6bf66f53323c1db29b5efeb2168253c6c5f0767d59e9aa4d5aab1b97c6563be31658df9c1e
|
7
|
+
data.tar.gz: aa249b7fb1dee0adb3a8b5d8839ab91452d7cb169e1121c14b0f6d858ba07b80bf2264d0df15f1365109bcceb853a911e28da13985856fc70352ce3f86c51887
|
data/Guardfile
CHANGED
@@ -17,7 +17,8 @@
|
|
17
17
|
|
18
18
|
guard :rspec, cmd: 'bundle exec rspec', all_on_start: true do
|
19
19
|
watch(%r{^spec/.+_spec\.rb$})
|
20
|
-
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib
|
20
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/samanage_#{m[1]}_spec.rb" }
|
21
|
+
watch(%r{^lib/api/(.+)\.rb$}) { |m| "spec/lib/api/samanage_#{m[1]}_spec.rb" }
|
21
22
|
watch(%r{^lib/(.+)\.rb$})
|
22
23
|
watch('spec/spec_helper.rb') { "spec" }
|
23
24
|
end
|
data/changelog.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
+
# 1.8.2
|
2
|
+
- Adding Category support
|
3
|
+
|
1
4
|
#1.8.1
|
2
5
|
- More flexible membership adding
|
3
|
-
- Collection method aliasing for simpler api
|
6
|
+
- Collection method aliasing for simpler api (old methods will be removed in v2.0)
|
4
7
|
|
5
8
|
#1.8.0
|
6
9
|
- Adding coverage for invalid api requests
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Samanage
|
2
|
+
class Api
|
3
|
+
def get_categories(path: PATHS[:category], options: {})
|
4
|
+
url = Samanage::UrlBuilder.new(path: path, options: options).url
|
5
|
+
self.execute(path: url)
|
6
|
+
end
|
7
|
+
|
8
|
+
|
9
|
+
# Samanage categories are not paginated
|
10
|
+
# - to break into subcategories, add
|
11
|
+
def collect_categories
|
12
|
+
categories = Array.new
|
13
|
+
categories += self.execute(http_method: 'get', path: "categories.json")[:data]
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_category(payload: nil, options: {})
|
17
|
+
self.execute(path: PATHS[:category], http_method: 'post', payload: payload)
|
18
|
+
end
|
19
|
+
|
20
|
+
# def find_category(name: )
|
21
|
+
# self.categories
|
22
|
+
# end
|
23
|
+
|
24
|
+
alias_method :categories, :collect_categories
|
25
|
+
end
|
26
|
+
end
|
data/lib/samanage/api.rb
CHANGED
@@ -5,16 +5,17 @@ module Samanage
|
|
5
5
|
|
6
6
|
|
7
7
|
PATHS = {
|
8
|
+
category: 'categories.json',
|
9
|
+
custom_fields: 'custom_fields.json',
|
10
|
+
custom_forms: 'custom_forms.json',
|
11
|
+
department: 'departments.json',
|
12
|
+
group: 'groups.json',
|
8
13
|
hardware: 'hardwares.json',
|
9
|
-
user: 'users.json',
|
10
14
|
incident: 'incidents.json',
|
11
|
-
other_asset: 'other_assets.json',
|
12
15
|
mobile: 'mobiles.json',
|
13
|
-
|
14
|
-
custom_forms: 'custom_forms.json',
|
16
|
+
other_asset: 'other_assets.json',
|
15
17
|
site: 'sites.json',
|
16
|
-
|
17
|
-
group: 'groups.json'
|
18
|
+
user: 'users.json',
|
18
19
|
}
|
19
20
|
attr_accessor :datacenter, :content_type, :base_url, :token, :custom_forms, :authorized, :admins
|
20
21
|
|
@@ -23,9 +24,9 @@ module Samanage
|
|
23
24
|
def initialize(token: nil, datacenter: nil, development_mode: false)
|
24
25
|
self.token = token if token
|
25
26
|
if !datacenter.nil? && datacenter.to_s.downcase != 'eu'
|
26
|
-
|
27
|
+
datacenter = nil
|
27
28
|
end
|
28
|
-
self.datacenter ||= datacenter
|
29
|
+
self.datacenter ||= datacenter.to_s.downcase
|
29
30
|
self.base_url = "https://api#{self.datacenter.to_s.downcase}.samanage.com/"
|
30
31
|
self.content_type = 'json'
|
31
32
|
self.admins = []
|
data/lib/samanage.rb
CHANGED
@@ -2,6 +2,7 @@ $LOAD_PATH << File.dirname(__FILE__)
|
|
2
2
|
require 'httparty'
|
3
3
|
|
4
4
|
require 'samanage/api'
|
5
|
+
require 'samanage/api/category'
|
5
6
|
require 'samanage/api/comments'
|
6
7
|
require 'samanage/api/custom_fields'
|
7
8
|
require 'samanage/api/custom_forms'
|
@@ -18,5 +19,5 @@ require 'samanage/error'
|
|
18
19
|
require 'samanage/url_builder'
|
19
20
|
|
20
21
|
module Samanage
|
21
|
-
VERSION = '1.8.
|
22
|
+
VERSION = '1.8.2'
|
22
23
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'samanage'
|
2
|
+
describe Samanage::Api do
|
3
|
+
context 'category' do
|
4
|
+
before(:each) do
|
5
|
+
TOKEN ||= ENV['SAMANAGE_TEST_API_TOKEN']
|
6
|
+
@controller = Samanage::Api.new(token: TOKEN)
|
7
|
+
end
|
8
|
+
it 'collects all categories' do
|
9
|
+
puts "Category methods: #{@controller.methods}"
|
10
|
+
categories = @controller.collect_categories
|
11
|
+
expect(categories).to be_an(Array)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'creates a category' do
|
15
|
+
category_name = "Category Name ##{(rand*10**4).ceil}"
|
16
|
+
category_description = "Descrption #{(rand*10**4).ceil}"
|
17
|
+
payload = {
|
18
|
+
category: {
|
19
|
+
name: category_name,
|
20
|
+
description: category_description
|
21
|
+
}
|
22
|
+
}
|
23
|
+
category_create = @controller.create_category(payload: payload)
|
24
|
+
|
25
|
+
expect(category_create[:data]['id']).to be_an(Integer)
|
26
|
+
expect(category_create[:data]['name']).to eq(category_name)
|
27
|
+
expect(category_create[:code]).to eq(201).or(200)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
File without changes
|
@@ -15,7 +15,7 @@ describe Samanage::Api do
|
|
15
15
|
api_call = @controller.organize_forms
|
16
16
|
expect(api_call).to be_a(Hash)
|
17
17
|
expect(api_call.keys).to be_an(Array)
|
18
|
-
expect(api_call[api_call.keys.sample].sample).to be_a(Hash)
|
18
|
+
# expect(api_call[api_call.keys.sample].sample).to be_a(Hash)
|
19
19
|
end
|
20
20
|
it 'Finds the forms for an object_type' do
|
21
21
|
object_types = ['incident', 'user','other_asset','hardware','configuration_item']
|
data/spec/samanage_api_spec.rb
CHANGED
@@ -27,7 +27,7 @@ describe Samanage do
|
|
27
27
|
api_controller = Samanage::Api.new(token: TOKEN, development_mode: true)
|
28
28
|
expect(api_controller).to be_an_instance_of(Samanage::Api)
|
29
29
|
expect(api_controller.custom_forms).not_to be(nil)
|
30
|
-
expect(api_controller.custom_forms).to be_a(
|
30
|
+
expect(api_controller.custom_forms).to be_a(Array)
|
31
31
|
end
|
32
32
|
it 'Fails with invalid token in development mode' do
|
33
33
|
expect{ Samanage::Api.new(token: 'Invalid Token', development_mode: true)}.to raise_error(Samanage::AuthorizationError)
|
@@ -44,12 +44,12 @@ describe Samanage do
|
|
44
44
|
|
45
45
|
it 'sets eu datacenter' do
|
46
46
|
api_controller = Samanage::Api.new(token: 'token', datacenter: 'eu')
|
47
|
-
expect(api_controller.base_url).to eq('https://
|
47
|
+
expect(api_controller.base_url).to eq('https://apieu.samanage.com/')
|
48
48
|
end
|
49
49
|
|
50
50
|
it 'does not set non/eu datacenter' do
|
51
51
|
api_controller = Samanage::Api.new(token: 'token', datacenter: 'invalid')
|
52
|
-
expect(api_controller.base_url).to eq('https://
|
52
|
+
expect(api_controller.base_url).to eq('https://api.samanage.com/')
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'samanage'
|
2
|
+
describe Samanage::Api do
|
3
|
+
context 'category' do
|
4
|
+
before(:each) do
|
5
|
+
TOKEN ||= ENV['SAMANAGE_TEST_API_TOKEN']
|
6
|
+
@controller = Samanage::Api.new(token: TOKEN)
|
7
|
+
end
|
8
|
+
it 'collects all categories' do
|
9
|
+
categories = @controller.collect_categories
|
10
|
+
category_count = @controller.execute(path: 'categories.json')
|
11
|
+
expect(categories).to be_an(Array)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'creates a category' do
|
15
|
+
category_name = "category ##{(rand*10**4).ceil}"
|
16
|
+
category_location = "Location #{(rand*10**4).ceil}"
|
17
|
+
category_description = "Location #{(rand*10**4).ceil}"
|
18
|
+
payload = {
|
19
|
+
category: {
|
20
|
+
name: category_name,
|
21
|
+
description: category_description
|
22
|
+
}
|
23
|
+
}
|
24
|
+
category_create = @controller.create_category(payload: payload)
|
25
|
+
|
26
|
+
expect(category_create[:data]['id']).to be_an(Integer)
|
27
|
+
expect(category_create[:data]['name']).to eq(category_name)
|
28
|
+
expect(category_create[:code]).to eq(200).or(201)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: samanage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.8.
|
4
|
+
version: 1.8.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Walls
|
@@ -54,6 +54,7 @@ files:
|
|
54
54
|
- lib/data/cacert.pem
|
55
55
|
- lib/samanage.rb
|
56
56
|
- lib/samanage/api.rb
|
57
|
+
- lib/samanage/api/category.rb
|
57
58
|
- lib/samanage/api/comments.rb
|
58
59
|
- lib/samanage/api/custom_fields.rb
|
59
60
|
- lib/samanage/api/custom_forms.rb
|
@@ -69,7 +70,8 @@ files:
|
|
69
70
|
- lib/samanage/error.rb
|
70
71
|
- lib/samanage/url_builder.rb
|
71
72
|
- samanage.gemspec
|
72
|
-
- spec/api/
|
73
|
+
- spec/api/samanage_category_spec.rb
|
74
|
+
- spec/api/samanage_comments_spec.rb
|
73
75
|
- spec/api/samanage_custom_field_spec.rb
|
74
76
|
- spec/api/samanage_custom_form_spec.rb
|
75
77
|
- spec/api/samanage_department_spec.rb
|
@@ -81,6 +83,7 @@ files:
|
|
81
83
|
- spec/api/samanage_site_spec.rb
|
82
84
|
- spec/api/samanage_user_spec.rb
|
83
85
|
- spec/samanage_api_spec.rb
|
86
|
+
- spec/samanage_category_spec.rb
|
84
87
|
- spec/samanage_url_builder_spec.rb
|
85
88
|
- spec/spec_helper.rb
|
86
89
|
homepage: https://github.com/cw2908/samanage-ruby
|