samanage 1.4 → 1.5.1

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: 21e28bd62a0f17cc2b426165860747bfe145e562
4
- data.tar.gz: b7e4d2fb72833801da8318f3d49491cb697a1174
3
+ metadata.gz: 3e49ce72a751f5236319e16bc11da84747b6af2b
4
+ data.tar.gz: b919e086c1293a6253ff9b365d0331962c25378c
5
5
  SHA512:
6
- metadata.gz: 603aa9412cd806ab8955b3be593371de94a2f26321542f4d3d7db904e324374f8e71f545643325684a3c3a919e8bd5a5731b86255f51dcc48cd13a1effd0de2a
7
- data.tar.gz: eaaab71b6d781898805469177bfbd1a2a00396981839ed350e788d79f23bfbcec141088d38a1c78e481a2e9278dbe1b86d5afb214ea97b7c78f3fe561fa836df
6
+ metadata.gz: 9056b29ff625771ac418e12ec935e7f089f411b0e52d6561d827d32954e3bc0c76e215e8391a1522d7267d4d615f2e4405d2ebbdd4ca486b2a44ac2e0015314d
7
+ data.tar.gz: cd9fcee69f53de525ee2a519e89c9d114a14a2aa7a51931287e906e4842cac216fb9658cf43c8d68304634b88cef829fd805a576bdd37bedb34f483f385347ee
data/lib/samanage/api.rb CHANGED
@@ -9,7 +9,7 @@ module Samanage
9
9
  custom_forms: 'custom_forms.json',
10
10
  }
11
11
  attr_accessor :datacenter, :content_type, :base_url, :token, :custom_forms
12
- def initialize(token: , dacenter: '', development_mode: false)
12
+ def initialize(token: '', dacenter: '', development_mode: false)
13
13
  self.token = token
14
14
  self.datacenter = nil || datacenter
15
15
  self.base_url = "https://api#{datacenter}.samanage.com/"
@@ -22,11 +22,15 @@ module Samanage
22
22
  end
23
23
 
24
24
  def authorize
25
- self.execute(path: 'api.json')
25
+ self.execute(path: 'api.json')
26
+ rescue OpenSSL::SSL::SSLError => e
27
+ puts "Raised: #{e} #{e.class}"
28
+ puts 'Disabling Local SSL Verification'
29
+ self.execute(path: 'api.json', ssl_fix: true)
26
30
  end
27
31
 
28
32
  # Defaults to GET
29
- def execute(http_method: 'get', path: , payload: nil, verbose: nil)
33
+ def execute(http_method: 'get', path: nil, payload: nil, verbose: nil, ssl_fix: false)
30
34
  unless verbose.nil?
31
35
  verbose = '?layout=long'
32
36
  end
@@ -36,7 +40,11 @@ module Samanage
36
40
  'Content-type' => "application/#{self.content_type}",
37
41
  'X-Samanage-Authorization' => 'Bearer ' + self.token
38
42
  )
39
- api_call = api_call.public_send(http_method.to_sym, self.base_url + Addressable::URI.encode_component(path, Addressable::URI::CharacterClasses::QUERY).gsub('+',"%2B"), :body => payload)
43
+ ctx = OpenSSL::SSL::SSLContext.new
44
+ if ssl_fix
45
+ ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE
46
+ end
47
+ api_call = api_call.public_send(http_method.to_sym, self.base_url + Addressable::URI.encode_component(path, Addressable::URI::CharacterClasses::QUERY).gsub('+',"%2B"), :body => payload, ssl_context: ctx)
40
48
  response = Hash.new
41
49
  response[:code] = api_call.code.to_i
42
50
  response[:json] = api_call.body
@@ -31,7 +31,7 @@ module Samanage
31
31
  }
32
32
  }
33
33
  end
34
- def form_for(object_type: )
34
+ def form_for(object_type: nil)
35
35
  if self.custom_forms == nil
36
36
  self.custom_forms = self.organize_forms
37
37
  end
@@ -19,12 +19,12 @@ module Samanage
19
19
  hardwares
20
20
  end
21
21
 
22
- def create_hardware(payload: , options: {})
22
+ def create_hardware(payload: nil, options: {})
23
23
  api_call = self.execute(path: PATHS[:hardware], http_method: 'post', payload: payload)
24
24
  api_call
25
25
  end
26
26
 
27
- def find_hardware(id: )
27
+ def find_hardware(id: nil)
28
28
  path = "hardwares/#{id}.json"
29
29
  api_call = self.execute(path: path)
30
30
  api_call
@@ -38,7 +38,7 @@ module Samanage
38
38
  end
39
39
 
40
40
 
41
- def update_hardware(payload:, id:, options: {})
41
+ def update_hardware(payload: nil, id:, options: {})
42
42
  path = "hardwares/#{id}.json"
43
43
  api_call = self.execute(path: path, http_method: 'put', payload: payload)
44
44
  api_call
@@ -24,13 +24,13 @@ module Samanage
24
24
  api_call
25
25
  end
26
26
 
27
- def find_incident(id: )
27
+ def find_incident(id: nil)
28
28
  path = "incidents/#{id}.json"
29
29
  api_call = self.execute(path: path)
30
30
  api_call
31
31
  end
32
32
 
33
- def update_incident(payload:, id:, options: {})
33
+ def update_incident(payload: nil, id: nil, options: {})
34
34
  path = "incidents/#{id}.json"
35
35
  api_call = self.execute(path: path, http_method: 'put', payload: payload)
36
36
  api_call
@@ -25,13 +25,13 @@ module Samanage
25
25
  api_call
26
26
  end
27
27
 
28
- def find_other_asset(id: )
28
+ def find_other_asset(id: nil)
29
29
  path = "other_assets/#{id}.json"
30
30
  api_call = self.execute(path: path)
31
31
  api_call
32
32
  end
33
33
 
34
- def update_other_asset(payload:, id:, options: {})
34
+ def update_other_asset(payload: nil, id: nil, options: {})
35
35
  path = "other_assets/#{id}.json"
36
36
  api_call = self.execute(path: path, http_method: 'put', payload: payload)
37
37
  api_call
@@ -1,6 +1,6 @@
1
1
  module Samanage
2
2
  class Api
3
- def get_requester_id(value: )
3
+ def get_requester_id(value: nil)
4
4
  api_call = self.execute(path: "requesters.json?name=#{value}")
5
5
  requester = api_call[:data].size == 1 ? api_call[:data][0] : nil
6
6
  requester
@@ -21,24 +21,24 @@ module Samanage
21
21
  users
22
22
  end
23
23
 
24
- def create_user(payload: , options: {})
24
+ def create_user(payload: nil, options: {})
25
25
  api_call = self.execute(path: PATHS[:user], http_method: 'post', payload: payload)
26
26
  api_call
27
27
  end
28
28
 
29
- def find_user(id: )
29
+ def find_user(id: nil)
30
30
  path = "users/#{id}.json"
31
31
  api_call = self.execute(path: path)
32
32
  api_call
33
33
  end
34
34
 
35
- def check_user(field: 'email', value: )
35
+ def check_user(field: 'email', value: nil)
36
36
  url = "users.json?#{field}=#{value}"
37
37
  api_call = self.execute(path: url)
38
38
  api_call
39
39
  end
40
40
 
41
- def update_user(payload:, id:)
41
+ def update_user(payload: nil, id: nil)
42
42
  path = "users/#{id}.json"
43
43
  puts "Path: #{path}"
44
44
  api_call = self.execute(path: path, http_method: 'put', payload: payload)
@@ -1,7 +1,7 @@
1
1
  module Samanage
2
2
  class Error < StandardError
3
3
  attr_accessor :status_code, :response, :error
4
- def initialize(error: , response: {})
4
+ def initialize(error: nil, response: {})
5
5
  self.status_code = response[:code]
6
6
  self.response = response[:data] ||= response[:response]
7
7
  self.error = error
@@ -2,7 +2,7 @@ module Samanage
2
2
  class UrlBuilder
3
3
  attr_accessor :url
4
4
  @url = ''
5
- def initialize(path: ,options: nil)
5
+ def initialize(path: nil,options: nil)
6
6
  self.url = map_path(path, options)
7
7
  return url
8
8
  end
data/samanage.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'samanage'
3
- s.version = '1.4'
3
+ s.version = '1.5.1'
4
4
  s.date = '2017-01-01'
5
5
  s.summary = "Samanage Ruby Gem"
6
6
  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.4'
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Walls