samanage 2.1.16 → 2.1.18

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: 3ba9d49fb26927fd2cf98b118da982990a5ffb64
4
- data.tar.gz: 976b9b27dd7174d1b8e7d820d46c522122ad7aa3
3
+ metadata.gz: ffc172624f62a1fd88be55e019f8e60e578a74c1
4
+ data.tar.gz: a5ffc35b4b1b15c7e57f7ff41cab78915790b936
5
5
  SHA512:
6
- metadata.gz: 9f99a5ba09aa8f979df8211a43449588ce94429abda7df8ecfe6f2126e7493c6ece8d8a965ee67be9e33ddd3cbd859bfc9935d63bfecb7173372204e3a214e9a
7
- data.tar.gz: 64c92b5d364400c5ce6ded2c2d7b5c0f9056193aa0369daa40b5d35377500d6e33e7f4177f4ad4828fc4135180205a6a08b6d78d20cd545ccfab4cfb873c41bf
6
+ metadata.gz: 2ba6fa8ce196713d263785ed9a45ea8e303b34c1134cc8a24b7cbdfe870d85d6e157a7f3b1d8825a0967bfe0f1256f4b7365de4a313cbf5fe53b3e1b8832c6df
7
+ data.tar.gz: ac4fcd8180ddb9beb45a5c6bf360be90bb459616d645ec8d51b8c693db2291af7e7ae2bbd0189069f02dde940ab6c8d859eef6806f6718e90bc50d86a78415a5
@@ -1,3 +1,14 @@
1
+ ### 2.1.18
2
+ - Force multipart for attachments
3
+ - Custom sleep time
4
+ - Added catching all errors
5
+ - Normalizing stout
6
+
7
+ ### 2.1.17
8
+ - Retry all errors
9
+ - Ability to configure retry count & wait time.
10
+ - Normalize messages
11
+
1
12
  ### 2.1.16
2
13
  - Use options where callbacks could be sent
3
14
 
@@ -3,8 +3,7 @@ require 'open-uri'
3
3
  module Samanage
4
4
  class Api
5
5
  include HTTParty
6
- attr_accessor :datacenter, :content_type, :base_url, :token, :custom_forms, :authorized, :admins, :max_retries
7
- MAX_RETRIES = 3
6
+ attr_accessor :datacenter, :content_type, :base_url, :token, :custom_forms, :authorized, :admins, :max_retries, :sleep_time
8
7
  PATHS = {
9
8
  attachment: 'attachments.json',
10
9
  category: 'categories.json',
@@ -28,7 +27,7 @@ module Samanage
28
27
  }
29
28
  # Development mode forces authorization & pre-populates admins and custom forms / fields
30
29
  # datacenter should equal 'eu' or blank
31
- def initialize(token: , datacenter: nil, development_mode: false, max_retries: MAX_RETRIES, content_type: 'json')
30
+ def initialize(token: , datacenter: nil, development_mode: false, max_retries: 3, content_type: 'json', sleep_time: 5)
32
31
  self.token = token
33
32
  if !datacenter.nil? && datacenter.to_s.downcase != 'eu'
34
33
  datacenter = nil
@@ -38,6 +37,7 @@ module Samanage
38
37
  self.content_type = content_type || 'json'
39
38
  self.admins = []
40
39
  self.max_retries = max_retries
40
+ self.sleep_time = sleep_time
41
41
  if development_mode
42
42
  if self.authorized? != true
43
43
  self.authorize
@@ -58,7 +58,7 @@ module Samanage
58
58
  end
59
59
 
60
60
  # Calling execute without a method defaults to GET
61
- def execute(http_method: 'get', path: nil, payload: nil, verbose: nil, headers: {}, options: {})
61
+ def execute(http_method: 'get', path: nil, payload: nil, verbose: nil, headers: {}, options: {}, multipart: false)
62
62
  if payload.class == Hash && self.content_type == 'json'
63
63
  begin
64
64
  if path != 'attachments.json'
@@ -87,7 +87,7 @@ module Samanage
87
87
  when 'get'
88
88
  api_call = self.class.get(full_path, headers: headers, query: options)
89
89
  when 'post'
90
- api_call = self.class.post(full_path, body: payload, headers: headers, query: options)
90
+ api_call = self.class.post(full_path, multipart: multipart, body: payload, headers: headers, query: options)
91
91
  when 'put'
92
92
  api_call = self.class.put(full_path, body: payload, headers: headers, query: options)
93
93
  when 'delete'
@@ -95,14 +95,28 @@ module Samanage
95
95
  else
96
96
  raise Samanage::Error.new(response: {response: 'Unknown HTTP method'})
97
97
  end
98
- rescue Errno::ECONNREFUSED, Net::OpenTimeout, Errno::ETIMEDOUT, OpenSSL::SSL::SSLError, Errno::ENETDOWN, Errno::ECONNRESET, Errno::ENOENT, EOFError, Net::HTTPTooManyRequests, SocketError => e
99
- puts "[Warning] #{e.class}: #{e} - Retry: #{retries}/#{self.max_retries}"
100
- sleep 5
98
+ rescue Errno::ECONNREFUSED, Net::OpenTimeout, Errno::ETIMEDOUT, Net::ReadTimeout, OpenSSL::SSL::SSLError, Errno::ENETDOWN, Errno::ECONNRESET, Errno::ENOENT, EOFError, Net::HTTPTooManyRequests, SocketError => e
101
99
  retries += 1
102
- retry if retries < self.max_retries
103
- error = e
104
- response = e.class
105
- raise Samanage::InvalidRequest.new(error: error, response: response)
100
+ if retries < self.max_retries
101
+ puts "[Warning] #{e.class}: #{e} - Retry: #{retries}/#{self.max_retries}"
102
+ sleep sleep_time
103
+ retry
104
+ else
105
+ error = e
106
+ response = e.class
107
+ raise Samanage::InvalidRequest.new(error: error, response: response)
108
+ end
109
+ rescue => e
110
+ retries += 1
111
+ if retries < self.max_retries
112
+ puts "[Warning] #{e.class}: #{e} - Retry: #{retries}/#{self.max_retries}"
113
+ sleep sleep_time
114
+ retry
115
+ else
116
+ error = e
117
+ response = e.class
118
+ raise Samanage::InvalidRequest.new(error: error, response: response)
119
+ end
106
120
  end
107
121
 
108
122
  response = Hash.new
@@ -26,17 +26,17 @@ module Samanage
26
26
  req = self.execute(
27
27
  path: 'attachments.json',
28
28
  http_method: 'post',
29
+ multipart: true,
29
30
  payload: {
30
31
  'file[attachable_type]' => attachable_type,
31
32
  'file[attachable_id]' => attachable_id,
32
- 'file[attachment]' => file = File.open(filepath, 'r')
33
+ 'file[attachment]' => File.open(filepath, 'rb')
33
34
  },
34
35
  headers: {
35
36
  'Content-Type' => 'multipart/form-data',
36
37
  'X-Samanage-Authorization' => 'Bearer ' + self.token
37
38
  }
38
39
  )
39
- file.close
40
40
  req
41
41
  end
42
42
 
@@ -18,7 +18,7 @@ module Samanage
18
18
  1.upto(total_pages) do |page|
19
19
  options[:page] = page
20
20
 
21
- puts "Collecting changes page: #{page}/#{total_pages}" if options[:verbose]
21
+ puts "Collecting Changes page: #{page}/#{total_pages}" if options[:verbose]
22
22
  path = "changes.json?"
23
23
  request = self.execute(http_method: 'get', path: path, options: options)
24
24
  request[:data].each do |change|
@@ -15,7 +15,7 @@ module Samanage
15
15
  1.upto(total_pages) do |page|
16
16
  options[:page] = page
17
17
 
18
- puts "Collecting contracts page: #{page}/#{total_pages}" if options[:verbose]
18
+ puts "Collecting Contracts page: #{page}/#{total_pages}" if options[:verbose]
19
19
  path = "contracts.json?"
20
20
  self.execute(path: path, options: options)[:data].each do |contract|
21
21
  if block_given?
@@ -16,7 +16,7 @@ module Samanage
16
16
  def collect_incidents(options: {})
17
17
  incidents = Array.new
18
18
  total_pages = self.get_incidents(options: options.except(:audit_archives,:audit_archive,:layout))[:total_pages]
19
- puts "Pulling Incidents with Audit Archives (this may take a while)" if options[:audit_archives] && options[:verbose]
19
+ puts "Requesting Incidents with Audit Archives (this may take a while)" if options[:audit_archives] && options[:verbose]
20
20
  1.upto(total_pages) do |page|
21
21
  puts "Collecting Incidents page: #{page}/#{total_pages}" if options[:verbose]
22
22
  if options[:audit_archives]
@@ -34,7 +34,7 @@ module Samanage
34
34
  end
35
35
 
36
36
  # Find mobile given id
37
- def find_mobile(id: nil)
37
+ def find_mobile(id: , options: {})
38
38
  path = "mobiles/#{id}.json"
39
39
  self.execute(path: path)
40
40
  end
@@ -19,7 +19,7 @@ module Samanage
19
19
  1.upto(total_pages) do |page|
20
20
  options[:page] = page
21
21
 
22
- puts "Collecting problems page: #{page}/#{total_pages}" if options[:verbose]
22
+ puts "Collecting Problems page: #{page}/#{total_pages}" if options[:verbose]
23
23
  path = "problems.json?"
24
24
  request = self.execute(http_method: 'get', path: path, options: options)
25
25
  request[:data].each do |problem|
@@ -19,7 +19,7 @@ module Samanage
19
19
  1.upto(total_pages) do |page|
20
20
  options[:page] = page
21
21
 
22
- puts "Collecting purchase_orders page: #{page}/#{total_pages}" if options[:verbose]
22
+ puts "Collecting Purchase Orders page: #{page}/#{total_pages}" if options[:verbose]
23
23
  path = "purchase_orders.json?"
24
24
  request = self.execute(http_method: 'get', path: path, options: options)
25
25
  request[:data].each do |purchase_order|
@@ -24,6 +24,12 @@ module Samanage
24
24
  solutions
25
25
  end
26
26
 
27
+ def find_solution(id: , options: {})
28
+ path = "solutions/#{id}.json"
29
+ self.execute(path: path)
30
+ end
31
+
32
+
27
33
  def create_solution(payload: , options: {})
28
34
  self.execute(path: PATHS[:solution], http_method: 'post', payload: payload)
29
35
  end
@@ -12,7 +12,7 @@ module Samanage
12
12
  1.upto(total_pages) do |page|
13
13
  options[:page] = page
14
14
 
15
- puts "Collecting vendors page: #{page}/#{total_pages}" if options[:verbose]
15
+ puts "Collecting Vendors page: #{page}/#{total_pages}" if options[:verbose]
16
16
  path = "vendors.json?"
17
17
  self.execute(http_method: 'get', path: path, options: options)[:data].each do |vendor|
18
18
  if block_given?
@@ -1,3 +1,3 @@
1
1
  module Samanage
2
- VERSION = '2.1.16'
2
+ VERSION = '2.1.18'
3
3
  end
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: 2.1.16
4
+ version: 2.1.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Walls
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-14 00:00:00.000000000 Z
11
+ date: 2019-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty