jenkins-json-api 0.0.1 → 0.0.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.
data/bin/rjja CHANGED
@@ -29,7 +29,7 @@ cmd_opts = case cmd
29
29
 
30
30
  Trollop::die "no action given" if cmd.nil?
31
31
 
32
- jenkins = Jenkins.new opts[:host]
32
+ jenkins = Jenkins::Jenkins.new opts[:host]
33
33
 
34
34
  hostname, port = opts[:host].split ':'
35
35
  begin
@@ -1,5 +1,5 @@
1
1
 
2
-
2
+ # TODO nicer step-def code, more support code
3
3
  Given /^jenkins on port "(.*?)" with jobs "(.*?)", "(.*?)" with statuses respectively "(.*?)", "(.*?)"$/ do |port, job1, job2, stat1, stat2|
4
4
  mock_resp(port: port) do
5
5
  get('/api/json') do
@@ -1,71 +1,4 @@
1
1
 
2
- require 'json'
3
- require 'open-uri'
4
-
5
- class Jenkins
6
-
7
- class Job
8
- SUCCESS = 'blue'
9
- FAILED = 'red'
10
-
11
- def initialize(json)
12
- @name = json['name']
13
- @url = json['url']
14
- @color = json['color']
15
- end
16
-
17
- def success?
18
- return true if color == SUCCESS
19
- return false if color == FAILED
20
- raise "Inconsistent class state! color: #{color}"
21
- end
22
-
23
- def build
24
- open url+'build'
25
- end
26
-
27
- def build_async
28
- Process.waitpid @job if @job
29
- @job = fork do
30
- build
31
- end
32
- end
33
-
34
- def to_s
35
- "\n #{super.to_s}\n name: #{name}\n url: #{url}\n success: #{success?}\n"
36
- end
37
-
38
- def ==(r)
39
- r.name == name and
40
- r.url == url and
41
- r.success? == success?
42
- end
43
-
44
- attr_reader :name, :url, :color
45
- end
46
-
47
- def initialize(host)
48
- @host = host
49
- end
50
-
51
- def get_all_jobs
52
- get_json['jobs'].map { |job| Job.new(job) }
53
- end
54
-
55
- def build_all
56
- get_all_jobs.each do |job|
57
- job.build
58
- end
59
- end
60
-
61
-
62
- attr_reader :host
63
- private
64
- def get_json(med = nil)
65
- JSON.parse(open( api_url(med) ).read)
66
- end
67
- def api_url(med)
68
- "http://#{host}/api/json"
69
- end
70
- end
2
+ require_relative 'jenkins-json-api/jenkins.rb'
3
+ require_relative 'jenkins-json-api/job.rb'
71
4
 
@@ -0,0 +1,30 @@
1
+
2
+ require 'json'
3
+
4
+ module Jenkins
5
+ class Jenkins
6
+ def initialize(host)
7
+ @host = host
8
+ end
9
+
10
+ def get_all_jobs
11
+ get_json['jobs'].map { |job| Job.new(job) }
12
+ end
13
+
14
+ def build_all
15
+ get_all_jobs.each do |job|
16
+ job.build
17
+ end
18
+ end
19
+
20
+ attr_reader :host
21
+ private
22
+ def get_json(med = nil)
23
+ JSON.parse(open( api_url(med) ).read)
24
+ end
25
+ def api_url(med)
26
+ "http://#{host}/api/json"
27
+ end
28
+ end
29
+ end
30
+
@@ -0,0 +1,45 @@
1
+
2
+ require 'open-uri'
3
+
4
+ module Jenkins
5
+ class Job
6
+ SUCCESS = 'blue'
7
+ FAILED = 'red'
8
+
9
+ def initialize(json)
10
+ @name = json['name']
11
+ @url = json['url']
12
+ @color = json['color']
13
+ end
14
+
15
+ def success?
16
+ return true if color == SUCCESS
17
+ return false if color == FAILED
18
+ raise "Inconsistent class state! color: #{color}"
19
+ end
20
+
21
+ def build
22
+ open url+'build'
23
+ end
24
+
25
+ def build_async
26
+ Process.waitpid @job if @job
27
+ @job = fork do
28
+ build
29
+ end
30
+ end
31
+
32
+ def to_s
33
+ "\n #{super.to_s}\n name: #{name}\n url: #{url}\n success: #{success?}\n"
34
+ end
35
+
36
+ def ==(r)
37
+ r.name == name and
38
+ r.url == url and
39
+ r.success? == success?
40
+ end
41
+
42
+ attr_reader :name, :url, :color
43
+ end
44
+ end
45
+
@@ -1,7 +1,7 @@
1
1
  module Jenkins
2
2
  module Json
3
3
  module Api
4
- VERSION = "0.0.1"
4
+ VERSION = "0.0.2"
5
5
  end
6
6
  end
7
7
  end
@@ -3,8 +3,8 @@ require 'spec_helper'
3
3
 
4
4
  require_relative '../lib/jenkins-json-api'
5
5
 
6
- describe Jenkins do
7
- subject { Jenkins.new testhost }
6
+ describe Jenkins::Jenkins do
7
+ subject { Jenkins::Jenkins.new testhost }
8
8
  let(:testhost) { 'myjenkinshost.com' }
9
9
 
10
10
  its(:host) { should == testhost }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jenkins-json-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -32,6 +32,8 @@ files:
32
32
  - features/support/env.rb
33
33
  - jenkins-json-api.gemspec
34
34
  - lib/jenkins-json-api.rb
35
+ - lib/jenkins-json-api/jenkins.rb
36
+ - lib/jenkins-json-api/job.rb
35
37
  - lib/jenkins-json-api/version.rb
36
38
  - spec/jenkins_spec.rb
37
39
  - spec/job_spec.rb