bamboo-client 0.0.6 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +4 -0
- data/LICENSE +1 -1
- data/Rakefile +1 -1
- data/bamboo-client.gemspec +4 -3
- data/features/rest.feature +7 -0
- data/features/step_definitions/rest_steps.rb +8 -0
- data/features/step_definitions/rest_steps.rb~ +38 -0
- data/features/support/env.rb +1 -0
- data/lib/bamboo-client/http/json.rb +10 -5
- data/lib/bamboo-client/rest.rb +17 -2
- data/lib/bamboo-client/version.rb +1 -1
- data/spec/bamboo-client/http/json_spec.rb +11 -2
- data/spec/bamboo-client/remote_spec.rb +2 -2
- data/spec/bamboo-client/rest_spec.rb +16 -3
- metadata +64 -13
data/.travis.yml
ADDED
data/LICENSE
CHANGED
data/Rakefile
CHANGED
data/bamboo-client.gemspec
CHANGED
@@ -6,17 +6,18 @@ Gem::Specification.new do |s|
|
|
6
6
|
s.name = "bamboo-client"
|
7
7
|
s.version = Bamboo::Client::VERSION
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
|
-
s.authors = ["Jari Bakken"]
|
10
|
-
s.email = ["jari.bakken@gmail.com"]
|
9
|
+
s.authors = ["Jari Bakken", "Peter Marsh"]
|
10
|
+
s.email = ["jari.bakken@gmail.com", "pete.d.marsh@gmail.com"]
|
11
11
|
s.homepage = ""
|
12
12
|
s.summary = %q{Ruby client for Atlassian Bamboo's REST APIs}
|
13
13
|
s.description = %q{Ruby client for Atlassian Bamboo's REST APIs}
|
14
14
|
|
15
15
|
s.rubyforge_project = "bamboo-client"
|
16
16
|
|
17
|
-
s.add_development_dependency "rspec"
|
17
|
+
s.add_development_dependency "rspec", "~> 2.5"
|
18
18
|
s.add_development_dependency "cucumber", ">= 0.10.0"
|
19
19
|
s.add_development_dependency "simplecov"
|
20
|
+
s.add_development_dependency "rake", "~> 0.9"
|
20
21
|
|
21
22
|
s.add_dependency "rest-client"
|
22
23
|
s.add_dependency "json"
|
data/features/rest.feature
CHANGED
@@ -20,3 +20,10 @@ Feature: Bamboo REST client
|
|
20
20
|
When I fetch all builds
|
21
21
|
Then I should get a list of builds
|
22
22
|
And all builds should have a state
|
23
|
+
|
24
|
+
Scenario: Authenticated API
|
25
|
+
When I log in
|
26
|
+
Then I should get a session ID
|
27
|
+
When I fetch all the plans
|
28
|
+
Then I should get a list of plans
|
29
|
+
And all plans should have a key
|
@@ -31,3 +31,11 @@ end
|
|
31
31
|
Then /^all builds should have a state$/ do
|
32
32
|
@builds.each { |b| [:successful, :failed].should include(b.state) }
|
33
33
|
end
|
34
|
+
|
35
|
+
When /^I log in$/ do
|
36
|
+
client.login user, password
|
37
|
+
end
|
38
|
+
|
39
|
+
Then /^I should get a session ID$/ do
|
40
|
+
client.cookies.has_key? :JSESSIONID
|
41
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
When /^I fetch all the plans$/ do
|
2
|
+
@plans = client.plans
|
3
|
+
end
|
4
|
+
|
5
|
+
Then /^I should get a list of plans$/ do
|
6
|
+
@plans.should_not be_empty
|
7
|
+
@plans.each { |plan| plan.should be_kind_of(Bamboo::Client::Rest::Plan) }
|
8
|
+
end
|
9
|
+
|
10
|
+
When /^I fetch all projects$/ do
|
11
|
+
@projects = client.projects
|
12
|
+
end
|
13
|
+
|
14
|
+
Then /^I should get a list of projects$/ do
|
15
|
+
@projects.should_not be_empty
|
16
|
+
@projects.each { |pro| pro.should be_kind_of(Bamboo::Client::Rest::Project) }
|
17
|
+
end
|
18
|
+
|
19
|
+
Then /^all plans should have a key$/ do
|
20
|
+
@plans.each { |e| e.key.should be_kind_of(String) }
|
21
|
+
end
|
22
|
+
|
23
|
+
Then /^all projects should have a key$/ do
|
24
|
+
@projects.each { |e| e.key.should be_kind_of(String) }
|
25
|
+
end
|
26
|
+
|
27
|
+
When /^I fetch all builds$/ do
|
28
|
+
@builds = client.builds
|
29
|
+
end
|
30
|
+
|
31
|
+
Then /^all builds should have a state$/ do
|
32
|
+
@builds.each { |b| [:successful, :failed].should include(b.state) }
|
33
|
+
end
|
34
|
+
|
35
|
+
When /^I login to in with my credentials, (.*) and (.*)$/ do |username, password|
|
36
|
+
client.login(username, password)
|
37
|
+
client.cookies != nil
|
38
|
+
end
|
data/features/support/env.rb
CHANGED
@@ -13,7 +13,6 @@ module Bamboo
|
|
13
13
|
|
14
14
|
def initialize(data)
|
15
15
|
@data = data
|
16
|
-
|
17
16
|
pp @data if $DEBUG
|
18
17
|
end
|
19
18
|
|
@@ -40,14 +39,20 @@ module Bamboo
|
|
40
39
|
end
|
41
40
|
end # Doc
|
42
41
|
|
43
|
-
def post(uri_or_path, data = {})
|
44
|
-
resp = RestClient.post(uri_for(uri_or_path), data.to_json, :accept => :json, :content_type => :json)
|
42
|
+
def post(uri_or_path, data = {}, cookies = nil)
|
43
|
+
resp = RestClient.post(uri_for(uri_or_path), data.to_json, :accept => :json, :content_type => :json, :cookies => cookies)
|
45
44
|
Doc.from(resp) unless resp.empty?
|
46
45
|
end
|
47
46
|
|
48
|
-
def get(uri_or_path, params = nil)
|
47
|
+
def get(uri_or_path, params = nil, cookies = nil)
|
49
48
|
uri = uri_for(uri_or_path, params)
|
50
|
-
Doc.from RestClient.get(uri, :accept => :json)
|
49
|
+
Doc.from RestClient.get(uri, :accept => :json, :cookies => cookies)
|
50
|
+
end
|
51
|
+
|
52
|
+
def get_cookies(uri_or_path, params = nil)
|
53
|
+
uri = uri_for(uri_or_path, nil)
|
54
|
+
resp = RestClient.get(uri, :params => params)
|
55
|
+
resp.cookies
|
51
56
|
end
|
52
57
|
|
53
58
|
end # Json
|
data/lib/bamboo-client/rest.rb
CHANGED
@@ -8,10 +8,25 @@ module Bamboo
|
|
8
8
|
#
|
9
9
|
|
10
10
|
class Rest < Abstract
|
11
|
+
|
12
|
+
attr_reader :cookies
|
13
|
+
|
11
14
|
SERVICE = "/rest/api/latest"
|
12
15
|
|
13
16
|
def initialize(http)
|
14
17
|
super
|
18
|
+
@cookies = nil
|
19
|
+
end
|
20
|
+
|
21
|
+
def login(username, password)
|
22
|
+
url = File.join(SERVICE, 'plan')
|
23
|
+
resp = @http.get_cookies(url, {
|
24
|
+
:os_authType => 'basic',
|
25
|
+
:os_username => username,
|
26
|
+
:os_password => password
|
27
|
+
}
|
28
|
+
)
|
29
|
+
@cookies = {:JSESSIONID => resp['JSESSIONID']}
|
15
30
|
end
|
16
31
|
|
17
32
|
def plans
|
@@ -28,8 +43,8 @@ module Bamboo
|
|
28
43
|
|
29
44
|
private
|
30
45
|
|
31
|
-
def get(what)
|
32
|
-
@http.get File.join(SERVICE, what)
|
46
|
+
def get(what, params = nil)
|
47
|
+
@http.get File.join(SERVICE, what), params, @cookies
|
33
48
|
end
|
34
49
|
|
35
50
|
class Plan
|
@@ -9,7 +9,7 @@ module Bamboo
|
|
9
9
|
|
10
10
|
it "does a GET" do
|
11
11
|
RestClient.should_receive(:get).with(
|
12
|
-
"#{url}/", :accept => :json
|
12
|
+
"#{url}/", :accept => :json, :cookies => nil
|
13
13
|
).and_return('{"some": "data"}')
|
14
14
|
|
15
15
|
doc = json.get "/"
|
@@ -18,11 +18,20 @@ module Bamboo
|
|
18
18
|
|
19
19
|
it "does a POST" do
|
20
20
|
RestClient.should_receive(:post).with(
|
21
|
-
"#{url}/", '{"some":"data"}', :accept => :json, :content_type => :json
|
21
|
+
"#{url}/", '{"some":"data"}', :accept => :json, :content_type => :json, :cookies => nil
|
22
22
|
).and_return('')
|
23
23
|
|
24
24
|
json.post("/", :some => "data").should be_nil
|
25
25
|
end
|
26
|
+
|
27
|
+
it "returns cookies from GET" do
|
28
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, "OK")
|
29
|
+
net_http_resp.add_field 'Set-Cookie', 'Cookie=Value;'
|
30
|
+
resp = RestClient::Response.create("",net_http_resp, nil)
|
31
|
+
RestClient.should_receive(:get).with("#{url}/", :params => nil).and_return(resp)
|
32
|
+
cookies = json.get_cookies("/").should == {'Cookie' => 'Value'}
|
33
|
+
end
|
34
|
+
|
26
35
|
end
|
27
36
|
|
28
37
|
describe Json::Doc do
|
@@ -214,12 +214,12 @@ module Bamboo
|
|
214
214
|
end
|
215
215
|
|
216
216
|
it "returns nil if start time can not be parsed" do
|
217
|
-
doc.stub(:css).and_return mock(:text => "
|
217
|
+
doc.stub(:css).and_return mock(:text => "Sun Sep 32")
|
218
218
|
result.start_time.should be_nil
|
219
219
|
end
|
220
220
|
|
221
221
|
it "returns nil if start time can not be parsed" do
|
222
|
-
doc.stub(:css).and_return mock(:text => "
|
222
|
+
doc.stub(:css).and_return mock(:text => "Sun Sep 32")
|
223
223
|
result.end_time.should be_nil
|
224
224
|
end
|
225
225
|
|
@@ -7,11 +7,24 @@ module Bamboo
|
|
7
7
|
let(:document) { mock(Http::Json::Doc) }
|
8
8
|
let(:client) { Rest.new(http) }
|
9
9
|
|
10
|
+
it "logs in" do
|
11
|
+
username = 'something'
|
12
|
+
password = 'somethingelse'
|
13
|
+
http.should_receive(:get_cookies).with(
|
14
|
+
'/rest/api/latest/plan',
|
15
|
+
{:os_authType => 'basic', :os_username => username, :os_password => password}).
|
16
|
+
and_return({'JSESSIONID' => '1'})
|
17
|
+
client.login username, password
|
18
|
+
client.cookies.should == { :JSESSIONID => '1'}
|
19
|
+
end
|
20
|
+
|
10
21
|
it "should be able to fetch plans" do
|
11
22
|
document.should_receive(:auto_expand).with(Rest::Plan, http).and_return %w[foo bar]
|
12
23
|
|
13
24
|
http.should_receive(:get).with(
|
14
|
-
"/rest/api/latest/plan/"
|
25
|
+
"/rest/api/latest/plan/",
|
26
|
+
nil,
|
27
|
+
nil
|
15
28
|
).and_return(document)
|
16
29
|
|
17
30
|
client.plans.should == %w[foo bar]
|
@@ -20,7 +33,7 @@ module Bamboo
|
|
20
33
|
it "should be able to fetch projects" do
|
21
34
|
document.should_receive(:auto_expand).with(Rest::Project, http).and_return %w[foo bar]
|
22
35
|
|
23
|
-
http.should_receive(:get).with("/rest/api/latest/project/").
|
36
|
+
http.should_receive(:get).with("/rest/api/latest/project/", nil, nil).
|
24
37
|
and_return(document)
|
25
38
|
|
26
39
|
client.projects.should == %w[foo bar]
|
@@ -29,7 +42,7 @@ module Bamboo
|
|
29
42
|
it "should be able to fetch builds" do
|
30
43
|
document.should_receive(:auto_expand).with(Rest::Build, http).and_return %w[foo bar]
|
31
44
|
|
32
|
-
http.should_receive(:get).with("/rest/api/latest/build/").
|
45
|
+
http.should_receive(:get).with("/rest/api/latest/build/", nil, nil).
|
33
46
|
and_return(document)
|
34
47
|
|
35
48
|
client.builds.should == %w[foo bar]
|
metadata
CHANGED
@@ -1,17 +1,22 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bamboo-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 15
|
4
5
|
prerelease:
|
5
|
-
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 8
|
10
|
+
version: 0.0.8
|
6
11
|
platform: ruby
|
7
12
|
authors:
|
8
13
|
- Jari Bakken
|
14
|
+
- Peter Marsh
|
9
15
|
autorequire:
|
10
16
|
bindir: bin
|
11
17
|
cert_chain: []
|
12
18
|
|
13
|
-
date:
|
14
|
-
default_executable:
|
19
|
+
date: 2012-01-31 00:00:00 Z
|
15
20
|
dependencies:
|
16
21
|
- !ruby/object:Gem::Dependency
|
17
22
|
name: rspec
|
@@ -19,9 +24,13 @@ dependencies:
|
|
19
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
20
25
|
none: false
|
21
26
|
requirements:
|
22
|
-
- -
|
27
|
+
- - ~>
|
23
28
|
- !ruby/object:Gem::Version
|
24
|
-
|
29
|
+
hash: 9
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 5
|
33
|
+
version: "2.5"
|
25
34
|
type: :development
|
26
35
|
version_requirements: *id001
|
27
36
|
- !ruby/object:Gem::Dependency
|
@@ -32,6 +41,11 @@ dependencies:
|
|
32
41
|
requirements:
|
33
42
|
- - ">="
|
34
43
|
- !ruby/object:Gem::Version
|
44
|
+
hash: 55
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
- 10
|
48
|
+
- 0
|
35
49
|
version: 0.10.0
|
36
50
|
type: :development
|
37
51
|
version_requirements: *id002
|
@@ -43,45 +57,73 @@ dependencies:
|
|
43
57
|
requirements:
|
44
58
|
- - ">="
|
45
59
|
- !ruby/object:Gem::Version
|
60
|
+
hash: 3
|
61
|
+
segments:
|
62
|
+
- 0
|
46
63
|
version: "0"
|
47
64
|
type: :development
|
48
65
|
version_requirements: *id003
|
49
66
|
- !ruby/object:Gem::Dependency
|
50
|
-
name:
|
67
|
+
name: rake
|
51
68
|
prerelease: false
|
52
69
|
requirement: &id004 !ruby/object:Gem::Requirement
|
53
70
|
none: false
|
54
71
|
requirements:
|
55
|
-
- -
|
72
|
+
- - ~>
|
56
73
|
- !ruby/object:Gem::Version
|
57
|
-
|
58
|
-
|
74
|
+
hash: 25
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
- 9
|
78
|
+
version: "0.9"
|
79
|
+
type: :development
|
59
80
|
version_requirements: *id004
|
60
81
|
- !ruby/object:Gem::Dependency
|
61
|
-
name:
|
82
|
+
name: rest-client
|
62
83
|
prerelease: false
|
63
84
|
requirement: &id005 !ruby/object:Gem::Requirement
|
64
85
|
none: false
|
65
86
|
requirements:
|
66
87
|
- - ">="
|
67
88
|
- !ruby/object:Gem::Version
|
89
|
+
hash: 3
|
90
|
+
segments:
|
91
|
+
- 0
|
68
92
|
version: "0"
|
69
93
|
type: :runtime
|
70
94
|
version_requirements: *id005
|
71
95
|
- !ruby/object:Gem::Dependency
|
72
|
-
name:
|
96
|
+
name: json
|
73
97
|
prerelease: false
|
74
98
|
requirement: &id006 !ruby/object:Gem::Requirement
|
75
99
|
none: false
|
76
100
|
requirements:
|
77
101
|
- - ">="
|
78
102
|
- !ruby/object:Gem::Version
|
103
|
+
hash: 3
|
104
|
+
segments:
|
105
|
+
- 0
|
79
106
|
version: "0"
|
80
107
|
type: :runtime
|
81
108
|
version_requirements: *id006
|
109
|
+
- !ruby/object:Gem::Dependency
|
110
|
+
name: nokogiri
|
111
|
+
prerelease: false
|
112
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
hash: 3
|
118
|
+
segments:
|
119
|
+
- 0
|
120
|
+
version: "0"
|
121
|
+
type: :runtime
|
122
|
+
version_requirements: *id007
|
82
123
|
description: Ruby client for Atlassian Bamboo's REST APIs
|
83
124
|
email:
|
84
125
|
- jari.bakken@gmail.com
|
126
|
+
- pete.d.marsh@gmail.com
|
85
127
|
executables: []
|
86
128
|
|
87
129
|
extensions: []
|
@@ -91,6 +133,7 @@ extra_rdoc_files: []
|
|
91
133
|
files:
|
92
134
|
- .gitignore
|
93
135
|
- .rspec
|
136
|
+
- .travis.yml
|
94
137
|
- Gemfile
|
95
138
|
- LICENSE
|
96
139
|
- README
|
@@ -101,6 +144,7 @@ files:
|
|
101
144
|
- features/rest.feature
|
102
145
|
- features/step_definitions/remote_steps.rb
|
103
146
|
- features/step_definitions/rest_steps.rb
|
147
|
+
- features/step_definitions/rest_steps.rb~
|
104
148
|
- features/support/env.rb
|
105
149
|
- lib/bamboo-client.rb
|
106
150
|
- lib/bamboo-client/abstract.rb
|
@@ -124,7 +168,6 @@ files:
|
|
124
168
|
- spec/fixtures/plan.json
|
125
169
|
- spec/fixtures/project.json
|
126
170
|
- spec/spec_helper.rb
|
127
|
-
has_rdoc: true
|
128
171
|
homepage: ""
|
129
172
|
licenses: []
|
130
173
|
|
@@ -138,17 +181,23 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
138
181
|
requirements:
|
139
182
|
- - ">="
|
140
183
|
- !ruby/object:Gem::Version
|
184
|
+
hash: 3
|
185
|
+
segments:
|
186
|
+
- 0
|
141
187
|
version: "0"
|
142
188
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
189
|
none: false
|
144
190
|
requirements:
|
145
191
|
- - ">="
|
146
192
|
- !ruby/object:Gem::Version
|
193
|
+
hash: 3
|
194
|
+
segments:
|
195
|
+
- 0
|
147
196
|
version: "0"
|
148
197
|
requirements: []
|
149
198
|
|
150
199
|
rubyforge_project: bamboo-client
|
151
|
-
rubygems_version: 1.
|
200
|
+
rubygems_version: 1.8.15
|
152
201
|
signing_key:
|
153
202
|
specification_version: 3
|
154
203
|
summary: Ruby client for Atlassian Bamboo's REST APIs
|
@@ -157,6 +206,7 @@ test_files:
|
|
157
206
|
- features/rest.feature
|
158
207
|
- features/step_definitions/remote_steps.rb
|
159
208
|
- features/step_definitions/rest_steps.rb
|
209
|
+
- features/step_definitions/rest_steps.rb~
|
160
210
|
- features/support/env.rb
|
161
211
|
- spec/bamboo-client/client_spec.rb
|
162
212
|
- spec/bamboo-client/http/json_spec.rb
|
@@ -171,3 +221,4 @@ test_files:
|
|
171
221
|
- spec/fixtures/plan.json
|
172
222
|
- spec/fixtures/project.json
|
173
223
|
- spec/spec_helper.rb
|
224
|
+
has_rdoc:
|