samanage 1.6.8 → 1.6.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/changelog.txt +1 -0
- data/lib/samanage.rb +1 -0
- data/lib/samanage/api.rb +3 -2
- data/lib/samanage/api/comments.rb +3 -6
- data/lib/samanage/api/custom_fields.rb +2 -4
- data/lib/samanage/api/custom_forms.rb +2 -5
- data/lib/samanage/api/hardwares.rb +7 -16
- data/lib/samanage/api/incidents.rb +5 -11
- data/lib/samanage/api/mobiles.rb +45 -0
- data/lib/samanage/api/other_assets.rb +5 -11
- data/lib/samanage/api/requester.rb +1 -2
- data/lib/samanage/api/users.rb +8 -14
- data/lib/samanage/url_builder.rb +2 -0
- data/lib/test.rb +1 -1
- data/samanage.gemspec +1 -1
- data/spec/api/comments_spec.rb +0 -2
- data/spec/api/samanage_incident_spec.rb +5 -5
- data/spec/api/samanage_mobile_spec.rb +77 -0
- data/spec/api/samanage_other_asset_spec.rb +0 -3
- metadata +4 -3
- data/test.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd423983751b04925ffae9682558c704a9264b07
|
4
|
+
data.tar.gz: e03159f0fefc436de87abd20522ce42e293c31af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13117b118b758a29d7441b9a03d4cf2582b4579c5c4110e2bc5b886b1bdb6656dbf01c02dfe10390df07cc667b874c7dfd3d6b83285ee9ee6d69b31c3720d0e1
|
7
|
+
data.tar.gz: cf10be0fdb93b0cb35b09a309f4c6c1aa5f5ecee8b848d253139b7fcd26f76387cfd7559da51d1ebdc7116127dad37e262b086c94675a6f9abbdbec768f037e0
|
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# Samanage Ruby Gem
|
2
2
|
[![Gem Version](https://badge.fury.io/rb/samanage.svg)](https://badge.fury.io/rb/samanage)
|
3
|
+
[![Build Status](https://semaphoreci.com/api/v1/projects/8e1f8e7f-6e09-4dad-ac10-e9f41fa61b7d/1437435/shields_badge.svg)](https://semaphoreci.com/cw2908/samanage-ruby)
|
3
4
|
## Requirements
|
4
5
|
- Ruby >= 2.3
|
5
6
|
|
@@ -37,7 +38,7 @@ Initialize API controller
|
|
37
38
|
|
38
39
|
- Update hardware
|
39
40
|
```ruby
|
40
|
-
hardware = {'hardware':{'name':'My Computer'}}
|
41
|
+
hardware = {'hardware':{'name':'My Computer'}}.to_json
|
41
42
|
result = api_controller.update_hardware(id: 123, payload: hardware)
|
42
43
|
```
|
43
44
|
|
data/changelog.txt
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
1.6.9 Added CRU support for Mobile Devices
|
data/lib/samanage.rb
CHANGED
@@ -6,6 +6,7 @@ require 'samanage/api/users'
|
|
6
6
|
require 'samanage/api/requester'
|
7
7
|
require 'samanage/api/hardwares'
|
8
8
|
require 'samanage/api/other_assets'
|
9
|
+
require 'samanage/api/mobiles'
|
9
10
|
require 'samanage/api/incidents'
|
10
11
|
require 'samanage/api/comments'
|
11
12
|
require 'samanage/api/custom_fields'
|
data/lib/samanage/api.rb
CHANGED
@@ -5,6 +5,7 @@ module Samanage
|
|
5
5
|
user: 'users.json',
|
6
6
|
incident: 'incidents.json',
|
7
7
|
other_asset: 'other_assets.json',
|
8
|
+
mobile: 'mobiles.json',
|
8
9
|
custom_fields: 'custom_fields.json',
|
9
10
|
custom_forms: 'custom_forms.json',
|
10
11
|
}
|
@@ -100,8 +101,8 @@ module Samanage
|
|
100
101
|
error = e.class
|
101
102
|
response = nil
|
102
103
|
raise Samanage::Error.new(error: error, response: response)
|
103
|
-
|
104
|
-
|
104
|
+
# Always return response hash
|
105
|
+
response
|
105
106
|
end
|
106
107
|
|
107
108
|
|
@@ -5,15 +5,13 @@ module Samanage
|
|
5
5
|
# Find comments given incident_id
|
6
6
|
def get_comments(incident_id: )
|
7
7
|
path = "incidents/#{incident_id}/comments.json"
|
8
|
-
|
9
|
-
api_call
|
8
|
+
self.execute(path: path)
|
10
9
|
end
|
11
10
|
|
12
11
|
# Add a new comment
|
13
12
|
def create_comment(incident_id: nil, comment: nil, options: {})
|
14
13
|
path = "incidents/#{incident_id}/comments.json"
|
15
|
-
|
16
|
-
api_call
|
14
|
+
self.execute(http_method: 'post', path: path, payload: comment)
|
17
15
|
end
|
18
16
|
|
19
17
|
# Return all comments from the incident_id
|
@@ -24,8 +22,7 @@ module Samanage
|
|
24
22
|
comments = Array.new
|
25
23
|
while page <= max_pages
|
26
24
|
path = "incidents/#{incident_id}/comments.json?page=#{page}"
|
27
|
-
|
28
|
-
comments += api_call[:data]
|
25
|
+
comments += self.execute(path: path)[:data]
|
29
26
|
page += 1
|
30
27
|
end
|
31
28
|
comments
|
@@ -4,8 +4,7 @@ module Samanage
|
|
4
4
|
# Get custom fields default url
|
5
5
|
def get_custom_fields(path: PATHS[:custom_fields], options:{})
|
6
6
|
url = Samanage::UrlBuilder.new(path: path, options: options).url
|
7
|
-
|
8
|
-
api_call
|
7
|
+
self.execute(path: url)
|
9
8
|
end
|
10
9
|
|
11
10
|
# Gets all custom fields
|
@@ -14,8 +13,7 @@ module Samanage
|
|
14
13
|
custom_fields = Array.new
|
15
14
|
total_pages = self.get_custom_fields[:total_pages] ||= 2
|
16
15
|
while page <= total_pages
|
17
|
-
|
18
|
-
custom_fields += api_call[:data]
|
16
|
+
custom_fields += self.execute(path: "custom_fields.json")[:data]
|
19
17
|
page += 1
|
20
18
|
end
|
21
19
|
custom_fields
|
@@ -3,8 +3,7 @@ module Samanage
|
|
3
3
|
# Get custom forms path
|
4
4
|
def get_custom_forms(path: PATHS[:custom_forms], options: {})
|
5
5
|
url = Samanage::UrlBuilder.new(path: path, options: options).url
|
6
|
-
|
7
|
-
api_call
|
6
|
+
self.execute(path: url)
|
8
7
|
end
|
9
8
|
|
10
9
|
# Get all custom forms
|
@@ -12,10 +11,8 @@ module Samanage
|
|
12
11
|
page = 1
|
13
12
|
custom_forms = Array.new
|
14
13
|
total_pages = self.get_custom_forms[:total_pages]
|
15
|
-
# puts api_call
|
16
14
|
while page <= total_pages
|
17
|
-
|
18
|
-
custom_forms += api_call[:data]
|
15
|
+
custom_forms += self.execute(http_method: 'get', path: "custom_forms.json?page=#{page}")[:data]
|
19
16
|
page += 1
|
20
17
|
end
|
21
18
|
custom_forms
|
@@ -4,8 +4,7 @@ module Samanage
|
|
4
4
|
# Get hardware default path
|
5
5
|
def get_hardwares(path: PATHS[:hardware], options: {})
|
6
6
|
url = Samanage::UrlBuilder.new(path: path, options: options).url
|
7
|
-
|
8
|
-
api_call
|
7
|
+
self.execute(path: url)
|
9
8
|
end
|
10
9
|
|
11
10
|
# Get all hardwares
|
@@ -13,10 +12,8 @@ module Samanage
|
|
13
12
|
page = 1
|
14
13
|
hardwares = Array.new
|
15
14
|
total_pages = self.get_hardwares[:total_pages]
|
16
|
-
# puts api_call
|
17
15
|
while page <= total_pages
|
18
|
-
|
19
|
-
hardwares += api_call[:data]
|
16
|
+
hardwares += self.execute(http_method: 'get', path: "hardwares.json?page=#{page}")[:data]
|
20
17
|
page += 1
|
21
18
|
end
|
22
19
|
hardwares
|
@@ -24,38 +21,32 @@ module Samanage
|
|
24
21
|
|
25
22
|
# Create hardware given json payload
|
26
23
|
def create_hardware(payload: nil, options: {})
|
27
|
-
|
28
|
-
api_call
|
24
|
+
self.execute(path: PATHS[:hardware], http_method: 'post', payload: payload)
|
29
25
|
end
|
30
26
|
|
31
27
|
# Find hardware given id
|
32
28
|
def find_hardware(id: nil)
|
33
29
|
path = "hardwares/#{id}.json"
|
34
|
-
|
35
|
-
api_call
|
30
|
+
self.execute(path: path)
|
36
31
|
end
|
37
32
|
|
38
33
|
# Find hardware given a serial number
|
39
34
|
def find_hardwares_by_serial(serial_number: nil)
|
40
35
|
path = "hardwares.json?serial_number[]=#{serial_number}"
|
41
|
-
|
42
|
-
api_call
|
36
|
+
self.execute(path: path)
|
43
37
|
end
|
44
38
|
|
45
39
|
|
46
40
|
# Check for hardware using URL builder
|
47
41
|
def check_hardware(options: {})
|
48
42
|
url = Samanage::UrlBuilder.new(path: PATHS[:hardware], options: options).url
|
49
|
-
|
50
|
-
api_call = self.execute(path: url)
|
51
|
-
api_call
|
43
|
+
self.execute(path: url)
|
52
44
|
end
|
53
45
|
|
54
46
|
# Update hardware given id
|
55
47
|
def update_hardware(payload: nil, id: nil, options: {})
|
56
48
|
path = "hardwares/#{id}.json"
|
57
|
-
|
58
|
-
api_call
|
49
|
+
self.execute(path: path, http_method: 'put', payload: payload)
|
59
50
|
end
|
60
51
|
end
|
61
52
|
end
|
@@ -4,8 +4,7 @@ module Samanage
|
|
4
4
|
# Default get incident path
|
5
5
|
def get_incidents(path: PATHS[:incident], options: {})
|
6
6
|
url = Samanage::UrlBuilder.new(path: path, options: options).url
|
7
|
-
|
8
|
-
api_call
|
7
|
+
self.execute(path: url)
|
9
8
|
end
|
10
9
|
|
11
10
|
|
@@ -14,10 +13,8 @@ module Samanage
|
|
14
13
|
page = 1
|
15
14
|
incidents = Array.new
|
16
15
|
total_pages = self.get_incidents[:total_pages]
|
17
|
-
# puts api_call
|
18
16
|
while page <= total_pages
|
19
|
-
|
20
|
-
incidents += api_call[:data]
|
17
|
+
incidents += self.execute(http_method: 'get', path: "incidents.json?page=#{page}")[:data]
|
21
18
|
page += 1
|
22
19
|
end
|
23
20
|
incidents
|
@@ -26,22 +23,19 @@ module Samanage
|
|
26
23
|
|
27
24
|
# Create an incident given json
|
28
25
|
def create_incident(payload: nil, options: {})
|
29
|
-
|
30
|
-
api_call
|
26
|
+
self.execute(path: PATHS[:incident], http_method: 'post', payload: payload)
|
31
27
|
end
|
32
28
|
|
33
29
|
# Find incident by ID
|
34
30
|
def find_incident(id: nil)
|
35
31
|
path = "incidents/#{id}.json"
|
36
|
-
|
37
|
-
api_call
|
32
|
+
self.execute(path: path)
|
38
33
|
end
|
39
34
|
|
40
35
|
# Update an incident given id and json
|
41
36
|
def update_incident(payload: nil, id: nil, options: {})
|
42
37
|
path = "incidents/#{id}.json"
|
43
|
-
|
44
|
-
api_call
|
38
|
+
self.execute(path: path, http_method: 'put', payload: payload)
|
45
39
|
end
|
46
40
|
end
|
47
41
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Samanage
|
2
|
+
class Api
|
3
|
+
|
4
|
+
# Get mobile default path
|
5
|
+
def get_mobiles(path: PATHS[:mobile], options: {})
|
6
|
+
url = Samanage::UrlBuilder.new(path: path, options: options).url
|
7
|
+
self.execute(path: url)
|
8
|
+
end
|
9
|
+
|
10
|
+
# Get all mobiles
|
11
|
+
def collect_mobiles
|
12
|
+
page = 1
|
13
|
+
mobiles = Array.new
|
14
|
+
total_pages = self.get_mobiles[:total_pages]
|
15
|
+
while page <= total_pages
|
16
|
+
mobiles += self.execute(http_method: 'get', path: "mobiles.json?page=#{page}")[:data]
|
17
|
+
page += 1
|
18
|
+
end
|
19
|
+
mobiles
|
20
|
+
end
|
21
|
+
|
22
|
+
# Create mobile given json payload
|
23
|
+
def create_mobile(payload: nil, options: {})
|
24
|
+
self.execute(path: PATHS[:mobile], http_method: 'post', payload: payload)
|
25
|
+
end
|
26
|
+
|
27
|
+
# Find mobile given id
|
28
|
+
def find_mobile(id: nil)
|
29
|
+
path = "mobiles/#{id}.json"
|
30
|
+
self.execute(path: path)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Check for mobile using URL builder
|
34
|
+
def check_mobile(options: {})
|
35
|
+
url = Samanage::UrlBuilder.new(path: PATHS[:mobile], options: options).url
|
36
|
+
self.execute(path: url)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Update mobile given id
|
40
|
+
def update_mobile(payload: nil, id: nil, options: {})
|
41
|
+
path = "mobiles/#{id}.json"
|
42
|
+
self.execute(path: path, http_method: 'put', payload: payload)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -4,8 +4,7 @@ module Samanage
|
|
4
4
|
# Default get other_assets path
|
5
5
|
def get_other_assets(path: PATHS[:other_asset], options: {})
|
6
6
|
url = Samanage::UrlBuilder.new(path: path, options: options).url
|
7
|
-
|
8
|
-
api_call
|
7
|
+
self.execute(path: url)
|
9
8
|
end
|
10
9
|
|
11
10
|
# Returns all other assets
|
@@ -13,11 +12,9 @@ module Samanage
|
|
13
12
|
page = 1
|
14
13
|
other_assets = Array.new
|
15
14
|
total_pages = self.get_other_assets[:total_pages]
|
16
|
-
# puts api_call
|
17
15
|
other_assets = []
|
18
16
|
while page <= total_pages
|
19
|
-
|
20
|
-
other_assets += api_call[:data]
|
17
|
+
other_assets += self.execute(http_method: 'get', path: "other_assets.json?page=#{page}")[:data]
|
21
18
|
page += 1
|
22
19
|
end
|
23
20
|
other_assets.uniq
|
@@ -26,23 +23,20 @@ module Samanage
|
|
26
23
|
|
27
24
|
# Create an other_asset given json
|
28
25
|
def create_other_asset(payload: nil, options: {})
|
29
|
-
|
30
|
-
api_call
|
26
|
+
self.execute(path: PATHS[:other_asset], http_method: 'post', payload: payload)
|
31
27
|
end
|
32
28
|
|
33
29
|
|
34
30
|
# Find other_asset by id
|
35
31
|
def find_other_asset(id: nil)
|
36
32
|
path = "other_assets/#{id}.json"
|
37
|
-
|
38
|
-
api_call
|
33
|
+
self.execute(path: path)
|
39
34
|
end
|
40
35
|
|
41
36
|
# Update other_asset given json and id
|
42
37
|
def update_other_asset(payload: nil, id: nil, options: {})
|
43
38
|
path = "other_assets/#{id}.json"
|
44
|
-
|
45
|
-
api_call
|
39
|
+
self.execute(path: path, http_method: 'put', payload: payload)
|
46
40
|
end
|
47
41
|
end
|
48
42
|
end
|
@@ -3,8 +3,7 @@ module Samanage
|
|
3
3
|
# Get requester from value (email)
|
4
4
|
def get_requester_id(value: nil)
|
5
5
|
api_call = self.execute(path: "requesters.json?name=#{value}")
|
6
|
-
|
7
|
-
requester
|
6
|
+
api_call[:data].size == 1 ? api_call[:data][0] : nil
|
8
7
|
end
|
9
8
|
end
|
10
9
|
end
|
data/lib/samanage/api/users.rb
CHANGED
@@ -5,9 +5,8 @@ module Samanage
|
|
5
5
|
# Get users, using URL builder
|
6
6
|
def get_users(path: PATHS[:user], options: {})
|
7
7
|
url = Samanage::UrlBuilder.new(path: path, options: options).url
|
8
|
-
|
9
|
-
|
10
|
-
end
|
8
|
+
self.execute(path: url)
|
9
|
+
end
|
11
10
|
|
12
11
|
# Returns all users in the account
|
13
12
|
def collect_users
|
@@ -15,8 +14,7 @@ module Samanage
|
|
15
14
|
users = Array.new
|
16
15
|
total_pages = self.get_users[:total_pages]
|
17
16
|
while page <= total_pages
|
18
|
-
|
19
|
-
users += api_call[:data]
|
17
|
+
users += self.execute(http_method: 'get', path: "users.json?page=#{page}")[:data]
|
20
18
|
page += 1
|
21
19
|
end
|
22
20
|
users
|
@@ -24,15 +22,13 @@ module Samanage
|
|
24
22
|
|
25
23
|
# Create user given JSON
|
26
24
|
def create_user(payload: nil, options: {})
|
27
|
-
|
28
|
-
|
29
|
-
end
|
25
|
+
self.execute(path: PATHS[:user], http_method: 'post', payload: payload)
|
26
|
+
end
|
30
27
|
|
31
28
|
# Return user by ID
|
32
29
|
def find_user(id: nil)
|
33
30
|
path = "users/#{id}.json"
|
34
|
-
|
35
|
-
api_call
|
31
|
+
self.execute(path: path)
|
36
32
|
end
|
37
33
|
|
38
34
|
# Email is unique so compare first for exact match only. Returns nil or the id
|
@@ -44,15 +40,13 @@ module Samanage
|
|
44
40
|
# Check for user by field (ex: users.json?field=value)
|
45
41
|
def check_user(field: 'email', value: nil)
|
46
42
|
url = "users.json?#{field}=#{value}"
|
47
|
-
|
48
|
-
api_call
|
43
|
+
self.execute(path: url)
|
49
44
|
end
|
50
45
|
|
51
46
|
# Update user by id
|
52
47
|
def update_user(payload: nil, id: nil)
|
53
48
|
path = "users/#{id}.json"
|
54
|
-
|
55
|
-
api_call
|
49
|
+
self.execute(path: path, http_method: 'put', payload: payload)
|
56
50
|
end
|
57
51
|
end
|
58
52
|
end
|
data/lib/samanage/url_builder.rb
CHANGED
data/lib/test.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.6.
|
4
|
+
s.version = '1.6.9'
|
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!"
|
data/spec/api/comments_spec.rb
CHANGED
@@ -30,8 +30,6 @@ describe Samanage::Api do
|
|
30
30
|
incident_id = 19394209
|
31
31
|
comments_api = @controller.get_comments(incident_id: incident_id)
|
32
32
|
comments_found = @controller.collect_comments(incident_id: incident_id)
|
33
|
-
# puts "comments api size: #{comments_api.inspect}"
|
34
|
-
# puts "Found Comments: #{comments_found.size}"
|
35
33
|
|
36
34
|
# Total count bug
|
37
35
|
# expect(comments_api[:total_count]).to eq(comments_found.size)
|
@@ -21,7 +21,6 @@ describe Samanage::Api do
|
|
21
21
|
end
|
22
22
|
it 'create_incident(payload: json): creates a incident' do
|
23
23
|
users_email = @controller.collect_users.sample['email']
|
24
|
-
serial_number = (0...50).map { ('a'..'z').to_a[rand(26)] }.join
|
25
24
|
incident_name = "Samanage Ruby Incident"
|
26
25
|
json = {
|
27
26
|
:incident => {
|
@@ -62,15 +61,16 @@ describe Samanage::Api do
|
|
62
61
|
end
|
63
62
|
it 'update_incident: update_incident by id' do
|
64
63
|
incidents = @controller.collect_incidents
|
65
|
-
|
66
|
-
|
64
|
+
sample_incident = incidents.reject{|i| ['Closed','Resolved'].include? i['state']}.sample
|
65
|
+
sample_id = sample_incident['id']
|
66
|
+
description = (0...500).map { ('a'..'z').to_a[rand(26)] }.join
|
67
67
|
incident_json = {
|
68
68
|
:incident => {
|
69
|
-
:
|
69
|
+
:description => description
|
70
70
|
}
|
71
71
|
}
|
72
72
|
incident_update = @controller.update_incident(payload: incident_json.to_json, id: sample_id)
|
73
|
-
expect(incident_update[:data][
|
73
|
+
expect(incident_update[:data]['description']).to eq(description)
|
74
74
|
expect(incident_update[:code]).to eq(200).or(201)
|
75
75
|
end
|
76
76
|
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'samanage'
|
2
|
+
|
3
|
+
describe Samanage::Api do
|
4
|
+
context 'Mobile' 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_mobiles: it returns API call of mobiles' do
|
11
|
+
api_call = @controller.get_mobiles
|
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_mobiles: collects array of mobiles' do
|
18
|
+
mobiles = @controller.collect_mobiles
|
19
|
+
mobile_count = @controller.get_mobiles[:total_count]
|
20
|
+
expect(mobiles).to be_an(Array)
|
21
|
+
expect(mobiles.size).to eq(mobile_count)
|
22
|
+
end
|
23
|
+
it 'create_mobile(payload: json): creates a mobile' do
|
24
|
+
mobile_name = "samanage-ruby-#{(rand*10**10).ceil}"
|
25
|
+
serial_number = (0...50).map { ('a'..'z').to_a[rand(26)] }.join
|
26
|
+
json = {
|
27
|
+
:mobile => {
|
28
|
+
model: 'test',
|
29
|
+
manufacturer: mobile_name,
|
30
|
+
serial_number: serial_number,
|
31
|
+
}
|
32
|
+
}
|
33
|
+
mobile_create = @controller.create_mobile(payload: json.to_json)
|
34
|
+
|
35
|
+
expect(mobile_create[:data]['id']).to be_an(Integer)
|
36
|
+
expect(mobile_create[:data]['manufacturer']).to eq(mobile_name)
|
37
|
+
end
|
38
|
+
it 'create_mobile: fails if no serial' do
|
39
|
+
mobile_name = "samanage-ruby-#{(rand*10**10).ceil}"
|
40
|
+
json = {
|
41
|
+
:mobile => {
|
42
|
+
model: 'test',
|
43
|
+
manufacturer: mobile_name,
|
44
|
+
}
|
45
|
+
}
|
46
|
+
expect{@controller.create_mobile(payload: json.to_json)}.to raise_error(Samanage::InvalidRequest)
|
47
|
+
end
|
48
|
+
it 'find_mobile: returns a mobile card by known id' do
|
49
|
+
mobiles = @controller.collect_mobiles
|
50
|
+
sample_id = mobiles.sample['id']
|
51
|
+
mobile = @controller.find_mobile(id: sample_id)
|
52
|
+
|
53
|
+
expect(mobile[:data]['id']).to eq(sample_id) # id should match found mobile
|
54
|
+
expect(mobile[:data]).to have_key('manufacturer')
|
55
|
+
expect(mobile[:data]).to have_key('serial_number')
|
56
|
+
expect(mobile[:data]).to have_key('id')
|
57
|
+
end
|
58
|
+
it 'find_mobile: returns nothing for an invalid id' do
|
59
|
+
sample_id = (0..10).entries.sample
|
60
|
+
expect{@controller.find_mobile(id: sample_id)}.to raise_error(Samanage::NotFound) # id should match found mobile
|
61
|
+
end
|
62
|
+
it 'update_mobile: update_mobile by id' do
|
63
|
+
mobiles = @controller.collect_mobiles
|
64
|
+
sample_id = mobiles.sample['id']
|
65
|
+
new_name = (0...50).map {('a'..'z').to_a[rand(26)] }.join
|
66
|
+
json = {
|
67
|
+
:mobile => {
|
68
|
+
:manufacturer => new_name
|
69
|
+
}
|
70
|
+
}
|
71
|
+
mobile_update = @controller.update_mobile(payload: json.to_json, id: sample_id)
|
72
|
+
expect(mobile_update[:data]["manufacturer"]).to eq(new_name)
|
73
|
+
expect(mobile_update[:code]).to eq(200).or(201)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -50,9 +50,6 @@ describe Samanage::Api do
|
|
50
50
|
|
51
51
|
it 'find_other_asset: returns an other_asset card by known id' do
|
52
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
53
|
sample_id = other_assets.sample['id']
|
57
54
|
|
58
55
|
other_asset = @controller.find_other_asset(id: sample_id)
|
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.6.
|
4
|
+
version: 1.6.9
|
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-11-
|
11
|
+
date: 2017-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|
@@ -58,6 +58,7 @@ files:
|
|
58
58
|
- lib/samanage/api/custom_forms.rb
|
59
59
|
- lib/samanage/api/hardwares.rb
|
60
60
|
- lib/samanage/api/incidents.rb
|
61
|
+
- lib/samanage/api/mobiles.rb
|
61
62
|
- lib/samanage/api/other_assets.rb
|
62
63
|
- lib/samanage/api/requester.rb
|
63
64
|
- lib/samanage/api/users.rb
|
@@ -70,12 +71,12 @@ files:
|
|
70
71
|
- spec/api/samanage_custom_form_spec.rb
|
71
72
|
- spec/api/samanage_hardware_spec.rb
|
72
73
|
- spec/api/samanage_incident_spec.rb
|
74
|
+
- spec/api/samanage_mobile_spec.rb
|
73
75
|
- spec/api/samanage_other_asset_spec.rb
|
74
76
|
- spec/api/samanage_user_spec.rb
|
75
77
|
- spec/samanage_api_spec.rb
|
76
78
|
- spec/samanage_url_builder_spec.rb
|
77
79
|
- spec/spec_helper.rb
|
78
|
-
- test.rb
|
79
80
|
homepage: https://github.com/cw2908/samanage-ruby
|
80
81
|
licenses:
|
81
82
|
- MIT
|