triglav-client 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -0
- data/lib/triglav/client/version.rb +1 -1
- data/lib/triglav/client.rb +18 -14
- data/lib/triglav/model.rb +4 -4
- data/spec/client_spec.rb +3 -2
- data/spec/model_spec.rb +2 -2
- data/spec/spec_helper.rb +11 -11
- data/triglav-client.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14662b554060777f54dab37a22d441fe7ea9bba7
|
4
|
+
data.tar.gz: f85e283ffdcfc2ef761f12770868bd53c11df00c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ddbb667794fd3a12200a1d5a594b080a4781ad763b6c3db34b167cd416d0845dedd739994ecd0c3e29efc906540715ad207195150820f5d044c7307aa9526d2
|
7
|
+
data.tar.gz: 3aa1ce743de1e37a0efbd7a1e87550769c80915a1901a7f94ebd417a6ecd1059fa13de301797773ba0647944057b407c8458eae797e31e99dca1c4c8e045c04e
|
data/README.md
CHANGED
@@ -15,10 +15,18 @@ client = Triglav::Client.new(
|
|
15
15
|
# Services
|
16
16
|
client.services #=> Returns all the services registered on Triglav
|
17
17
|
|
18
|
+
# Get service information
|
19
|
+
service = client.services.first #=> Triglav::Model::Service instance
|
20
|
+
service.info.name #=> "sqale"
|
21
|
+
|
18
22
|
# Roles
|
19
23
|
client.roles #=> Returns all the roles registered on Triglav
|
20
24
|
client.roles_in('sqale') #=> Only roles in the service
|
21
25
|
|
26
|
+
# Get role information
|
27
|
+
role = client.roles_in('sqale').first #=> Triglav::Model::Role instance
|
28
|
+
role.info.name #=> "app"
|
29
|
+
|
22
30
|
# Active hosts (default behaviour)
|
23
31
|
client.hosts #=> Returns all the hosts registered on Triglav
|
24
32
|
client.hosts_in('sqale') #=> Only hosts in the service
|
@@ -28,6 +36,10 @@ client.hosts_in('sqale', 'users') #=> Only hosts in the service and which hav
|
|
28
36
|
client.hosts(with_inactive: true)
|
29
37
|
client.hosts_in('sqale', nil, with_inactive: true)
|
30
38
|
client.hosts_in('sqale', 'users', with_inactive: true)
|
39
|
+
|
40
|
+
# Get host information
|
41
|
+
host = client.hosts_in('sqale').first #=> Triglav::Model::Host instance
|
42
|
+
host.info.name #=> "app001.sqale.jp"
|
31
43
|
```
|
32
44
|
|
33
45
|
## Installation
|
data/lib/triglav/client.rb
CHANGED
@@ -64,32 +64,32 @@ module Triglav
|
|
64
64
|
def services
|
65
65
|
endpoint = endpoint_for(:services)
|
66
66
|
response = dispatch_request(endpoint[:method], endpoint[:path])
|
67
|
-
response.map do |
|
68
|
-
Model::Service.new(client: self, info:
|
67
|
+
response.map do |info|
|
68
|
+
Model::Service.new(client: self, info: info)
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
72
|
def roles
|
73
73
|
endpoint = endpoint_for(:roles)
|
74
74
|
response = dispatch_request(endpoint[:method], endpoint[:path])
|
75
|
-
response.map do |
|
76
|
-
Model::Role.new(client: self, info:
|
75
|
+
response.map do |info|
|
76
|
+
Model::Role.new(client: self, info: info)
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
80
|
def roles_in (service)
|
81
81
|
endpoint = endpoint_for(:roles_in, service)
|
82
82
|
response = dispatch_request(endpoint[:method], endpoint[:path])
|
83
|
-
response.map do |
|
84
|
-
Model::Role.new(client: self, info:
|
83
|
+
response.map do |info|
|
84
|
+
Model::Role.new(client: self, info: info)
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
88
|
def hosts (options = {})
|
89
89
|
endpoint = endpoint_for(:hosts)
|
90
90
|
response = dispatch_request(endpoint[:method], endpoint[:path])
|
91
|
-
response.map do |
|
92
|
-
Model::Host.new(client: self, info:
|
91
|
+
response.map do |info|
|
92
|
+
Model::Host.new(client: self, info: info)
|
93
93
|
end.select do |h|
|
94
94
|
if options[:with_inactive]
|
95
95
|
true
|
@@ -114,8 +114,8 @@ module Triglav
|
|
114
114
|
response = dispatch_request(endpoint[:method], endpoint[:path])
|
115
115
|
end
|
116
116
|
|
117
|
-
response.map do |
|
118
|
-
Model::Host.new(client: self, info:
|
117
|
+
response.map do |info|
|
118
|
+
Model::Host.new(client: self, info: info)
|
119
119
|
end.select do |h|
|
120
120
|
if options[:with_inactive]
|
121
121
|
true
|
@@ -130,8 +130,8 @@ module Triglav
|
|
130
130
|
raise ArgumentError.new("Both `method` and `path` are required.")
|
131
131
|
end
|
132
132
|
|
133
|
-
|
134
|
-
|
133
|
+
response = do_request(method, path, params)
|
134
|
+
handle_response(response)
|
135
135
|
end
|
136
136
|
|
137
137
|
private
|
@@ -153,10 +153,14 @@ module Triglav
|
|
153
153
|
end
|
154
154
|
|
155
155
|
if response.code.to_i >= 300
|
156
|
-
raise Error.new(
|
156
|
+
raise Error.new(handle_response(response))
|
157
157
|
end
|
158
158
|
|
159
|
-
response
|
159
|
+
response
|
160
|
+
end
|
161
|
+
|
162
|
+
def handle_response(response)
|
163
|
+
JSON.parse(response.body)
|
160
164
|
end
|
161
165
|
end
|
162
166
|
end
|
data/lib/triglav/model.rb
CHANGED
@@ -51,7 +51,7 @@ module Triglav
|
|
51
51
|
def show
|
52
52
|
endpoint = self.class.endpoint_for(:show, info.name)
|
53
53
|
result = client.dispatch_request(endpoint[:method], endpoint[:path])
|
54
|
-
self.class.new(client: client, info: result
|
54
|
+
self.class.new(client: client, info: result)
|
55
55
|
end
|
56
56
|
|
57
57
|
def update(params = {})
|
@@ -61,19 +61,19 @@ module Triglav
|
|
61
61
|
endpoint[:path],
|
62
62
|
self.class.build_params(params),
|
63
63
|
)
|
64
|
-
self.class.new(client: client, info: result
|
64
|
+
self.class.new(client: client, info: result)
|
65
65
|
end
|
66
66
|
|
67
67
|
def destroy
|
68
68
|
endpoint = self.class.endpoint_for(:destroy, info.name)
|
69
69
|
result = client.dispatch_request(endpoint[:method], endpoint[:path])
|
70
|
-
self.class.new(client: client, info: result
|
70
|
+
self.class.new(client: client, info: result)
|
71
71
|
end
|
72
72
|
|
73
73
|
def revert
|
74
74
|
endpoint = self.class.endpoint_for(:revert, info.name)
|
75
75
|
result = client.dispatch_request(endpoint[:method], endpoint[:path])
|
76
|
-
self.class.new(client: client, info: result
|
76
|
+
self.class.new(client: client, info: result)
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
data/spec/client_spec.rb
CHANGED
@@ -84,7 +84,7 @@ describe Triglav::Client do
|
|
84
84
|
|
85
85
|
context 'when model is successfully created' do
|
86
86
|
it {
|
87
|
-
result = client.create(:service, name: fixture['
|
87
|
+
result = client.create(:service, name: fixture['name'])
|
88
88
|
expect(result).to be_an_instance_of(Triglav::Model::Service)
|
89
89
|
}
|
90
90
|
end
|
@@ -226,7 +226,8 @@ describe Triglav::Client do
|
|
226
226
|
context 'when arguments are passed correctly' do
|
227
227
|
context 'and request is successfully dispatched' do
|
228
228
|
before {
|
229
|
-
subject.stub(:do_request).and_return(
|
229
|
+
subject.stub(:do_request).and_return(true)
|
230
|
+
subject.stub(:handle_response).and_return("result" => "ok")
|
230
231
|
}
|
231
232
|
|
232
233
|
it {
|
data/spec/model_spec.rb
CHANGED
@@ -19,7 +19,7 @@ require 'spec_helper'
|
|
19
19
|
let(:res_body) { fixture.to_json }
|
20
20
|
|
21
21
|
it {
|
22
|
-
result = klass_name.create(client, name: fixture[
|
22
|
+
result = klass_name.create(client, name: fixture['name'])
|
23
23
|
expect(result).to be_an_instance_of(klass)
|
24
24
|
}
|
25
25
|
end
|
@@ -47,7 +47,7 @@ require 'spec_helper'
|
|
47
47
|
let(:res_body) { fixture.to_json }
|
48
48
|
|
49
49
|
it {
|
50
|
-
result = model.update(name: fixture[
|
50
|
+
result = model.update(name: fixture['name'])
|
51
51
|
expect(result).to be_an_instance_of(klass)
|
52
52
|
}
|
53
53
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -39,23 +39,23 @@ shared_context 'initialize client with fixtures' do
|
|
39
39
|
|
40
40
|
let(:services) {
|
41
41
|
[
|
42
|
-
{ '
|
43
|
-
{ '
|
42
|
+
{ 'id' => 1 },
|
43
|
+
{ 'id' => 2 },
|
44
44
|
]
|
45
45
|
}
|
46
46
|
|
47
47
|
let(:roles) {
|
48
48
|
[
|
49
|
-
{ '
|
50
|
-
{ '
|
49
|
+
{ 'id' => 1 },
|
50
|
+
{ 'id' => 2 },
|
51
51
|
]
|
52
52
|
}
|
53
53
|
|
54
54
|
let(:hosts) {
|
55
55
|
[
|
56
|
-
{ '
|
57
|
-
{ '
|
58
|
-
{ '
|
56
|
+
{ 'id' => 1, 'active' => true },
|
57
|
+
{ 'id' => 2, 'active' => false },
|
58
|
+
{ 'id' => 2, 'active' => true },
|
59
59
|
]
|
60
60
|
}
|
61
61
|
end
|
@@ -65,7 +65,7 @@ shared_context 'initialize client with model fixtures' do
|
|
65
65
|
include_context 'setup request'
|
66
66
|
|
67
67
|
let(:model) {
|
68
|
-
info = fixture_for(model_name)
|
68
|
+
info = fixture_for(model_name)
|
69
69
|
|
70
70
|
klass_name.new(
|
71
71
|
client: client,
|
@@ -96,14 +96,14 @@ shared_context 'initialize client with model fixtures' do
|
|
96
96
|
end
|
97
97
|
|
98
98
|
let(:service) {
|
99
|
-
{ '
|
99
|
+
{ 'id' => 1, 'name' => 'test service' }
|
100
100
|
}
|
101
101
|
|
102
102
|
let(:role) {
|
103
|
-
{ '
|
103
|
+
{ 'id' => 1, 'name' => 'test role' }
|
104
104
|
}
|
105
105
|
|
106
106
|
let(:host) {
|
107
|
-
{ '
|
107
|
+
{ 'id' => 1, 'name' => 'test host', 'active' => true }
|
108
108
|
}
|
109
109
|
end
|
data/triglav-client.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: triglav-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kentaro Kuribayashi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-03-
|
11
|
+
date: 2013-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
description: A Ruby interface to Triglav API.
|
56
70
|
email:
|
57
71
|
- kentarok@gmail.com
|