gocd 0.4 → 0.5

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: 8ecfb7fe232628e1723d51e0910d4582a0e97569
4
- data.tar.gz: f4d5b4d78f28c350089932fcf595c29913e29ba6
3
+ metadata.gz: 56400d362923723a438a5f25c658c120c16e9790
4
+ data.tar.gz: bca2fdec6bbb2147a531113f5f290cab52f67a82
5
5
  SHA512:
6
- metadata.gz: 9f0422eb9a2edfdc4155e944a8b774fa4db092f30787f7ec918db773b1f4124bd49c947b1b1b634280e1dcf6d9038db60154b7382775fb5a6bba19497aff0bb8
7
- data.tar.gz: f3429bc451a52e48ab16dfa52c66ad9c4f09c07269c4bf308fe0c657489b7da6ea780d44064b5be1b358535b5297230dc0371b42405b739791e515895b9aa21d
6
+ metadata.gz: 4bb3a3dd77f6a0cb1adde4835fb24e3a9abdffe05382a591e7a1e2b86d405201ada1de0907bccb737573ece3bdc701225d270e954ce3cca22225d65c551ecc7c
7
+ data.tar.gz: 18ed081410ab2d9b8d4af5777efc190c76f0f79e6349244ee1329baf57079e19cb7c4de5553210f3becad4e56a6adccfceddbbf04999aafdaf1097e12a47f43d
@@ -6,7 +6,7 @@ require_relative './lib/gocd/version.rb'
6
6
  Gem::Specification.new do |s|
7
7
  s.name = 'gocd'
8
8
  s.version = GOCD::VERSION
9
- s.date = '2016-09-18'
9
+ s.date = '2016-09-22'
10
10
  s.summary = 'Get info from gocd using its apis'
11
11
  s.description = s.summary
12
12
  s.authors = ['Ajit Singh']
@@ -20,4 +20,5 @@ Gem::Specification.new do |s|
20
20
  s.require_paths = ["lib"]
21
21
 
22
22
  s.add_dependency 'activesupport'
23
+ s.add_dependency 'json'
23
24
  end
@@ -0,0 +1,67 @@
1
+ module GOCD
2
+ class Agent
3
+ def initialize(response)
4
+ @response = response
5
+ end
6
+
7
+ def name
8
+ @response['hostname']
9
+ end
10
+
11
+ def uuid
12
+ @response['uuid']
13
+ end
14
+
15
+ def ip_address
16
+ @response['ip_address']
17
+ end
18
+
19
+ def os
20
+ @response['operating_system']
21
+ end
22
+
23
+ def free_space
24
+ @response['free_space']
25
+ end
26
+
27
+ def state
28
+ @response['agent_state']
29
+ end
30
+
31
+ def disabled?
32
+ @response['agent_config_state'] == 'Disabled'
33
+ end
34
+
35
+ def idle?
36
+ @response['agent_state'] == 'Idle'
37
+ end
38
+
39
+ def building?
40
+ @response['agent_state'] == 'Building'
41
+ end
42
+
43
+ def missing?
44
+ @response['agent_state'] == 'Missing'
45
+ end
46
+
47
+ def resources
48
+ @response['resources']
49
+ end
50
+
51
+ def has_resource(resource)
52
+ resources.include? resource
53
+ end
54
+
55
+ def environments
56
+ @responsep['environments']
57
+ end
58
+
59
+ def has_environment(env)
60
+ environments.include? env
61
+ end
62
+
63
+ def location
64
+ @response['sandbox']
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,25 @@
1
+ module GOCD
2
+ class Agents
3
+ class << self
4
+ def idle
5
+ agents.select { |agent| agent.idle? }
6
+ end
7
+
8
+ def missing
9
+ agents.select { |agent| agent.missing? }
10
+ end
11
+
12
+ def building
13
+ agents.select { |agent| agent.building? }
14
+ end
15
+
16
+ def disabled
17
+ agents.select { |agent| agent.disabled? }
18
+ end
19
+
20
+ def agents
21
+ GOCD::AgentRepository.agents
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,21 @@
1
+ require 'json'
2
+
3
+ module GOCD
4
+ class AgentRepository
5
+ def self.agents
6
+ @agents ||= fetch
7
+ end
8
+
9
+ private
10
+ def self.fetch
11
+ raw_agents = `curl -s -k -u #{GOCD.credentials.curl_credentials} #{GOCD.server.url}/go/api/agents -H 'Accept: application/vnd.go.cd.v2+json'`
12
+ to_agents raw_agents
13
+ end
14
+
15
+ def self.to_agents(raw_agents)
16
+ raise GOCDDataFetchException, 'Could not fetch data from server!!' if raw_agents.nil?
17
+ agents_hash = JSON.parse(raw_agents)
18
+ agents_hash['_embedded']['agents'].map { |agent_response| GOCD::Agent.new agent_response }
19
+ end
20
+ end
21
+ end
@@ -1,3 +1,3 @@
1
1
  module GOCD
2
- VERSION = '0.4'
2
+ VERSION = '0.5'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gocd
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.4'
4
+ version: '0.5'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ajit Singh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-18 00:00:00.000000000 Z
11
+ date: 2016-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  description: Get info from gocd using its apis
28
42
  email: jeetsingh.ajit@gamil.com
29
43
  executables: []
@@ -35,12 +49,15 @@ files:
35
49
  - Gemfile.lock
36
50
  - gocd.gemspec
37
51
  - lib/gocd.rb
52
+ - lib/gocd/agents/agent.rb
53
+ - lib/gocd/agents/agents.rb
54
+ - lib/gocd/agents/agents_repository.rb
38
55
  - lib/gocd/config/credentials.rb
39
56
  - lib/gocd/config/server.rb
40
57
  - lib/gocd/exception/data_fetch_exception.rb
41
58
  - lib/gocd/pipeline/pipeline.rb
42
59
  - lib/gocd/pipeline/pipeline_repository.rb
43
- - lib/gocd/pipelines.rb
60
+ - lib/gocd/pipeline/pipelines.rb
44
61
  - lib/gocd/version.rb
45
62
  homepage: https://github.com/ajitsing/gocd.git
46
63
  licenses: