samanage 1.8.2 → 1.8.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/samanage.rb +2 -1
- data/lib/samanage/api.rb +26 -16
- data/lib/samanage/api/custom_forms.rb +0 -2
- data/lib/samanage/version.rb +3 -0
- data/spec/api/samanage_category_spec.rb +1 -2
- data/spec/samanage_api_spec.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1a73bd9d0ecff83e8c95ca29b389260d73eb3e7
|
4
|
+
data.tar.gz: b2a98bff4c554c017ac670f172981676a3ac9128
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0caa861127343267e8c33fe1a730acdf48a722244a2c9464178d9445d60576ed92e85ce9b1dd5cc1db7f53ec24590663cc8c8c35f61a4edbcdf91386f5874ccc
|
7
|
+
data.tar.gz: ddc7ad10f2e7f6f1642b08dd5d18d745d0956600b24fb6532a46c9049d83197e0098fdbc559aca3048b1874697edffe7dace52c57cc341bc0371d9ad43925a37
|
data/lib/samanage.rb
CHANGED
data/lib/samanage/api.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
module Samanage
|
2
2
|
class Api
|
3
3
|
include HTTParty
|
4
|
-
|
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
|
-
|
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
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
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
|
|
@@ -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(
|
26
|
+
expect(category_create[:code]).to eq(200).or(201)
|
28
27
|
end
|
29
28
|
end
|
30
29
|
end
|
data/spec/samanage_api_spec.rb
CHANGED
@@ -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(
|
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.
|
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-
|
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.
|
110
|
+
rubygems_version: 2.6.14
|
110
111
|
signing_key:
|
111
112
|
specification_version: 4
|
112
113
|
summary: Samanage Ruby Gem
|