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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 84618d5362c94e2a5901caa06faa32873efaf8f5
4
- data.tar.gz: 3dc1c426ea6c63822e57295e8bc7b202b415d9b5
3
+ metadata.gz: 14662b554060777f54dab37a22d441fe7ea9bba7
4
+ data.tar.gz: f85e283ffdcfc2ef761f12770868bd53c11df00c
5
5
  SHA512:
6
- metadata.gz: c0f651b23f3e937feb59c41005c337b2c0f6eb00b022d8fa62979e7fd9b14c93dc7fb2f12b9ba879a5aa950086dffd1d18efc484b4bf49533ab3a07d8a46a2d6
7
- data.tar.gz: dc511c694af9e897f72b18f0a63a33edeb98df43d1485ddcf7f5757269db5e7f512525755a911237812acd8cec5bd621661e54d75715a8c3c28cfcca3cc3bbc6
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
@@ -1,5 +1,5 @@
1
1
  module Triglav
2
2
  class Client
3
- VERSION = "0.0.5"
3
+ VERSION = "0.0.6"
4
4
  end
5
5
  end
@@ -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 |e|
68
- Model::Service.new(client: self, info: e['service'])
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 |e|
76
- Model::Role.new(client: self, info: e['role'])
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 |e|
84
- Model::Role.new(client: self, info: e['role'])
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 |e|
92
- Model::Host.new(client: self, info: e['host'])
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 |e|
118
- Model::Host.new(client: self, info: e['host'])
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
- json = do_request(method, path, params)
134
- JSON.parse(json)
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("#{response.code}: #{response.message}")
156
+ raise Error.new(handle_response(response))
157
157
  end
158
158
 
159
- response.body
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[self.class.param])
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[self.class.param])
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[self.class.param])
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[self.class.param])
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['service']['name'])
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('{ "result": "ok" }')
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[model_name]['name'])
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[model_name]['name'])
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
- { 'service' => { 'id' => 1 } },
43
- { 'service' => { 'id' => 2 } },
42
+ { 'id' => 1 },
43
+ { 'id' => 2 },
44
44
  ]
45
45
  }
46
46
 
47
47
  let(:roles) {
48
48
  [
49
- { 'role' => { 'id' => 1 } },
50
- { 'role' => { 'id' => 2 } },
49
+ { 'id' => 1 },
50
+ { 'id' => 2 },
51
51
  ]
52
52
  }
53
53
 
54
54
  let(:hosts) {
55
55
  [
56
- { 'host' => { 'id' => 1, 'active' => true } },
57
- { 'host' => { 'id' => 2, 'active' => false } },
58
- { 'host' => { 'id' => 2, 'active' => true } },
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)[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
- { 'service' => { 'id' => 1, 'name' => 'test service' } }
99
+ { 'id' => 1, 'name' => 'test service' }
100
100
  }
101
101
 
102
102
  let(:role) {
103
- { 'role' => { 'id' => 1, 'name' => 'test role' } }
103
+ { 'id' => 1, 'name' => 'test role' }
104
104
  }
105
105
 
106
106
  let(:host) {
107
- { 'host' => { 'id' => 1, 'name' => 'test host', 'active' => true } }
107
+ { 'id' => 1, 'name' => 'test host', 'active' => true }
108
108
  }
109
109
  end
@@ -20,4 +20,5 @@ Gem::Specification.new do |gem|
20
20
  gem.add_development_dependency 'rspec'
21
21
  gem.add_development_dependency 'rake'
22
22
  gem.add_development_dependency 'webmock'
23
+ gem.add_development_dependency 'pry'
23
24
  end
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.5
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-04 00:00:00.000000000 Z
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