circleci 1.0.3 → 1.1.0

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: 92e030c54f884f86c18121b16a7d5faf48a6fa1b
4
- data.tar.gz: eac0613d6ef27641244bc9363855e58114ee8e44
3
+ metadata.gz: c271b9c2906c8719ddbe6aaeac6e81629d9645e8
4
+ data.tar.gz: c8abb1f29b0977cb64577db02d530b03911c1357
5
5
  SHA512:
6
- metadata.gz: b8ebd62b3f3a224db444c2eaa403866217a0ca19fb1fc1ead80471e20510579d607296401735440cd4ab90822dd31411e737177cc60ce468e4a7d5185109886a
7
- data.tar.gz: ce048495a73a7363d6c679f40202a3e3d733b913f6afc13f64a13b1117bcbd358d7ec466dff00981e986b17890acb769f84bc595f806cb65ce56b7439c5a7582
6
+ metadata.gz: b260e331a7d82d2ae8f5b437fe1672eb045680e15fc85235d4bd1825527bd41cedbf791fb0928776cb2c881977920a468bad50a456e433db7a1b213aa1ada1ab
7
+ data.tar.gz: 9befc960bc2353e0410e308375ea5a9b4677a152bcd205c72b7e69a1434f6ffbfaccd887e21ca1da1e496970cf3953d2d11770b17e83806a9dda253ab71e921e
Binary file
data.tar.gz.sig CHANGED
Binary file
data/README.md CHANGED
@@ -731,7 +731,7 @@ Creates a new environment variable for a project
731
731
 
732
732
  ```ruby
733
733
  environment = { name: 'foo', value: 'bar' }
734
- res = CircleCi::Project.envvar 'username', 'repo', environment
734
+ res = CircleCi::Project.set_envvar 'username', 'repo', environment
735
735
  res.success?
736
736
  ```
737
737
 
@@ -1,12 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
  require 'json'
3
+ require 'logger'
3
4
  require 'net/http'
4
5
  require 'uri'
5
6
 
6
7
  files = %w[
8
+ api_resource
7
9
  build
8
10
  config
9
11
  project
12
+ projects
10
13
  recent_builds
11
14
  request
12
15
  response
@@ -38,7 +41,7 @@ module CircleCi
38
41
  @config ||= Config.new
39
42
  end
40
43
 
41
- def request(path, params = {})
42
- Request.new config, path, params
44
+ def request(conf, path, params = {})
45
+ Request.new conf, path, params
43
46
  end
44
47
  end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+ module CircleCi
3
+ ##
4
+ #
5
+ # ApiResource is a parent class for rest resources for the
6
+ # CircleCI API. It allows for request conifugration to be
7
+ # set per request if needed, otherwise the default global
8
+ # CircleCi.config is used
9
+ class ApiResource
10
+ attr_reader :conf, :project, :username
11
+
12
+ def initialize(username = nil, project = nil, conf = nil)
13
+ @username = username
14
+ @project = project
15
+ @conf = conf ? conf : default_config
16
+ end
17
+
18
+ def self.default_config
19
+ CircleCi.config
20
+ end
21
+
22
+ def default_config
23
+ self.class.default_config
24
+ end
25
+ end
26
+ end
@@ -3,66 +3,140 @@ module CircleCi
3
3
  ##
4
4
  #
5
5
  # Class for interacting with and managing builds
6
- class Build
6
+ class Build < ApiResource
7
+ attr_reader :build
7
8
  ##
8
9
  #
9
- # Get artifacts for a specific build of a project
10
+ # Initialize a Build object to interact with the Build API
10
11
  #
12
+ # @param config [CircleCi::Config] - Defaults to [default_config] if not provided
11
13
  # @param username [String] - User or org name who owns project
12
14
  # @param project [String] - Name of project
13
15
  # @param build [String] - Build ID
14
- # @return [CircleCi::Response] - Response object
15
- def self.artifacts(username, project, build)
16
- CircleCi.request("/project/#{username}/#{project}/#{build}/artifacts").get
16
+ # @return [CircleCi::Build] - A Build object
17
+ def initialize(username, project, build, conf = nil)
18
+ super(username, project, conf)
19
+ @build = build
20
+ end
21
+
22
+ ##
23
+ #
24
+ # Deprecated class methods
25
+ class << self
26
+ ##
27
+ #
28
+ # Get artifacts for a specific build of a project
29
+ #
30
+ # @deprecated Please use instance method of [CircleCi::Build] instead
31
+ # @param username [String] - User or org name who owns project
32
+ # @param project [String] - Name of project
33
+ # @param build [String] - Build ID
34
+ # @return [CircleCi::Response] - Response object
35
+ def artifacts(username, project, build)
36
+ default_config.logger.warn('[Deprecated] Use instance method CircleCi::Build#artifacts instead')
37
+ new(username, project, build, default_config).artifacts
38
+ end
39
+
40
+ ##
41
+ #
42
+ # Cancel a specific build
43
+ #
44
+ # @deprecated Please use instance method of [CircleCi::Build] instead
45
+ # @param username [String] - User or org name who owns project
46
+ # @param project [String] - Name of project
47
+ # @param build [String] - Build ID
48
+ # @return [CircleCi::Response] - Response object
49
+ def cancel(username, project, build)
50
+ default_config.logger.warn('[Deprecated] Use instance method CircleCi::Build#cancel instead')
51
+ new(username, project, build, default_config).cancel
52
+ end
53
+
54
+ ##
55
+ #
56
+ # Get a specific build for a project
57
+ #
58
+ # @deprecated Please use instance method of [CircleCi::Build] instead
59
+ # @param username [String] - User or org name who owns project
60
+ # @param project [String] - Name of project
61
+ # @param build [String] - Build ID
62
+ # @return [CircleCi::Response] - Response object
63
+ def get(username, project, build)
64
+ default_config.logger.warn('[Deprecated] Use instance method CircleCi::Build#get instead')
65
+ new(username, project, build, default_config).get
66
+ end
67
+
68
+ ##
69
+ #
70
+ # Kick off a retry of a specific build
71
+ #
72
+ # @deprecated Please use instance method of [CircleCi::Build] instead
73
+ # @param username [String] - User or org name who owns project
74
+ # @param project [String] - Name of project
75
+ # @param build [String] - Build ID
76
+ # @return [CircleCi::Response] - Response object
77
+ def retry(username, project, build)
78
+ default_config.logger.warn('[Deprecated] Use instance method CircleCi::Build#retry instead')
79
+ new(username, project, build, default_config).retry
80
+ end
81
+
82
+ ##
83
+ #
84
+ # Get tests for a specific build of a project
85
+ #
86
+ # @deprecated Please use instance method of [CircleCi::Build] instead
87
+ # @param username [String] - User or org name who owns project
88
+ # @param project [String] - Name of project
89
+ # @param build [String] - Build ID
90
+ # @return [CircleCi::Response] - Response object
91
+ def tests(username, project, build)
92
+ default_config.logger.warn('[Deprecated] Use instance method CircleCi::Build#tests instead')
93
+ new(username, project, build, default_config).tests
94
+ end
95
+ end
96
+
97
+ ##
98
+ #
99
+ # Get artifacts for a specific build of a project
100
+ #
101
+ # @return [CircleCi::Response] - Response object
102
+ def artifacts
103
+ CircleCi.request(@conf, "/project/#{username}/#{project}/#{build}/artifacts").get
17
104
  end
18
105
 
19
106
  ##
20
107
  #
21
108
  # Cancel a specific build
22
109
  #
23
- # @param username [String] - User or org name who owns project
24
- # @param project [String] - Name of project
25
- # @param build [String] - Build ID
26
- # @return [CircleCi::Response] - Response object
27
- def self.cancel(username, project, build)
28
- CircleCi.request("/project/#{username}/#{project}/#{build}/cancel").post
110
+ # @return [CircleCi::Response] - Response object
111
+ def cancel
112
+ CircleCi.request(@conf, "/project/#{username}/#{project}/#{build}/cancel").post
29
113
  end
30
114
 
31
115
  ##
32
116
  #
33
117
  # Get a specific build for a project
34
118
  #
35
- # @param username [String] - User or org name who owns project
36
- # @param project [String] - Name of project
37
- # @param build [String] - Build ID
38
- # @return [CircleCi::Response] - Response object
39
- def self.get(username, project, build)
40
- CircleCi.request("/project/#{username}/#{project}/#{build}").get
119
+ # @return [CircleCi::Response] - Response object
120
+ def get
121
+ CircleCi.request(@conf, "/project/#{username}/#{project}/#{build}").get
41
122
  end
42
123
 
43
124
  ##
44
125
  #
45
126
  # Kick off a retry of a specific build
46
127
  #
47
- # @param username [String] - User or org name who owns project
48
- # @param project [String] - Name of project
49
- # @param build [String] - Build ID
50
- # @return [CircleCi::Response] - Response object
51
- def self.retry(username, project, build)
52
- CircleCi.request("/project/#{username}/#{project}/#{build}/retry").post
128
+ # @return [CircleCi::Response] - Response object
129
+ def retry
130
+ CircleCi.request(@conf, "/project/#{username}/#{project}/#{build}/retry").post
53
131
  end
54
132
 
55
133
  ##
56
134
  #
57
135
  # Get tests for a specific build of a project
58
136
  #
59
- # @param username [String] - User or org name who owns project
60
- # @param project [String] - Name of project
61
- # @param build [String] - Build ID
62
137
  # @return [CircleCi::Response] - Response object
63
-
64
- def self.tests(username, project, build)
65
- CircleCi.request("/project/#{username}/#{project}/#{build}/tests").get
138
+ def tests
139
+ CircleCi.request(@conf, "/project/#{username}/#{project}/#{build}/tests").get
66
140
  end
67
141
  end
68
142
  end
@@ -11,18 +11,22 @@ module CircleCi
11
11
  DEFAULT_PORT = 443
12
12
 
13
13
  attr_accessor :token, :host, :port, :request_overrides, :version, :proxy,
14
- :proxy_host, :proxy_port, :proxy_user, :proxy_pass
14
+ :proxy_host, :proxy_port, :proxy_user, :proxy_pass, :logger
15
15
 
16
16
  ##
17
17
  #
18
18
  # @private
19
- def initialize
20
- @host = DEFAULT_HOST
21
- @port = DEFAULT_PORT
22
- @proxy = false
23
- @version = DEFAULT_VERSION
24
- @request_overrides = {}
19
+ # rubocop:disable Metrics/ParameterLists
20
+ def initialize(host: DEFAULT_HOST, port: DEFAULT_PORT, proxy: nil, version: DEFAULT_VERSION, token: nil, request_overrides: {}, logger: nil)
21
+ @host = host
22
+ @port = port
23
+ @proxy = proxy.nil? ? false : proxy
24
+ @version = version
25
+ @token = token
26
+ @request_overrides = request_overrides
27
+ @logger = logger ? logger : Logger.new(STDOUT)
25
28
  end
29
+ # rubocop:enable Metrics/ParameterLists
26
30
 
27
31
  def uri
28
32
  URI.parse("#{@host || DEFAULT_HOST}:#{@port || DEFAULT_PORT}/api/#{@version || DEFAULT_VERSION}")
@@ -3,76 +3,318 @@ module CircleCi
3
3
  ##
4
4
  #
5
5
  # Class for interacting with Projects
6
- class Project
6
+ # rubocop:disable Metrics/ClassLength
7
+ class Project < ApiResource
7
8
  ##
8
9
  #
9
- # Return all projects for your API key
10
- #
11
- # @return [CircleCi::Response] - Response object
12
- def self.all
13
- CircleCi.request('/projects').get
10
+ # Deprecated class methods
11
+ class << self
12
+ ##
13
+ #
14
+ # Return all projects for your API key
15
+ #
16
+ # @deprecated Please use instance method of [CircleCi::Project] instead
17
+ # @return [CircleCi::Response] - Response object
18
+ def all
19
+ default_config.logger.warn('[Deprecated] Use instance method CircleCi::Projects#get instead')
20
+ CircleCi::Projects.new.get
21
+ end
22
+
23
+ ##
24
+ #
25
+ # Build the latest master push for this project
26
+ #
27
+ # @deprecated Please use instance method of [CircleCi::Project] instead
28
+ # @param username [String] - User or org name who owns project
29
+ # @param project [String] - Name of project
30
+ # @return [CircleCi::Response] - Response object
31
+ def build(username, project)
32
+ default_config.logger.warn('[Deprecated] Use instance method CircleCi::Project#build instead')
33
+ new(username, project, default_config).build
34
+ end
35
+
36
+ ##
37
+ #
38
+ # Build the latest push for this branch of a specific project
39
+ #
40
+ # @deprecated Please use instance method of [CircleCi::Project] instead
41
+ # @param username [String] - User or org name who owns project
42
+ # @param project [String] - Name of project
43
+ # @param branch [String] - Name of branch
44
+ # @param body [Hash] - Optional post body with build parameters
45
+ # @return [CircleCi::Response] - Response object
46
+ def build_branch(username, project, branch, params = {}, body = {})
47
+ default_config.logger.warn('[Deprecated] Use instance method CircleCi::Project#build_branch instead')
48
+ new(username, project, default_config).build_branch(branch, params, body)
49
+ end
50
+
51
+ ##
52
+ #
53
+ # Add a ssh key to a build
54
+ #
55
+ # @deprecated Please use instance method of [CircleCi::Project] instead
56
+ # @param username [String] - User or org name who owns project
57
+ # @param project [String] - Name of project
58
+ # @param build [String] - Build number
59
+ # @param key [String] - The ssh private key
60
+ # @param hostname [String] - The hostname identified by the key
61
+ # @return [CircleCi::Response] - Response object
62
+ def build_ssh_key(username, project, build, key, hostname)
63
+ default_config.logger.warn('[Deprecated] Use instance method CircleCi::Project#build_ssh_key instead')
64
+ new(username, project, default_config).build_ssh_key(build, key, hostname)
65
+ end
66
+
67
+ ##
68
+ #
69
+ # Clear the build cache for a specific project
70
+ #
71
+ # @deprecated Please use instance method of [CircleCi::Project] instead
72
+ # @param username [String] - User or org name who owns project
73
+ # @param project [String] - Name of project
74
+ # @return [CircleCi::Response] - Response object
75
+ def clear_cache(username, project)
76
+ default_config.logger.warn('[Deprecated] Use instance method CircleCi::Project#clear_cache instead')
77
+ new(username, project, default_config).clear_cache
78
+ end
79
+
80
+ ##
81
+ #
82
+ # Delete a checkout key for a project
83
+ #
84
+ # @deprecated Please use instance method of [CircleCi::Project] instead
85
+ # @param username [String] - User or org name who owns project
86
+ # @param project [String] - Name of project
87
+ # @param fingerprint [String] - Fingerprint of a checkout key
88
+ # @return [CircleCi::Response] - Response object
89
+ def delete_checkout_key(username, project, fingerprint)
90
+ default_config.logger.warn('[Deprecated] Use instance method CircleCi::Project#delete_checkout_key instead')
91
+ new(username, project, default_config).delete_checkout_key(fingerprint)
92
+ end
93
+
94
+ ##
95
+ #
96
+ # Enable a project in CircleCI. Causes a CircleCI SSH key to be added to
97
+ # the GitHub. Requires admin privilege to the repository.
98
+ #
99
+ # @deprecated Please use instance method of [CircleCi::Project] instead
100
+ # @param username [String] - User or org name who owns project
101
+ # @param project [String] - Name of project
102
+ # @return [CircleCi::Response] - Response object
103
+ def enable(username, project)
104
+ default_config.logger.warn('[Deprecated] Use instance method CircleCi::Project#enable instead')
105
+ new(username, project, default_config).enable
106
+ end
107
+
108
+ ##
109
+ #
110
+ # Get the project envvars
111
+ #
112
+ # @deprecated Please use instance method of [CircleCi::Project] instead
113
+ # @param username [String] - User or org name who owns project
114
+ # @param project [String] - Name of project
115
+ # @return [CircleCi::Response] - Response object
116
+ def envvar(username, project)
117
+ default_config.logger.warn('[Deprecated] Use instance method CircleCi::Project#envvar instead')
118
+ new(username, project, default_config).envvar
119
+ end
120
+
121
+ ##
122
+ #
123
+ # @deprecated Please use [CircleCi::Project#envvar]
124
+ def envvars(username, project)
125
+ default_config.logger.warn('[Deprecated] CircleCi::Project#envvars is deprecated please use CircleCi::Project#envvar')
126
+ envvar username, project
127
+ end
128
+
129
+ ##
130
+ #
131
+ # Follow the project
132
+ #
133
+ # @deprecated Please use instance method of [CircleCi::Project] instead
134
+ # @param username [String] - User or org name who owns project
135
+ # @param project [String] - Name of project
136
+ # @return [CircleCi::Response] - Response object
137
+ def follow(username, project)
138
+ default_config.logger.warn('[Deprecated] Use instance method CircleCi::Project#follow instead')
139
+ new(username, project, default_config).follow
140
+ end
141
+
142
+ ##
143
+ #
144
+ # Get a checkout key for a project
145
+ #
146
+ # @deprecated Please use instance method of [CircleCi::Project] instead
147
+ # @param username [String] - User or org name who owns project
148
+ # @param project [String] - Name of project
149
+ # @param fingerprint [String] - Fingerprint of a checkout key
150
+ # @return [CircleCi::Response] - Response object
151
+ def get_checkout_key(username, project, fingerprint)
152
+ default_config.logger.warn('[Deprecated] Use instance method CircleCi::Project#get_checkout_key instead')
153
+ new(username, project, default_config).get_checkout_key(fingerprint)
154
+ end
155
+
156
+ ##
157
+ #
158
+ # Get a list of checkout keys for project
159
+ #
160
+ # @deprecated Please use instance method of [CircleCi::Project] instead
161
+ # @param username [String] - User or org name who owns project
162
+ # @param project [String] - Name of project
163
+ # @return [CircleCi::Response] - Response object
164
+ def list_checkout_keys(username, project)
165
+ default_config.logger.warn('[Deprecated] Use instance method CircleCi::Project#list_checkout_keys instead')
166
+ new(username, project, default_config).list_checkout_keys
167
+ end
168
+
169
+ ##
170
+ #
171
+ # Create a checkout key for a project
172
+ #
173
+ # @deprecated Please use instance method of [CircleCi::Project] instead
174
+ # @param username [String] - User or org name who owns project
175
+ # @param project [String] - Name of project
176
+ # @param type [String] - The type of key to create. Can be 'deploy-key' or 'github-user-key'.
177
+ # @return [CircleCi::Response] - Response object
178
+ def new_checkout_key(username, project, type)
179
+ default_config.logger.warn('[Deprecated] Use instance method CircleCi::Project#new_checkout_key instead')
180
+ new(username, project, default_config).new_checkout_key(type)
181
+ end
182
+
183
+ ##
184
+ #
185
+ # Get all recent builds for a specific project
186
+ #
187
+ # @deprecated Please use instance method of [CircleCi::Project] instead
188
+ # @param username [String] - User or org name who owns project
189
+ # @param project [String] - Name of project
190
+ # @param params [Hash] - Parameters for builds (limit, offset, filter)
191
+ # @return [CircleCi::Response] - Response object
192
+ def recent_builds(username, project, params = {})
193
+ default_config.logger.warn('[Deprecated] Use instance method CircleCi::Project#recent_builds instead')
194
+ new(username, project, default_config).recent_builds(params)
195
+ end
196
+
197
+ ##
198
+ #
199
+ # Get all recent builds for a specific branch of a project
200
+ #
201
+ # @deprecated Please use instance method of [CircleCi::Project] instead
202
+ # @param username [String] - User or org name who owns project
203
+ # @param project [String] - Name of project
204
+ # @param branch [String] - Name of branch
205
+ # @return [CircleCi::Response] - Response object
206
+ def recent_builds_branch(username, project, branch)
207
+ default_config.logger.warn('[Deprecated] Use instance method CircleCi::Project#recent_builds_branch instead')
208
+ new(username, project, default_config).recent_builds_branch(branch)
209
+ end
210
+
211
+ ##
212
+ #
213
+ # Get the project configuration
214
+ #
215
+ # @deprecated Please use instance method of [CircleCi::Project] instead
216
+ # @param username [String] - User or org name who owns project
217
+ # @param project [String] - Name of project
218
+ # @return [CircleCi::Response] - Response object
219
+ def settings(username, project)
220
+ default_config.logger.warn('[Deprecated] Use instance method CircleCi::Project#settings instead')
221
+ new(username, project, default_config).settings
222
+ end
223
+
224
+ ##
225
+ #
226
+ # Sets an envvar for a project
227
+ #
228
+ # @deprecated Please use instance method of [CircleCi::Project] instead
229
+ # @param username [String] - User or org name who owns project
230
+ # @param project [String] - Name of project
231
+ # @param envvar [Hash] - {name: 'foo', value: 'bar'}
232
+ # @return [CircleCi::Response] - Response object
233
+ def set_envvar(username, project, envvar)
234
+ default_config.logger.warn('[Deprecated] Use instance method CircleCi::Project#add_envvar instead')
235
+ new(username, project, default_config).add_envvar(envvar)
236
+ end
237
+
238
+ ##
239
+ #
240
+ # Add a ssh key to a project
241
+ #
242
+ # @deprecated Please use instance method of [CircleCi::Project] instead
243
+ # @param username [String] - User or org name who owns project
244
+ # @param project [String] - Name of project
245
+ # @param key [String] - The ssh private key
246
+ # @param hostname [String] - The hostname identified by the key
247
+ # @return [CircleCi::Response] - Response object
248
+ def ssh_key(username, project, key, hostname)
249
+ default_config.logger.warn('[Deprecated] Use instance method CircleCi::Project#ssh_key instead')
250
+ new(username, project, default_config).ssh_key(key, hostname)
251
+ end
252
+
253
+ ##
254
+ #
255
+ # Unfollow the project
256
+ #
257
+ # @deprecated Please use instance method of [CircleCi::Project] instead
258
+ # @param username [String] - User or org name who owns project
259
+ # @param project [String] - Name of project
260
+ # @return [CircleCi::Response] - Response object
261
+ def unfollow(username, project)
262
+ default_config.logger.warn('[Deprecated] Use instance method CircleCi::Project#unfollow instead')
263
+ new(username, project, default_config).unfollow
264
+ end
14
265
  end
15
266
 
16
267
  ##
17
268
  #
18
269
  # Build the latest master push for this project
19
270
  #
20
- # @param username [String] - User or org name who owns project
21
- # @param project [String] - Name of project
22
- # @return [CircleCi::Response] - Response object
23
- def self.build(username, project)
24
- CircleCi.request("/project/#{username}/#{project}").post
271
+ # @return [CircleCi::Response] - Response object
272
+ def build
273
+ CircleCi.request(@conf, "/project/#{username}/#{project}").post
25
274
  end
26
275
 
27
276
  ##
28
277
  #
29
278
  # Build the latest push for this branch of a specific project
30
279
  #
31
- # @param username [String] - User or org name who owns project
32
- # @param project [String] - Name of project
33
280
  # @param branch [String] - Name of branch
281
+ # @param params [Hash] - Optional params to send for building
34
282
  # @param body [Hash] - Optional post body with build parameters
35
283
  # @return [CircleCi::Response] - Response object
36
- def self.build_branch(username, project, branch, params = {}, body = {})
37
- CircleCi.request("/project/#{username}/#{project}/tree/#{branch}", params).post(body)
284
+ def build_branch(branch, params = {}, body = {})
285
+ CircleCi.request(@conf, "/project/#{username}/#{project}/tree/#{branch}", params).post(body)
38
286
  end
39
287
 
40
288
  ##
41
289
  #
42
290
  # Add a ssh key to a build
43
291
  #
44
- # @param username [String] - User or org name who owns project
45
- # @param project [String] - Name of project
46
292
  # @param build [String] - Build number
47
293
  # @param key [String] - The ssh private key
48
294
  # @param hostname [String] - The hostname identified by the key
49
295
  # @return [CircleCi::Response] - Response object
50
- def self.build_ssh_key(username, project, build, key, hostname)
296
+ def build_ssh_key(build, key, hostname)
51
297
  body = { hostname: hostname, private_key: key }
52
- CircleCi.request("/project/#{username}/#{project}/#{build}/ssh-users").post(body)
298
+ CircleCi.request(@conf, "/project/#{username}/#{project}/#{build}/ssh-users").post(body)
53
299
  end
54
300
 
55
301
  ##
56
302
  #
57
303
  # Clear the build cache for a specific project
58
304
  #
59
- # @param username [String] - User or org name who owns project
60
- # @param project [String] - Name of project
61
- # @return [CircleCi::Response] - Response object
62
- def self.clear_cache(username, project)
63
- CircleCi.request("/project/#{username}/#{project}/build-cache").delete
305
+ # @return [CircleCi::Response] - Response object
306
+ def clear_cache
307
+ CircleCi.request(@conf, "/project/#{username}/#{project}/build-cache").delete
64
308
  end
65
309
 
66
310
  ##
67
311
  #
68
312
  # Delete a checkout key for a project
69
313
  #
70
- # @param username [String] - User or org name who owns project
71
- # @param project [String] - Name of project
72
314
  # @param fingerprint [String] - Fingerprint of a checkout key
73
315
  # @return [CircleCi::Response] - Response object
74
- def self.delete_checkout_key(username, project, fingerprint)
75
- CircleCi.request("/project/#{username}/#{project}/checkout-key/#{fingerprint}").delete
316
+ def delete_checkout_key(fingerprint)
317
+ CircleCi.request(@conf, "/project/#{username}/#{project}/checkout-key/#{fingerprint}").delete
76
318
  end
77
319
 
78
320
  ##
@@ -80,152 +322,117 @@ module CircleCi
80
322
  # Enable a project in CircleCI. Causes a CircleCI SSH key to be added to
81
323
  # the GitHub. Requires admin privilege to the repository.
82
324
  #
83
- # @param username [String] - User or org name who owns project
84
- # @param project [String] - Name of project
85
- # @return [CircleCi::Response] - Response object
86
- def self.enable(username, project)
87
- CircleCi.request("/project/#{username}/#{project}/enable").post
325
+ # @return [CircleCi::Response] - Response object
326
+ def enable
327
+ CircleCi.request(@conf, "/project/#{username}/#{project}/enable").post
88
328
  end
89
329
 
90
330
  ##
91
331
  #
92
332
  # Get the project envvars
93
333
  #
94
- # @param username [String] - User or org name who owns project
95
- # @param project [String] - Name of project
96
- # @return [CircleCi::Response] - Response object
97
- def self.envvar(username, project)
98
- CircleCi.request("/project/#{username}/#{project}/envvar").get
99
- end
100
-
101
- ##
102
- #
103
- # @deprecated Please use [CircleCi::Project#envvar]
104
- def self.envvars(username, project)
105
- # NOTE: Make logger configurable on config object?
106
- logger = Logger.new(STDOUT)
107
- logger.warn('[Deprecated] Project#envvars is deprecated please use Project#envvar')
108
- envvar username, project
109
- end
110
-
111
- ##
112
- #
113
- # Sets an envvar for a project
114
- #
115
- # @param username [String] - User or org name who owns project
116
- # @param project [String] - Name of project
117
- # @param envvar [Hash] - {name: 'foo', value: 'bar'}
118
- # @return [CircleCi::Response] - Response object
119
- def self.set_envvar(username, project, envvar)
120
- CircleCi.request("/project/#{username}/#{project}/envvar").post(envvar)
334
+ # @return [CircleCi::Response] - Response object
335
+ def envvar
336
+ CircleCi.request(@conf, "/project/#{username}/#{project}/envvar").get
121
337
  end
122
338
 
123
339
  ##
124
340
  #
125
341
  # Follow the project
126
342
  #
127
- # @param username [String] - User or org name who owns project
128
- # @param project [String] - Name of project
129
- # @return [CircleCi::Response] - Response object
130
- def self.follow(username, project)
131
- CircleCi.request("/project/#{username}/#{project}/follow").post
343
+ # @return [CircleCi::Response] - Response object
344
+ def follow
345
+ CircleCi.request(@conf, "/project/#{username}/#{project}/follow").post
132
346
  end
133
347
 
134
348
  ##
135
349
  #
136
350
  # Get a checkout key for a project
137
351
  #
138
- # @param username [String] - User or org name who owns project
139
- # @param project [String] - Name of project
140
352
  # @param fingerprint [String] - Fingerprint of a checkout key
141
353
  # @return [CircleCi::Response] - Response object
142
- def self.get_checkout_key(username, project, fingerprint)
143
- CircleCi.request("/project/#{username}/#{project}/checkout-key/#{fingerprint}").get
354
+ def get_checkout_key(fingerprint)
355
+ CircleCi.request(@conf, "/project/#{username}/#{project}/checkout-key/#{fingerprint}").get
144
356
  end
145
357
 
146
358
  ##
147
359
  #
148
360
  # Get a list of checkout keys for project
149
361
  #
150
- # @param username [String] - User or org name who owns project
151
- # @param project [String] - Name of project
152
- # @return [CircleCi::Response] - Response object
153
- def self.list_checkout_keys(username, project)
154
- CircleCi.request("/project/#{username}/#{project}/checkout-key").get
362
+ # @return [CircleCi::Response] - Response object
363
+ def list_checkout_keys
364
+ CircleCi.request(@conf, "/project/#{username}/#{project}/checkout-key").get
155
365
  end
156
366
 
157
367
  ##
158
368
  #
159
369
  # Create a checkout key for a project
160
370
  #
161
- # @param username [String] - User or org name who owns project
162
- # @param project [String] - Name of project
163
- # @param type [String] - The type of key to create. Can be 'deploy-key' or 'github-user-key'.
164
- # @return [CircleCi::Response] - Response object
165
-
166
- def self.new_checkout_key(username, project, type)
167
- CircleCi.request("/project/#{username}/#{project}/checkout-key").post(type: type)
371
+ # @param type [String] - The type of key to create. Can be 'deploy-key' or 'github-user-key'.
372
+ # @return [CircleCi::Response] - Response object
373
+ def new_checkout_key(type)
374
+ CircleCi.request(@conf, "/project/#{username}/#{project}/checkout-key").post(type: type)
168
375
  end
169
376
 
170
377
  ##
171
378
  #
172
379
  # Get all recent builds for a specific project
173
380
  #
174
- # @param username [String] - User or org name who owns project
175
- # @param project [String] - Name of project
176
381
  # @param params [Hash] - Parameters for builds (limit, offset, filter)
177
382
  # @return [CircleCi::Response] - Response object
178
-
179
- def self.recent_builds(username, project, params = {})
180
- CircleCi.request("/project/#{username}/#{project}", params).get
383
+ def recent_builds(params = {})
384
+ CircleCi.request(@conf, "/project/#{username}/#{project}", params).get
181
385
  end
182
386
 
183
387
  ##
184
388
  #
185
389
  # Get all recent builds for a specific branch of a project
186
390
  #
187
- # @param username [String] - User or org name who owns project
188
- # @param project [String] - Name of project
189
- # @param branch [String] - Name of branch
190
- # @return [CircleCi::Response] - Response object
191
- def self.recent_builds_branch(username, project, branch)
192
- CircleCi.request("/project/#{username}/#{project}/tree/#{branch}").get
391
+ # @param branch [String] - Name of branch
392
+ # @return [CircleCi::Response] - Response object
393
+ def recent_builds_branch(branch)
394
+ CircleCi.request(@conf, "/project/#{username}/#{project}/tree/#{branch}").get
193
395
  end
194
396
 
195
397
  ##
196
398
  #
197
399
  # Get the project configuration
198
400
  #
199
- # @param username [String] - User or org name who owns project
200
- # @param project [String] - Name of project
201
- # @return [CircleCi::Response] - Response object
202
- def self.settings(username, project)
203
- CircleCi.request("/project/#{username}/#{project}/settings").get
401
+ # @return [CircleCi::Response] - Response object
402
+ def settings
403
+ CircleCi.request(@conf, "/project/#{username}/#{project}/settings").get
404
+ end
405
+
406
+ ##
407
+ #
408
+ # Adds an envvar for a project
409
+ #
410
+ # @param envvar [Hash] - {name: 'foo', value: 'bar'}
411
+ # @return [CircleCi::Response] - Response object
412
+ def add_envvar(envvar)
413
+ CircleCi.request(@conf, "/project/#{username}/#{project}/envvar").post(envvar)
204
414
  end
205
415
 
206
416
  ##
207
417
  #
208
418
  # Add a ssh key to a project
209
419
  #
210
- # @param username [String] - User or org name who owns project
211
- # @param project [String] - Name of project
212
420
  # @param key [String] - The ssh private key
213
421
  # @param hostname [String] - The hostname identified by the key
214
422
  # @return [CircleCi::Response] - Response object
215
- def self.ssh_key(username, project, key, hostname)
423
+ def ssh_key(key, hostname)
216
424
  body = { hostname: hostname, private_key: key }
217
- CircleCi.request("/project/#{username}/#{project}/ssh-key").post(body)
425
+ CircleCi.request(@conf, "/project/#{username}/#{project}/ssh-key").post(body)
218
426
  end
219
427
 
220
428
  ##
221
429
  #
222
430
  # Unfollow the project
223
431
  #
224
- # @param username [String] - User or org name who owns project
225
- # @param project [String] - Name of project
226
- # @return [CircleCi::Response] - Response object
227
- def self.unfollow(username, project)
228
- CircleCi.request("/project/#{username}/#{project}/unfollow").post
432
+ # @return [CircleCi::Response] - Response object
433
+ def unfollow
434
+ CircleCi.request(@conf, "/project/#{username}/#{project}/unfollow").post
229
435
  end
230
436
  end
437
+ # rubocop:enable Metrics/ClassLength
231
438
  end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+ module CircleCi
3
+ ##
4
+ #
5
+ # Class for getting all your Projects on CircleCI
6
+ class Projects < ApiResource
7
+ ##
8
+ #
9
+ # Initialize a Projects resource to get all projects
10
+ #
11
+ # @param config [CircleCi::Config] - Defaults to [default_config] if not provided
12
+ # @return [CircleCi::Projects] - A Projects object
13
+ def initialize(conf = nil)
14
+ super(nil, nil, conf)
15
+ end
16
+
17
+ ##
18
+ #
19
+ # Get all projects for your API key
20
+ #
21
+ # @return [CircleCi::Response] - Response object
22
+ def get
23
+ CircleCi.request(@conf, '/projects').get
24
+ end
25
+ end
26
+ end
@@ -3,15 +3,42 @@ module CircleCi
3
3
  ##
4
4
  #
5
5
  # Class for interacting with recent builds
6
- class RecentBuilds
6
+ class RecentBuilds < ApiResource
7
+ ##
8
+ #
9
+ # Initialize a new RecentBuilds API interaction
10
+ #
11
+ # @param conf [CircleCi::Config] - Optional config to use for request
12
+ # @return [CircleCi::RecentBuilds]
13
+ def initialize(conf = nil)
14
+ super(nil, nil, conf)
15
+ end
16
+
17
+ ##
18
+ #
19
+ # Deprecated class methods
20
+ class << self
21
+ ##
22
+ #
23
+ # Get get recent builds for your account
24
+ #
25
+ # @deprecated Please use instance method of [CircleCi::RecentBuilds] instead
26
+ # @param params [Hash] - Params to send for recent builds (limit, offset)
27
+ # @return [CircleCi::Response] - Response object
28
+ def get(params = {})
29
+ default_config.logger.warn('[Deprecated] Use instance method CircleCi::RecentBuilds#get instead')
30
+ new(default_config).get(params)
31
+ end
32
+ end
33
+
7
34
  ##
8
35
  #
9
36
  # Get get recent builds for your account
10
37
  #
11
38
  # @param params [Hash] - Params to send for recent builds (limit, offset)
12
- # @return [CircleCi::Response] - Response object
13
- def self.get(params = {})
14
- CircleCi.request('/recent-builds', params).get
39
+ # @return [CircleCi::Response] - Response object
40
+ def get(params = {})
41
+ CircleCi.request(@conf, '/recent-builds', params).get
15
42
  end
16
43
  end
17
44
  end
@@ -3,14 +3,49 @@ module CircleCi
3
3
  ##
4
4
  #
5
5
  # User class to access user details for a specific API key
6
- class User
6
+ class User < ApiResource
7
+ ##
8
+ #
9
+ # Initialize a new RecentBuilds API interaction
10
+ #
11
+ # @param conf [CircleCi::Config] - Optional config to use for request
12
+ # @return [CircleCi::RecentBuilds]
13
+ def initialize(conf = nil)
14
+ super(nil, nil, conf)
15
+ end
16
+
17
+ class << self
18
+ ##
19
+ #
20
+ # Get user account details
21
+ #
22
+ # @deprecated Please use instance method of [CircleCi::User] instead
23
+ # @return [CircleCi::Response] - Response object
24
+ def me
25
+ default_config.logger.warn('[Deprecated] Use instance method CircleCi::User#me instead')
26
+ new(default_config).me
27
+ end
28
+
29
+ ##
30
+ #
31
+ # Add a Heroku API key to CircleCI
32
+ #
33
+ # @deprecated Please use instance method of [CircleCi::User] instead
34
+ # @param apikey [String] - The Heroku API key
35
+ # @return [CircleCi::Response] - Response object
36
+ def heroku_key(apikey)
37
+ default_config.logger.warn('[Deprecated] Use instance method CircleCi::User#heroku_key instead')
38
+ new(default_config).heroku_key(apikey)
39
+ end
40
+ end
41
+
7
42
  ##
8
43
  #
9
44
  # Get user account details
10
45
  #
11
46
  # @return [CircleCi::Response] - Response object
12
- def self.me
13
- CircleCi.request('/me').get
47
+ def me
48
+ CircleCi.request(@conf, '/me').get
14
49
  end
15
50
 
16
51
  ##
@@ -19,8 +54,8 @@ module CircleCi
19
54
  #
20
55
  # @param apikey [String] - The Heroku API key
21
56
  # @return [CircleCi::Response] - Response object
22
- def self.heroku_key(apikey)
23
- CircleCi.request('/user/heroku-key').post(apikey: apikey)
57
+ def heroku_key(apikey)
58
+ CircleCi.request(@conf, '/user/heroku-key').post(apikey: apikey)
24
59
  end
25
60
  end
26
61
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: circleci
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chavez
@@ -30,7 +30,7 @@ cert_chain:
30
30
  7DerzHxWdPmU1DsMCCh7B3R2HH0TONFQ67h7FuJPvLQkvbUuwzzjzpBwfhdCIEFn
31
31
  WUW78NBBFETQzQE3nG9TifbcEDrx/dODsAFzoQ==
32
32
  -----END CERTIFICATE-----
33
- date: 2016-09-30 00:00:00.000000000 Z
33
+ date: 2017-03-20 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: coveralls
@@ -132,6 +132,46 @@ dependencies:
132
132
  - - ">="
133
133
  - !ruby/object:Gem::Version
134
134
  version: 0.10.4
135
+ - !ruby/object:Gem::Dependency
136
+ name: pry-byebug
137
+ requirement: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - "~>"
140
+ - !ruby/object:Gem::Version
141
+ version: 3.4.2
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: 3.4.2
145
+ type: :development
146
+ prerelease: false
147
+ version_requirements: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - "~>"
150
+ - !ruby/object:Gem::Version
151
+ version: 3.4.2
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: 3.4.2
155
+ - !ruby/object:Gem::Dependency
156
+ name: pry-doc
157
+ requirement: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - "~>"
160
+ - !ruby/object:Gem::Version
161
+ version: 0.10.0
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: 0.10.0
165
+ type: :development
166
+ prerelease: false
167
+ version_requirements: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - "~>"
170
+ - !ruby/object:Gem::Version
171
+ version: 0.10.0
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: 0.10.0
135
175
  - !ruby/object:Gem::Dependency
136
176
  name: rake
137
177
  requirement: !ruby/object:Gem::Requirement
@@ -321,9 +361,11 @@ extra_rdoc_files:
321
361
  files:
322
362
  - README.md
323
363
  - lib/circleci.rb
364
+ - lib/circleci/api_resource.rb
324
365
  - lib/circleci/build.rb
325
366
  - lib/circleci/config.rb
326
367
  - lib/circleci/project.rb
368
+ - lib/circleci/projects.rb
327
369
  - lib/circleci/recent_builds.rb
328
370
  - lib/circleci/request.rb
329
371
  - lib/circleci/response.rb
@@ -350,7 +392,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
350
392
  version: '0'
351
393
  requirements: []
352
394
  rubyforge_project:
353
- rubygems_version: 2.5.1
395
+ rubygems_version: 2.5.2
354
396
  signing_key:
355
397
  specification_version: 4
356
398
  summary: Circle CI REST API gem
metadata.gz.sig CHANGED
Binary file