samanage 1.6.7 → 1.6.8

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: a54ddc950e0e6cac420f3993849c31938243d5c2
4
- data.tar.gz: 59711d40b30ae8085be861e41fa7298351a31521
3
+ metadata.gz: 6e1600c1cfe1aeb6437bafbf11b7dde1a559ced4
4
+ data.tar.gz: '029fc5d74874c982203171dc618facef9d36876f'
5
5
  SHA512:
6
- metadata.gz: 5679aa41e37f5de3eded0e1f526c938a0fa55f466462816ca4eda6ca165f609ec947179197f46638a759562d751429486c0b6439cb0a44025244606a9092a0c8
7
- data.tar.gz: 9a18fe328a045081d5343427804fc2aa7885473ebc4fb2010ac83dd1c67b7977a88bad8e7acf6cf10cc84f2b91e6f11c6b997d96d5e49ae30fe85a35d7976839
6
+ metadata.gz: dbf34b7680c92d9974d1bd09a196a8e4b9944f12ce1dae03cd116f1c8daa22abe67e46c56869baa12a6989a2ee43ea6c9355f771f1d582e95a1e8b39d3ce5186
7
+ data.tar.gz: f69601824dda579f8d9adcb69b31ac453636ccf903d9db130ebb98208776a9538c512d79126dd01eabc2144eeed6325054d485835f51039aadc7529b445261a1
data/changelog.txt ADDED
File without changes
@@ -1,18 +1,22 @@
1
1
  module Samanage
2
2
  class Api
3
3
 
4
+
5
+ # Find comments given incident_id
4
6
  def get_comments(incident_id: )
5
7
  path = "incidents/#{incident_id}/comments.json"
6
8
  api_call = self.execute(path: path)
7
9
  api_call
8
10
  end
9
11
 
12
+ # Add a new comment
10
13
  def create_comment(incident_id: nil, comment: nil, options: {})
11
14
  path = "incidents/#{incident_id}/comments.json"
12
15
  api_call = self.execute(http_method: 'post', path: path, payload: comment)
13
16
  api_call
14
17
  end
15
18
 
19
+ # Return all comments from the incident_id
16
20
  def collect_comments(incident_id: nil)
17
21
 
18
22
  page = 1
@@ -1,10 +1,14 @@
1
1
  module Samanage
2
2
  class Api
3
+
4
+ # Get custom fields default url
3
5
  def get_custom_fields(path: PATHS[:custom_fields], options:{})
4
6
  url = Samanage::UrlBuilder.new(path: path, options: options).url
5
7
  api_call = self.execute(path: url)
6
8
  api_call
7
9
  end
10
+
11
+ # Gets all custom fields
8
12
  def collect_custom_fields
9
13
  page = 1
10
14
  custom_fields = Array.new
@@ -1,11 +1,13 @@
1
1
  module Samanage
2
2
  class Api
3
+ # Get custom forms path
3
4
  def get_custom_forms(path: PATHS[:custom_forms], options: {})
4
5
  url = Samanage::UrlBuilder.new(path: path, options: options).url
5
6
  api_call = self.execute(path: url)
6
7
  api_call
7
8
  end
8
9
 
10
+ # Get all custom forms
9
11
  def collect_custom_forms
10
12
  page = 1
11
13
  custom_forms = Array.new
@@ -19,6 +21,7 @@ module Samanage
19
21
  custom_forms
20
22
  end
21
23
 
24
+ # Set forms by type and map fields
22
25
  def organize_forms
23
26
  custom_forms = self.collect_custom_forms
24
27
  custom_forms.map{|form| form.delete_if{|k, v| v.nil?}}
@@ -31,6 +34,8 @@ module Samanage
31
34
  }
32
35
  }
33
36
  end
37
+
38
+ # Get form for a specific object type
34
39
  def form_for(object_type: nil)
35
40
  if self.custom_forms == nil
36
41
  self.custom_forms = self.organize_forms
@@ -1,11 +1,14 @@
1
1
  module Samanage
2
2
  class Api
3
+
4
+ # Get hardware default path
3
5
  def get_hardwares(path: PATHS[:hardware], options: {})
4
6
  url = Samanage::UrlBuilder.new(path: path, options: options).url
5
7
  api_call = self.execute(path: url)
6
8
  api_call
7
9
  end
8
10
 
11
+ # Get all hardwares
9
12
  def collect_hardwares
10
13
  page = 1
11
14
  hardwares = Array.new
@@ -19,23 +22,28 @@ module Samanage
19
22
  hardwares
20
23
  end
21
24
 
25
+ # Create hardware given json payload
22
26
  def create_hardware(payload: nil, options: {})
23
27
  api_call = self.execute(path: PATHS[:hardware], http_method: 'post', payload: payload)
24
28
  api_call
25
29
  end
26
30
 
31
+ # Find hardware given id
27
32
  def find_hardware(id: nil)
28
33
  path = "hardwares/#{id}.json"
29
34
  api_call = self.execute(path: path)
30
35
  api_call
31
36
  end
32
37
 
38
+ # Find hardware given a serial number
33
39
  def find_hardwares_by_serial(serial_number: nil)
34
40
  path = "hardwares.json?serial_number[]=#{serial_number}"
35
41
  api_call = self.execute(path: path)
36
42
  api_call
37
43
  end
38
44
 
45
+
46
+ # Check for hardware using URL builder
39
47
  def check_hardware(options: {})
40
48
  url = Samanage::UrlBuilder.new(path: PATHS[:hardware], options: options).url
41
49
  puts "Url: #{url}"
@@ -43,7 +51,7 @@ module Samanage
43
51
  api_call
44
52
  end
45
53
 
46
-
54
+ # Update hardware given id
47
55
  def update_hardware(payload: nil, id: nil, options: {})
48
56
  path = "hardwares/#{id}.json"
49
57
  api_call = self.execute(path: path, http_method: 'put', payload: payload)
@@ -1,11 +1,15 @@
1
1
  module Samanage
2
2
  class Api
3
+
4
+ # Default get incident path
3
5
  def get_incidents(path: PATHS[:incident], options: {})
4
6
  url = Samanage::UrlBuilder.new(path: path, options: options).url
5
7
  api_call = self.execute(path: url)
6
8
  api_call
7
9
  end
8
10
 
11
+
12
+ # Returns all incidents
9
13
  def collect_incidents
10
14
  page = 1
11
15
  incidents = Array.new
@@ -19,17 +23,21 @@ module Samanage
19
23
  incidents
20
24
  end
21
25
 
26
+
27
+ # Create an incident given json
22
28
  def create_incident(payload: nil, options: {})
23
29
  api_call = self.execute(path: PATHS[:incident], http_method: 'post', payload: payload)
24
30
  api_call
25
31
  end
26
32
 
33
+ # Find incident by ID
27
34
  def find_incident(id: nil)
28
35
  path = "incidents/#{id}.json"
29
36
  api_call = self.execute(path: path)
30
37
  api_call
31
38
  end
32
39
 
40
+ # Update an incident given id and json
33
41
  def update_incident(payload: nil, id: nil, options: {})
34
42
  path = "incidents/#{id}.json"
35
43
  api_call = self.execute(path: path, http_method: 'put', payload: payload)
@@ -1,11 +1,14 @@
1
1
  module Samanage
2
2
  class Api
3
+
4
+ # Default get other_assets path
3
5
  def get_other_assets(path: PATHS[:other_asset], options: {})
4
6
  url = Samanage::UrlBuilder.new(path: path, options: options).url
5
7
  api_call = self.execute(path: url)
6
8
  api_call
7
9
  end
8
10
 
11
+ # Returns all other assets
9
12
  def collect_other_assets
10
13
  page = 1
11
14
  other_assets = Array.new
@@ -20,17 +23,22 @@ module Samanage
20
23
  other_assets.uniq
21
24
  end
22
25
 
26
+
27
+ # Create an other_asset given json
23
28
  def create_other_asset(payload: nil, options: {})
24
29
  api_call = self.execute(path: PATHS[:other_asset], http_method: 'post', payload: payload)
25
30
  api_call
26
31
  end
27
32
 
33
+
34
+ # Find other_asset by id
28
35
  def find_other_asset(id: nil)
29
36
  path = "other_assets/#{id}.json"
30
37
  api_call = self.execute(path: path)
31
38
  api_call
32
39
  end
33
40
 
41
+ # Update other_asset given json and id
34
42
  def update_other_asset(payload: nil, id: nil, options: {})
35
43
  path = "other_assets/#{id}.json"
36
44
  api_call = self.execute(path: path, http_method: 'put', payload: payload)
@@ -1,6 +1,7 @@
1
1
  module Samanage
2
2
  class Api
3
- def get_requester_id(value: nil, name: nil, email: nil)
3
+ # Get requester from value (email)
4
+ def get_requester_id(value: nil)
4
5
  api_call = self.execute(path: "requesters.json?name=#{value}")
5
6
  requester = api_call[:data].size == 1 ? api_call[:data][0] : nil
6
7
  requester
@@ -1,6 +1,8 @@
1
1
  module Samanage
2
2
  class Api
3
3
 
4
+
5
+ # Get users, using URL builder
4
6
  def get_users(path: PATHS[:user], options: {})
5
7
  url = Samanage::UrlBuilder.new(path: path, options: options).url
6
8
  api_call = self.execute(path: url)
@@ -20,19 +22,20 @@ module Samanage
20
22
  users
21
23
  end
22
24
 
25
+ # Create user given JSON
23
26
  def create_user(payload: nil, options: {})
24
27
  api_call = self.execute(path: PATHS[:user], http_method: 'post', payload: payload)
25
28
  api_call
26
29
  end
27
30
 
28
- # Find user by id
31
+ # Return user by ID
29
32
  def find_user(id: nil)
30
33
  path = "users/#{id}.json"
31
34
  api_call = self.execute(path: path)
32
35
  api_call
33
36
  end
34
37
 
35
- # Email is unique so compare first for exact match only. Return [nil..id]
38
+ # Email is unique so compare first for exact match only. Returns nil or the id
36
39
  def find_user_id_by_email(email: nil)
37
40
  api_call = self.check_user(value: email)
38
41
  api_call.dig(:data).first.to_h.dig('email').to_s.downcase == email.to_s.downcase ? api_call.dig(:data).first.dig('id') : nil
data/lib/samanage/api.rb CHANGED
@@ -9,13 +9,18 @@ module Samanage
9
9
  custom_forms: 'custom_forms.json',
10
10
  }
11
11
  attr_accessor :datacenter, :content_type, :base_url, :token, :custom_forms, :authorized, :admins
12
- def initialize(token: nil, dacenter: nil, development_mode: false)
12
+
13
+ # Development mode forzes authorization & prepopulates custom forms/fields and admins
14
+ # datacenter should equal 'eu' or blank
15
+ def initialize(token: nil, datacenter: nil, development_mode: false)
13
16
  self.token = token if token
17
+ if !datacenter.nil? && datacenter.to_s.downcase != 'eu'
18
+ datacenter = nil
19
+ end
14
20
  self.datacenter = datacenter if datacenter
15
21
  self.base_url = "https://api#{datacenter}.samanage.com/"
16
22
  self.content_type = 'json'
17
23
  self.admins = []
18
- # Development mode forzes authorization & prepopulates custom forms/fields and admins
19
24
  if development_mode
20
25
  if self.authorized? != true
21
26
  self.authorize
@@ -29,6 +34,7 @@ module Samanage
29
34
  self.authorized
30
35
  end
31
36
 
37
+ # Check token against api.json
32
38
  def authorize
33
39
  self.execute(path: 'api.json')
34
40
  rescue OpenSSL::SSL::SSLError => e
@@ -38,7 +44,7 @@ module Samanage
38
44
  self.authorized = true
39
45
  end
40
46
 
41
- # Defaults to GET
47
+ # Calling execute without a method defaults to GET
42
48
  def execute(http_method: 'get', path: nil, payload: nil, verbose: nil, ssl_fix: false, token: nil)
43
49
  token = token ||= self.token
44
50
  unless verbose.nil?
@@ -98,6 +104,8 @@ module Samanage
98
104
  response
99
105
  end
100
106
 
107
+
108
+ # Return all admins in the account
101
109
  def list_admins
102
110
  admin_role_id = self.execute(path: 'roles.json').select{|role| role['name'] == 'Administrator'}['id']
103
111
  self.admins.push(
@@ -12,16 +12,12 @@ module Samanage
12
12
  end
13
13
 
14
14
  # API Errors
15
- class SamanageError < Error
16
- end
15
+ class SamanageError < Error; end
17
16
 
18
- class AuthorizationError < SamanageError
19
- end
17
+ class AuthorizationError < SamanageError; end
20
18
 
21
- class InvalidRequest < SamanageError
22
- end
19
+ class InvalidRequest < SamanageError; end
23
20
 
24
- class NotFound < SamanageError
25
- end
21
+ class NotFound < SamanageError; end
26
22
 
27
23
  end
@@ -2,6 +2,7 @@ module Samanage
2
2
  class UrlBuilder
3
3
  attr_accessor :url
4
4
  @url = ''
5
+
5
6
  def initialize(path: nil,options: nil)
6
7
  self.url = map_path(path: path, options: options)
7
8
  return url
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.7'
4
+ s.version = '1.6.8'
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!"
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.6.7
4
+ version: 1.6.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Walls
@@ -50,6 +50,7 @@ files:
50
50
  - Guardfile
51
51
  - LICENSE
52
52
  - README.md
53
+ - changelog.txt
53
54
  - lib/samanage.rb
54
55
  - lib/samanage/api.rb
55
56
  - lib/samanage/api/comments.rb