samanage 1.5.1 → 1.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +38 -1
- data/lib/samanage/api.rb +10 -7
- data/lib/samanage/error.rb +1 -1
- data/samanage.gemspec +3 -1
- data/spec/samanage_api_spec.rb +0 -1
- metadata +30 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49cf085d75e8e4de2a1fa11fdd19e6d99c38b421
|
4
|
+
data.tar.gz: 243c926d4445e5f58f2adea3179641e892239050
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70a262365ad0a58e9ad3b89e6f66e6828d68c80086ef136c81ece7766e1ff06a03d349a8ed5db285866d86feaecfcd50f9a6f71d17ed9ecec7597db7d2b3677e
|
7
|
+
data.tar.gz: 3f120fdc1a1f6d37e4826bf2a41d24c96cd0af2259640a3981d3efc40bbbf9e132398b4fd144efbb9d1175045e841c973db82fd27f7c7c92221a07ed24d2dbc5
|
data/README.md
CHANGED
@@ -1 +1,38 @@
|
|
1
|
-
# samanage-ruby
|
1
|
+
# samanage-ruby
|
2
|
+
|
3
|
+
## Requirements
|
4
|
+
- Ruby >= 2.3.1
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
gem install samanage
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
### Queries
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
api_controller = Samanage::Api.new(token: api_token)
|
16
|
+
query = api_controller.execute(http_method: 'get',
|
17
|
+
path: 'users.json')
|
18
|
+
```
|
19
|
+
Returns query returns a Hash with keys:
|
20
|
+
- `:response`*:* unparsed `http` response
|
21
|
+
- `:code`*:* http status code
|
22
|
+
- `:json`*:* Samanage API json response
|
23
|
+
- `:headers`*:* Response headers
|
24
|
+
- `:total_pages`*:* Total pages
|
25
|
+
- `:total_count`*:* Total count of records
|
26
|
+
- `:data`*:* Hash containing response body
|
27
|
+
|
28
|
+
### Function examples
|
29
|
+
#### Return all Samanage Users
|
30
|
+
```ruby
|
31
|
+
users = api_controller.collect_users
|
32
|
+
```
|
33
|
+
|
34
|
+
#### Update hardware
|
35
|
+
```ruby
|
36
|
+
hardware = {'hardware':{'name':'My Computer'}}
|
37
|
+
result = api_controller.update_hardware(id: 123, payload: hardware)
|
38
|
+
```
|
data/lib/samanage/api.rb
CHANGED
@@ -8,25 +8,32 @@ module Samanage
|
|
8
8
|
custom_fields: 'custom_fields.json',
|
9
9
|
custom_forms: 'custom_forms.json',
|
10
10
|
}
|
11
|
-
attr_accessor :datacenter, :content_type, :base_url, :token, :custom_forms
|
11
|
+
attr_accessor :datacenter, :content_type, :base_url, :token, :custom_forms, :authorized
|
12
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/"
|
16
16
|
# self.content_type = content_type || 'json'
|
17
17
|
self.content_type = 'json'
|
18
|
-
self.
|
18
|
+
if self.authorized != true
|
19
|
+
self.authorize
|
20
|
+
end
|
19
21
|
if development_mode
|
20
22
|
self.custom_forms = self.organize_forms
|
21
23
|
end
|
22
24
|
end
|
23
25
|
|
26
|
+
def authorized?
|
27
|
+
self.authorized
|
28
|
+
end
|
29
|
+
|
24
30
|
def authorize
|
25
31
|
self.execute(path: 'api.json')
|
26
32
|
rescue OpenSSL::SSL::SSLError => e
|
27
33
|
puts "Raised: #{e} #{e.class}"
|
28
34
|
puts 'Disabling Local SSL Verification'
|
29
35
|
self.execute(path: 'api.json', ssl_fix: true)
|
36
|
+
self.authorized = true
|
30
37
|
end
|
31
38
|
|
32
39
|
# Defaults to GET
|
@@ -53,7 +60,6 @@ module Samanage
|
|
53
60
|
response[:total_pages] = api_call.headers['X-Total-Pages'].to_i
|
54
61
|
response[:total_pages] = 1 if response[:total_pages] == 0
|
55
62
|
response[:total_count] = api_call.headers['X-Total-Count'].to_i
|
56
|
-
response[:total_count] = 1 if response[:total_count] == 0
|
57
63
|
|
58
64
|
# puts "Body Class: #{api_call.body.class}"
|
59
65
|
# puts "#{api_call.body}"
|
@@ -66,22 +72,19 @@ module Samanage
|
|
66
72
|
when 401
|
67
73
|
response[:data] = api_call.body
|
68
74
|
error = response[:response]
|
69
|
-
|
75
|
+
self.authorized =false
|
70
76
|
raise Samanage::AuthorizationError.new(error: error,response: response)
|
71
77
|
when 404
|
72
78
|
response[:data] = api_call.body
|
73
79
|
error = response[:response]
|
74
|
-
puts "Returned 404: #{error}"
|
75
80
|
raise Samanage::NotFound.new(error: error, response: response)
|
76
81
|
when 422
|
77
82
|
response[:data] = api_call.body
|
78
83
|
error = response[:response]
|
79
|
-
puts "Returned 422: #{error}"
|
80
84
|
raise Samanage::InvalidRequest.new(error: error, response: response)
|
81
85
|
else
|
82
86
|
response[:data] = api_call.body
|
83
87
|
error = response[:response]
|
84
|
-
puts "Returned #{response[:code]}: #{error}"
|
85
88
|
raise Samanage::InvalidRequest.new(error: error, response: response)
|
86
89
|
end
|
87
90
|
# Always return response hash
|
data/lib/samanage/error.rb
CHANGED
data/samanage.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'samanage'
|
3
|
-
s.version = '1.5.
|
3
|
+
s.version = '1.5.4'
|
4
4
|
s.date = '2017-01-01'
|
5
5
|
s.summary = "Samanage Ruby Gem"
|
6
6
|
s.description = "Connect to Samanage using Ruby!"
|
@@ -8,6 +8,8 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.email = 'chris.walls@samanage.com'
|
9
9
|
s.files = `git ls-files`.split("\n")
|
10
10
|
s.require_paths = ["lib"]
|
11
|
+
s.add_development_dependency 'http', ['~> 2.2']
|
12
|
+
s.add_runtime_dependency 'http', ["~> 2.2"]
|
11
13
|
s.homepage = 'http://rubygems.org/gems/samanage'
|
12
14
|
s.license = 'MIT'
|
13
15
|
end
|
data/spec/samanage_api_spec.rb
CHANGED
@@ -6,7 +6,6 @@ describe Samanage do
|
|
6
6
|
end
|
7
7
|
context 'on creation' do
|
8
8
|
it 'Requires Email & Token' do
|
9
|
-
expect{ Samanage::Api.new() }.to raise_error(ArgumentError)
|
10
9
|
expect{ Samanage::Api.new(token: "invalid token") }.to raise_error(Samanage::AuthorizationError)
|
11
10
|
expect{ Samanage::Api.new(token: TOKEN) }.to_not raise_error
|
12
11
|
end
|
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.5.
|
4
|
+
version: 1.5.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Walls
|
@@ -9,7 +9,35 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2017-01-01 00:00:00.000000000 Z
|
12
|
-
dependencies:
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: http
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.2'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: http
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.2'
|
13
41
|
description: Connect to Samanage using Ruby!
|
14
42
|
email: chris.walls@samanage.com
|
15
43
|
executables: []
|