samanage 1.9.3 → 1.9.31

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a2546bcfadc5336181263358272703e0d622350a
4
- data.tar.gz: 2ca8fd46211877fd877c2a52c015df8f4364af66
3
+ metadata.gz: bd9c36e5b7dcfa8533463d1efaaf094aaca7c142
4
+ data.tar.gz: 2d262cf6d6080c799332dbd2121e744b54c829dd
5
5
  SHA512:
6
- metadata.gz: cf23a86735c95112bb0a02d7c5e7c3fe8868870814684105ef31455e5cfbb0083b909285882ec796452f110aec1cbb5baf086efcd3533fdb7a21f18c824a9ed8
7
- data.tar.gz: e7d3f6dc216f39f6ad33bba025dc8c13135cf94668503d1a709bb7957038814ea0b10cb9b0117c8040f939a3e53b9f3dfae6a8d797e4250b77f1307961fd09e0
6
+ metadata.gz: d04babd705aea3f93c6bbbaf08c61c1adde2dee78748025996a4d0ad236bc5b6111bb7cb98289ce2798f187d03151ad95dded037a5c5b6ade657904f3acaf32b
7
+ data.tar.gz: 0a398b707e8dd4629f6d81ce06eb59523a1f94a68882ecf06d5cd517dd06bb683d467b63d78aa7a1f285f15289361d6279c31ec43d70e643700fd763d6a2c630
data/changelog.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 1.9.31
2
+ - Alias original comment method
3
+ - Remove (keyword: nil)
4
+ - Collapse error retry output
5
+
1
6
  # 1.9.3
2
7
  - Handle HTTP Read Timeout
3
8
 
data/lib/samanage/api.rb CHANGED
@@ -19,7 +19,7 @@ module Samanage
19
19
  ssl_ca_file "#{File.expand_path('..')}/data/cacert.pem"
20
20
  attr_accessor :datacenter, :content_type, :base_url, :token, :custom_forms, :authorized, :admins, :max_retries
21
21
 
22
- # Development mode forzes authorization & prepopulates custom forms/fields and admins
22
+ # Development mode forces authorization & pre-populates admins and custom forms / fields
23
23
  # datacenter should equal 'eu' or blank
24
24
  def initialize(token: , datacenter: nil, development_mode: false, max_retries: MAX_RETRIES)
25
25
  self.token = token
@@ -93,9 +93,8 @@ module Samanage
93
93
  else
94
94
  raise Samanage::Error.new(response: {response: 'Unknown HTTP method'})
95
95
  end
96
- rescue Errno::ECONNREFUSED, Net::OpenTimeout, Net::ReadTimeout, Errno::ETIMEDOUT, OpenSSL::SSL::SSLError => e
97
- puts "Error: #{e} - #{e.class}"
98
- puts "Retry: #{retries}/#{self.max_retries}"
96
+ rescue Errno::ECONNREFUSED, Net::OpenTimeout, Errno::ETIMEDOUT, OpenSSL::SSL::SSLError => e
97
+ puts "Error:[#{e.class}] #{e} - Retry: #{retries}/#{self.max_retries}"
99
98
  sleep 3
100
99
  retries += 1
101
100
  retry if retries < self.max_retries
@@ -9,25 +9,12 @@ module Samanage
9
9
  end
10
10
 
11
11
  # Add a new comment
12
- def create_comment(incident_id: nil, comment: nil, options: {})
12
+ def create_comment(incident_id: , comment: , options: {})
13
13
  path = "incidents/#{incident_id}/comments.json"
14
14
  self.execute(http_method: 'post', path: path, payload: comment)
15
15
  end
16
16
 
17
- # Return all comments from the incident_id
18
- def collect_comments(incident_id: nil)
19
17
 
20
- page = 1
21
- max_pages = 5
22
- comments = Array.new
23
- while page <= max_pages
24
- path = "incidents/#{incident_id}/comments.json?page=#{page}"
25
- comments += self.execute(path: path)[:data]
26
- page += 1
27
- end
28
- comments
29
- end
30
-
31
- alias_method :comments, :collect_comments
18
+ alias_method :comments, :get_comments
32
19
  end
33
20
  end
@@ -20,12 +20,12 @@ module Samanage
20
20
  end
21
21
 
22
22
  # Create contract given json payload
23
- def create_contract(payload: nil, options: {})
23
+ def create_contract(payload: , options: {})
24
24
  self.execute(path: PATHS[:contract], http_method: 'post', payload: payload)
25
25
  end
26
26
 
27
27
  # Find contract given id
28
- def find_contract(id: nil)
28
+ def find_contract(id: )
29
29
  path = "contracts/#{id}.json"
30
30
  self.execute(path: path)
31
31
  end
@@ -37,12 +37,12 @@ module Samanage
37
37
  end
38
38
 
39
39
  # Update contract given id
40
- def update_contract(payload: nil, id: nil, options: {})
40
+ def update_contract(payload: , id: , options: {})
41
41
  path = "contracts/#{id}.json"
42
42
  self.execute(path: path, http_method: 'put', payload: payload)
43
43
  end
44
44
 
45
- def add_item_to_contract(id: nil, payload: nil)
45
+ def add_item_to_contract(id: , payload: )
46
46
  path = "contracts/#{id}/items.json"
47
47
  self.execute(path: path, http_method: 'post', payload: payload)
48
48
  end
@@ -17,7 +17,7 @@ module Samanage
17
17
  departments
18
18
  end
19
19
 
20
- def create_department(payload: nil, options: {})
20
+ def create_department(payload: , options: {})
21
21
  self.execute(path: PATHS[:department], http_method: 'post', payload: payload)
22
22
 
23
23
  end
@@ -16,23 +16,23 @@ module Samanage
16
16
  groups
17
17
  end
18
18
 
19
- def create_group(payload: nil, options: {})
19
+ def create_group(payload: , options: {})
20
20
  self.execute(path: PATHS[:group], http_method: 'post', payload: payload)
21
21
  end
22
22
 
23
- def find_group_id_by_name(group: nil)
23
+ def find_group_id_by_name(group: )
24
24
  group_api = self.execute(path: "groups.json?name=#{group}")
25
25
  if !group_api[:data].empty? && group == group_api[:data].first['name']
26
26
  return group_api[:data].first['id']
27
27
  end
28
28
  end
29
29
 
30
- def find_group(id: nil)
30
+ def find_group(id: )
31
31
  path = "groups/#{id}.json"
32
32
  self.execute(path: path)
33
33
  end
34
34
 
35
- def add_member_to_group(email: nil, group_id: nil, group_name: nil)
35
+ def add_member_to_group(email: , group_id: nil, group_name: nil)
36
36
  group_id = group_id ||= self.find_group_id_by_name(group: group_name)
37
37
  user_id = self.find_user_id_by_email(email: email)
38
38
  member_path = "memberships.json?group_id=#{group_id}.json&user_ids=#{user_id}"
@@ -20,18 +20,18 @@ module Samanage
20
20
  end
21
21
 
22
22
  # Create hardware given json payload
23
- def create_hardware(payload: nil, options: {})
23
+ def create_hardware(payload: , options: {})
24
24
  self.execute(path: PATHS[:hardware], http_method: 'post', payload: payload)
25
25
  end
26
26
 
27
27
  # Find hardware given id
28
- def find_hardware(id: nil)
28
+ def find_hardware(id: )
29
29
  path = "hardwares/#{id}.json"
30
30
  self.execute(path: path)
31
31
  end
32
32
 
33
33
  # Find hardware given a serial number
34
- def find_hardwares_by_serial(serial_number: nil)
34
+ def find_hardwares_by_serial(serial_number: )
35
35
  path = "hardwares.json?serial_number[]=#{serial_number}"
36
36
  self.execute(path: path)
37
37
  end
@@ -44,7 +44,7 @@ module Samanage
44
44
  end
45
45
 
46
46
  # Update hardware given id
47
- def update_hardware(payload: nil, id: nil, options: {})
47
+ def update_hardware(payload: , id: , options: {})
48
48
  path = "hardwares/#{id}.json"
49
49
  self.execute(path: path, http_method: 'put', payload: payload)
50
50
  end
@@ -14,8 +14,8 @@ module Samanage
14
14
  # - layout: 'long'
15
15
  def collect_incidents(options: {})
16
16
  incidents = Array.new
17
- total_pages = self.get_incidents(options: options)[:total_pages]
18
- puts "Pulling Incidents with Audit Archives (this may take some time)" if options[:audit_archives] && options[:verbose]
17
+ total_pages = self.get_incidents[:total_pages]
18
+ puts "Pulling Incidents with Audit Archives (this may take a while)" if options[:audit_archives] && options[:verbose]
19
19
  1.upto(total_pages) do |page|
20
20
  puts "Collecting Incidents page: #{page}/#{total_pages}" if options[:verbose]
21
21
  if options[:audit_archives]
@@ -27,9 +27,7 @@ module Samanage
27
27
  end
28
28
  else
29
29
  layout = options[:layout] == 'long' ? '&layout=long' : nil
30
- options[:page] = page
31
- puts "options: #{options}"
32
- incidents += self.get_incidents(options: options)[:data]
30
+ incidents += self.execute(http_method: 'get', path: "incidents.json?page=#{page}#{layout}")[:data]
33
31
  end
34
32
  end
35
33
  incidents
@@ -42,13 +40,13 @@ module Samanage
42
40
  end
43
41
 
44
42
  # Find incident by ID
45
- def find_incident(id: nil)
43
+ def find_incident(id: )
46
44
  path = "incidents/#{id}.json"
47
45
  self.execute(path: path)
48
46
  end
49
47
 
50
48
  # Update an incident given id and json
51
- def update_incident(payload: nil, id: nil, options: {})
49
+ def update_incident(payload: , id: , options: {})
52
50
  path = "incidents/#{id}.json"
53
51
  self.execute(path: path, http_method: 'put', payload: payload)
54
52
  end
@@ -37,7 +37,7 @@ module Samanage
37
37
  end
38
38
 
39
39
  # Update mobile given id
40
- def update_mobile(payload: nil, id: nil, options: {})
40
+ def update_mobile(payload: , id: , options: {})
41
41
  path = "mobiles/#{id}.json"
42
42
  self.execute(path: path, http_method: 'put', payload: payload)
43
43
  end
@@ -22,19 +22,19 @@ module Samanage
22
22
 
23
23
 
24
24
  # Create an other_asset given json
25
- def create_other_asset(payload: nil, options: {})
25
+ def create_other_asset(payload: , options: {})
26
26
  self.execute(path: PATHS[:other_asset], http_method: 'post', payload: payload)
27
27
  end
28
28
 
29
29
 
30
30
  # Find other_asset by id
31
- def find_other_asset(id: nil)
31
+ def find_other_asset(id: )
32
32
  path = "other_assets/#{id}.json"
33
33
  self.execute(path: path)
34
34
  end
35
35
 
36
36
  # Update other_asset given json and id
37
- def update_other_asset(payload: nil, id: nil, options: {})
37
+ def update_other_asset(payload: , id: , options: {})
38
38
  path = "other_assets/#{id}.json"
39
39
  self.execute(path: path, http_method: 'put', payload: payload)
40
40
  end
@@ -1,7 +1,7 @@
1
1
  module Samanage
2
2
  class Api
3
3
  # Get requester from value (email)
4
- def get_requester_id(value: nil)
4
+ def get_requester_id(value: )
5
5
  api_call = self.execute(path: "requesters.json?name=#{value}")
6
6
  api_call[:data].size == 1 ? api_call[:data][0] : nil
7
7
  end
@@ -16,7 +16,7 @@ module Samanage
16
16
  sites
17
17
  end
18
18
 
19
- def create_site(payload: nil, options: {})
19
+ def create_site(payload: , options: {})
20
20
  self.execute(path: PATHS[:site], http_method: 'post', payload: payload)
21
21
  end
22
22
 
@@ -20,12 +20,12 @@ module Samanage
20
20
  end
21
21
 
22
22
  # Create user given JSON
23
- def create_user(payload: nil, options: {})
23
+ def create_user(payload: , options: {})
24
24
  self.execute(path: PATHS[:user], http_method: 'post', payload: payload)
25
25
  end
26
26
 
27
27
  # Return user by ID
28
- def find_user(id: nil)
28
+ def find_user(id: )
29
29
  path = "users/#{id}.json"
30
30
  self.execute(path: path)
31
31
  end
@@ -50,16 +50,16 @@ module Samanage
50
50
  end
51
51
 
52
52
  # Check for user by field (ex: users.json?field=value)
53
- def check_user(field: 'email', value: nil)
53
+ def check_user(field: 'email', value: )
54
54
  if field.to_s.downcase == 'email'
55
- value = value.gsub("+",'%2B')
55
+ value = value.to_s.gsub("+",'%2B')
56
56
  end
57
57
  url = "users.json?#{field}=#{value}"
58
58
  self.execute(path: url)
59
59
  end
60
60
 
61
61
  # Update user by id
62
- def update_user(payload: nil, id: nil)
62
+ def update_user(payload: , id: )
63
63
  path = "users/#{id}.json"
64
64
  self.execute(path: path, http_method: 'put', payload: payload)
65
65
  end
@@ -1,3 +1,3 @@
1
1
  module Samanage
2
- VERSION = '1.9.3'
2
+ VERSION = '1.9.31'
3
3
  end
@@ -28,7 +28,7 @@ describe Samanage::Api do
28
28
 
29
29
  it 'collects all comments' do
30
30
  incident_id = @incidents.sample.dig('id')
31
- comments = @samanage.collect_comments(incident_id: incident_id)
31
+ comments = @samanage.comments(incident_id: incident_id)
32
32
  # Total count bug
33
33
  # expect(comments).to be(Array)
34
34
  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: 1.9.3
4
+ version: 1.9.31
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Walls
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-26 00:00:00.000000000 Z
11
+ date: 2018-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty