samanage 1.8.2 → 1.8.3

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: 3e3b9e74fc9dd73dbe2989f205691068facee01d
4
- data.tar.gz: e3114f63ef4ee17a0c3546da722f9a9ba0bce80b
3
+ metadata.gz: f1a73bd9d0ecff83e8c95ca29b389260d73eb3e7
4
+ data.tar.gz: b2a98bff4c554c017ac670f172981676a3ac9128
5
5
  SHA512:
6
- metadata.gz: 80cbe3721a4b62f9512501c9cd83d30a6a3eed9a2e7b2d752cf93b6bf66f53323c1db29b5efeb2168253c6c5f0767d59e9aa4d5aab1b97c6563be31658df9c1e
7
- data.tar.gz: aa249b7fb1dee0adb3a8b5d8839ab91452d7cb169e1121c14b0f6d858ba07b80bf2264d0df15f1365109bcceb853a911e28da13985856fc70352ce3f86c51887
6
+ metadata.gz: 0caa861127343267e8c33fe1a730acdf48a722244a2c9464178d9445d60576ed92e85ce9b1dd5cc1db7f53ec24590663cc8c8c35f61a4edbcdf91386f5874ccc
7
+ data.tar.gz: ddc7ad10f2e7f6f1642b08dd5d18d745d0956600b24fb6532a46c9049d83197e0098fdbc559aca3048b1874697edffe7dace52c57cc341bc0371d9ad43925a37
data/lib/samanage.rb CHANGED
@@ -17,7 +17,8 @@ require 'samanage/api/sites'
17
17
  require 'samanage/api/users'
18
18
  require 'samanage/error'
19
19
  require 'samanage/url_builder'
20
+ require 'samanage/version'
20
21
 
21
22
  module Samanage
22
- VERSION = '1.8.2'
23
+
23
24
  end
data/lib/samanage/api.rb CHANGED
@@ -1,9 +1,7 @@
1
1
  module Samanage
2
2
  class Api
3
3
  include HTTParty
4
- ssl_ca_file "#{File.expand_path('..')}/data/cacert.pem"
5
-
6
-
4
+ MAX_RETRIES = 3
7
5
  PATHS = {
8
6
  category: 'categories.json',
9
7
  custom_fields: 'custom_fields.json',
@@ -17,11 +15,13 @@ module Samanage
17
15
  site: 'sites.json',
18
16
  user: 'users.json',
19
17
  }
20
- attr_accessor :datacenter, :content_type, :base_url, :token, :custom_forms, :authorized, :admins
18
+ ssl_ca_file "#{File.expand_path('..')}/data/cacert.pem"
19
+ attr_accessor :datacenter, :content_type, :base_url, :token, :custom_forms, :authorized, :admins, :retries
21
20
 
22
21
  # Development mode forzes authorization & prepopulates custom forms/fields and admins
23
22
  # datacenter should equal 'eu' or blank
24
- def initialize(token: nil, datacenter: nil, development_mode: false)
23
+ def initialize(token: nil, datacenter: nil, development_mode: false, max_retries: MAX_RETRIES)
24
+ self.retries = 0
25
25
  self.token = token if token
26
26
  if !datacenter.nil? && datacenter.to_s.downcase != 'eu'
27
27
  datacenter = nil
@@ -73,14 +73,28 @@ module Samanage
73
73
  'Content-type' => "application/#{self.content_type}",
74
74
  'X-Samanage-Authorization' => 'Bearer ' + self.token
75
75
  }
76
+ @options = {
77
+ headers: headers,
78
+ payload: payload
79
+ }
76
80
  full_path = self.base_url + path
77
- case http_method.to_s.downcase
78
- when 'get'
79
- api_call = HTTParty.get(full_path, headers: headers)
80
- when 'post'
81
- api_call = HTTParty.post(full_path, query: payload, headers: headers)
82
- when 'put'
83
- api_call = HTTParty.put(full_path, query: payload, headers: headers)
81
+ begin
82
+ case http_method.to_s.downcase
83
+ when 'get'
84
+ api_call = self.class.get(full_path, headers: headers)
85
+ when 'post'
86
+ api_call = self.class.post(full_path, query: payload, headers: headers)
87
+ when 'put'
88
+ api_call = self.class.put(full_path, query: payload, headers: headers)
89
+ end
90
+ rescue Errno::ECONNREFUSED => e
91
+ puts "#{e} - #{e.class}"
92
+ puts "Retry: #{self.retries}/#{self.max_retries}"
93
+ self.retries += 1
94
+ retry if self.retries < self.max_retries
95
+ error = e
96
+ response = e.class
97
+ raise Samanage::InvalidRequest.new(error: error, response: response)
84
98
  end
85
99
 
86
100
  response = Hash.new
@@ -115,10 +129,6 @@ module Samanage
115
129
  error = response[:response]
116
130
  raise Samanage::InvalidRequest.new(error: error, response: response)
117
131
  end
118
- rescue Errno::ECONNREFUSED => e
119
- error = e
120
- response = e.class
121
- raise Samanage::InvalidRequest.new(error: error, response: response)
122
132
  end
123
133
 
124
134
 
@@ -39,7 +39,5 @@ module Samanage
39
39
  end
40
40
  self.custom_forms[object_type]
41
41
  end
42
-
43
- alias_method :custom_forms, :collect_custom_forms
44
42
  end
45
43
  end
@@ -0,0 +1,3 @@
1
+ module Samanage
2
+ VERSION = '1.8.3'
3
+ end
@@ -6,7 +6,6 @@ describe Samanage::Api do
6
6
  @controller = Samanage::Api.new(token: TOKEN)
7
7
  end
8
8
  it 'collects all categories' do
9
- puts "Category methods: #{@controller.methods}"
10
9
  categories = @controller.collect_categories
11
10
  expect(categories).to be_an(Array)
12
11
  end
@@ -24,7 +23,7 @@ describe Samanage::Api do
24
23
 
25
24
  expect(category_create[:data]['id']).to be_an(Integer)
26
25
  expect(category_create[:data]['name']).to eq(category_name)
27
- expect(category_create[:code]).to eq(201).or(200)
26
+ expect(category_create[:code]).to eq(200).or(201)
28
27
  end
29
28
  end
30
29
  end
@@ -27,7 +27,7 @@ describe Samanage do
27
27
  api_controller = Samanage::Api.new(token: TOKEN, development_mode: true)
28
28
  expect(api_controller).to be_an_instance_of(Samanage::Api)
29
29
  expect(api_controller.custom_forms).not_to be(nil)
30
- expect(api_controller.custom_forms).to be_a(Array)
30
+ expect(api_controller.custom_forms).to be_a(Hash)
31
31
  end
32
32
  it 'Fails with invalid token in development mode' do
33
33
  expect{ Samanage::Api.new(token: 'Invalid Token', development_mode: true)}.to raise_error(Samanage::AuthorizationError)
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.8.2
4
+ version: 1.8.3
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-12-15 00:00:00.000000000 Z
11
+ date: 2017-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -69,6 +69,7 @@ files:
69
69
  - lib/samanage/api/users.rb
70
70
  - lib/samanage/error.rb
71
71
  - lib/samanage/url_builder.rb
72
+ - lib/samanage/version.rb
72
73
  - samanage.gemspec
73
74
  - spec/api/samanage_category_spec.rb
74
75
  - spec/api/samanage_comments_spec.rb
@@ -106,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
107
  version: '0'
107
108
  requirements: []
108
109
  rubyforge_project:
109
- rubygems_version: 2.6.13
110
+ rubygems_version: 2.6.14
110
111
  signing_key:
111
112
  specification_version: 4
112
113
  summary: Samanage Ruby Gem