samanage 1.6.1 → 1.6.2
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 +4 -4
- data/README.md +17 -4
- data/lib/samanage/api.rb +10 -9
- data/lib/samanage/api/users.rb +13 -11
- data/samanage.gemspec +2 -2
- data/spec/api/samanage_incident_spec.rb +0 -1
- data/spec/api/samanage_user_spec.rb +2 -2
- data/spec/samanage_api_spec.rb +11 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a868afa190497ef5e1ea3933c827800c6a0b872
|
4
|
+
data.tar.gz: 1795e4fc05003d145f8e4c20fd73240cac497a6e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55118de925fb9e075bcb4d318076f56a8410c1aa30e99ea6949afd5a7a0b5b977450cb5dfb1df1ca594bd084e11e8cdb14e7636ebb23173e630af4234fb83021
|
7
|
+
data.tar.gz: b504e6330c69bfc77db8c6ed614e8c27e0a60eb5d70a5d31da464de1d728ee4cecba7e6597b0284013c3727c79b07b6196e1dcb3fda17cf4f027f90166284ee6
|
data/README.md
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
# Samanage Ruby Gem
|
2
2
|
[](https://badge.fury.io/rb/samanage)
|
3
3
|
## Requirements
|
4
|
-
- Ruby >= 2.
|
4
|
+
- Ruby >= 2.3
|
5
|
+
|
5
6
|
|
6
7
|
## Installation
|
7
8
|
`gem install samanage`
|
9
|
+
|
8
10
|
#### Linux (CentOS)
|
9
11
|
- `sudo yum install gcc-c++`
|
10
12
|
- `sudo yum install ruby-devel`
|
@@ -14,13 +16,22 @@
|
|
14
16
|
|
15
17
|
|
16
18
|
## Usage
|
17
|
-
### Queries
|
19
|
+
### Basic Queries
|
18
20
|
|
19
21
|
```ruby
|
20
22
|
api_controller = Samanage::Api.new(token: api_token)
|
21
|
-
user_query = api_controller.execute(http_method: 'get',
|
22
|
-
|
23
|
+
user_query = api_controller.execute(http_method: 'get', path: 'users.json')
|
24
|
+
```
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
incident_data = {incident: { priority: 'Critical' }}.to_json
|
28
|
+
incident_update = api_controller.execute(http_method: 'put', path: 'incidents/123.json', payload: incident_data)
|
23
29
|
```
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
|
24
35
|
Returns query returns a Hash with keys:
|
25
36
|
- `:response`*:* unparsed http response
|
26
37
|
- `:code`*:* http status code
|
@@ -30,6 +41,8 @@ Returns query returns a Hash with keys:
|
|
30
41
|
- `:total_count`*:* Total count of records
|
31
42
|
- `:data`*:* Hash containing response body
|
32
43
|
|
44
|
+
|
45
|
+
|
33
46
|
### Function examples
|
34
47
|
#### Return all Samanage Users
|
35
48
|
```ruby
|
data/lib/samanage/api.rb
CHANGED
@@ -9,17 +9,17 @@ module Samanage
|
|
9
9
|
custom_forms: 'custom_forms.json',
|
10
10
|
}
|
11
11
|
attr_accessor :datacenter, :content_type, :base_url, :token, :custom_forms, :authorized, :admins
|
12
|
-
def initialize(token:
|
13
|
-
self.token = token
|
14
|
-
self.datacenter =
|
12
|
+
def initialize(token: nil, dacenter: nil, development_mode: false)
|
13
|
+
self.token = token if token
|
14
|
+
self.datacenter = datacenter if datacenter
|
15
15
|
self.base_url = "https://api#{datacenter}.samanage.com/"
|
16
|
-
# self.content_type = content_type || 'json'
|
17
16
|
self.content_type = 'json'
|
18
17
|
self.admins = []
|
19
|
-
|
20
|
-
self.authorize
|
21
|
-
end
|
18
|
+
# Development mode forzes authorization & prepopulates custom forms/fields and admins
|
22
19
|
if development_mode
|
20
|
+
if self.authorized? != true
|
21
|
+
self.authorize
|
22
|
+
end
|
23
23
|
self.custom_forms = self.organize_forms
|
24
24
|
self.admins = self.list_admins
|
25
25
|
end
|
@@ -39,7 +39,8 @@ module Samanage
|
|
39
39
|
end
|
40
40
|
|
41
41
|
# Defaults to GET
|
42
|
-
def execute(http_method: 'get', path: nil, payload: nil, verbose: nil, ssl_fix: false)
|
42
|
+
def execute(http_method: 'get', path: nil, payload: nil, verbose: nil, ssl_fix: false, token: nil)
|
43
|
+
token = token ||= self.token
|
43
44
|
unless verbose.nil?
|
44
45
|
verbose = '?layout=long'
|
45
46
|
end
|
@@ -47,7 +48,7 @@ module Samanage
|
|
47
48
|
api_call = HTTP.headers(
|
48
49
|
'Accept' => "application/vnd.samanage.v2.0+#{self.content_type}#{verbose}",
|
49
50
|
'Content-type' => "application/#{self.content_type}",
|
50
|
-
'X-Samanage-Authorization' => 'Bearer ' +
|
51
|
+
'X-Samanage-Authorization' => 'Bearer ' + token
|
51
52
|
)
|
52
53
|
ctx = OpenSSL::SSL::SSLContext.new
|
53
54
|
if ssl_fix
|
data/lib/samanage/api/users.rb
CHANGED
@@ -1,18 +1,17 @@
|
|
1
1
|
module Samanage
|
2
2
|
class Api
|
3
|
-
# Returns all users in the account
|
4
|
-
|
5
|
-
def get_users(path: PATHS[:user], options: {})
|
6
|
-
url = Samanage::UrlBuilder.new(path: path, options: options).url
|
7
|
-
api_call = self.execute(path: url)
|
8
|
-
api_call
|
9
|
-
end
|
10
3
|
|
4
|
+
def get_users(path: PATHS[:user], options: {})
|
5
|
+
url = Samanage::UrlBuilder.new(path: path, options: options).url
|
6
|
+
api_call = self.execute(path: url)
|
7
|
+
api_call
|
8
|
+
end
|
9
|
+
|
10
|
+
# Returns all users in the account
|
11
11
|
def collect_users
|
12
12
|
page = 1
|
13
13
|
users = Array.new
|
14
14
|
total_pages = self.get_users[:total_pages]
|
15
|
-
# puts api_call
|
16
15
|
while page <= total_pages
|
17
16
|
api_call = self.execute(http_method: 'get', path: "users.json?page=#{page}")
|
18
17
|
users += api_call[:data]
|
@@ -24,20 +23,23 @@ module Samanage
|
|
24
23
|
def create_user(payload: nil, options: {})
|
25
24
|
api_call = self.execute(path: PATHS[:user], http_method: 'post', payload: payload)
|
26
25
|
api_call
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
end
|
27
|
+
|
28
|
+
# Find user by id
|
29
|
+
def find_user(id: nil)
|
30
30
|
path = "users/#{id}.json"
|
31
31
|
api_call = self.execute(path: path)
|
32
32
|
api_call
|
33
33
|
end
|
34
34
|
|
35
|
+
# Check for user by field (ex: users.json?field=value)
|
35
36
|
def check_user(field: 'email', value: nil)
|
36
37
|
url = "users.json?#{field}=#{value}"
|
37
38
|
api_call = self.execute(path: url)
|
38
39
|
api_call
|
39
40
|
end
|
40
41
|
|
42
|
+
# Update user by id
|
41
43
|
def update_user(payload: nil, id: nil)
|
42
44
|
path = "users/#{id}.json"
|
43
45
|
puts "Path: #{path}"
|
data/samanage.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'samanage'
|
3
|
-
s.version = '1.6.
|
3
|
+
s.version = '1.6.2'
|
4
4
|
s.date = Date.today.strftime("%Y-%m-%d")
|
5
5
|
s.summary = "Samanage Ruby Gem"
|
6
6
|
s.description = "Connect to Samanage using Ruby!"
|
@@ -10,6 +10,6 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.require_paths = ["lib"]
|
11
11
|
s.add_development_dependency 'http', ['~> 2.2']
|
12
12
|
s.add_runtime_dependency 'http', ["~> 2.2"]
|
13
|
-
s.homepage = '
|
13
|
+
s.homepage = 'https://github.com/cw2908/samanage-ruby'
|
14
14
|
s.license = 'MIT'
|
15
15
|
end
|
@@ -36,10 +36,10 @@ describe Samanage::Api do
|
|
36
36
|
expect(user_create[:code]).to eq(200).or(201)
|
37
37
|
end
|
38
38
|
it 'create_user: fails if no email' do
|
39
|
-
user_name = "samanage-ruby-#{(rand*10**10).ceil}"
|
39
|
+
user_name = "samanage-ruby-#{(rand*10**(rand(10))).ceil}"
|
40
40
|
json = {
|
41
41
|
:user => {
|
42
|
-
|
42
|
+
:name => user_name,
|
43
43
|
}
|
44
44
|
}
|
45
45
|
expect{@controller.create_user(payload: json.to_json)}.to raise_error(Samanage::InvalidRequest)
|
data/spec/samanage_api_spec.rb
CHANGED
@@ -6,7 +6,10 @@ describe Samanage do
|
|
6
6
|
end
|
7
7
|
context 'on creation' do
|
8
8
|
it 'Requires Email & Token' do
|
9
|
-
expect{
|
9
|
+
expect{
|
10
|
+
api_controller = Samanage::Api.new(token: "invalid token")
|
11
|
+
api_controller.authorize
|
12
|
+
}.to raise_error(Samanage::AuthorizationError)
|
10
13
|
expect{ Samanage::Api.new(token: TOKEN) }.to_not raise_error
|
11
14
|
end
|
12
15
|
|
@@ -14,8 +17,10 @@ describe Samanage do
|
|
14
17
|
# Valid Credentials
|
15
18
|
expect(Samanage::Api.new(token: TOKEN)).to be_an_instance_of(Samanage::Api)
|
16
19
|
# Invalid / Reversed Credentials
|
17
|
-
expect{
|
18
|
-
|
20
|
+
expect{
|
21
|
+
api_controller = Samanage::Api.new(token: 'invalid')
|
22
|
+
api_controller.authorize
|
23
|
+
}.to raise_error(Samanage::AuthorizationError)
|
19
24
|
end
|
20
25
|
|
21
26
|
it 'Finds all custom forms in development mode' do
|
@@ -24,6 +29,9 @@ describe Samanage do
|
|
24
29
|
expect(api_controller.custom_forms).not_to be(nil)
|
25
30
|
expect(api_controller.custom_forms).to be_a(Hash)
|
26
31
|
end
|
32
|
+
it 'Fails with invalid token in development mode' do
|
33
|
+
expect{ Samanage::Api.new(token: 'Invalid Token', development_mode: true)}.to raise_error(Samanage::AuthorizationError)
|
34
|
+
end
|
27
35
|
end
|
28
36
|
end
|
29
37
|
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.6.
|
4
|
+
version: 1.6.2
|
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-09-
|
11
|
+
date: 2017-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|
@@ -76,7 +76,7 @@ files:
|
|
76
76
|
- spec/samanage_url_builder_spec.rb
|
77
77
|
- spec/spec_helper.rb
|
78
78
|
- test.rb
|
79
|
-
homepage:
|
79
|
+
homepage: https://github.com/cw2908/samanage-ruby
|
80
80
|
licenses:
|
81
81
|
- MIT
|
82
82
|
metadata: {}
|