circleci 0.2.3 → 1.0.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: 2b593d6e0bcf64fc14fb6ad923be106b6909cbd3
4
- data.tar.gz: 702ed7c6b41beef442a87c7d1f6ce0139a0fd51e
3
+ metadata.gz: 426c654a19583455c23e8d161e920c830c46ff88
4
+ data.tar.gz: 223fe31474077ccaa5e9ae0ac0be8e7a14c9df18
5
5
  SHA512:
6
- metadata.gz: a13042709bc07021325712265b2060d7b9fa4551bfd78163b90f337d6008c52d77cfe201f11d1a3f3331c3aafe705337e49f6064ca8bb89af870c4c97447772a
7
- data.tar.gz: b795a0a4b3bbff5acac6b7bd8441e82859ae4e9a696df45b1fc86c189c185de0991c5ccbbf4ce5a478ac788729f94d1c1460df6453dfd292b4bbce9daf7e06e0
6
+ metadata.gz: 9b6ea327972d7410aa4f2517b371039d87eeb9c91e7e16579a7610fc204188af9aba60bd7264ccc52782079a7bc0c13a5ed4faf141e80331f010d74c2888839d
7
+ data.tar.gz: 8f06b56a261f848aafc53ebc5f37d5c4042606e7be3e25b726522afcbf562cfb6eab86273a06800bda73826d3119a39f4d6ae2a290718507a56be27fb9380451
data/README.md CHANGED
@@ -7,7 +7,7 @@ circleci
7
7
  [![Coverage Status](https://coveralls.io/repos/mtchavez/circleci/badge.png)](https://coveralls.io/r/mtchavez/circleci)
8
8
  [![Dependency Status](https://gemnasium.com/mtchavez/circleci.svg)](https://gemnasium.com/mtchavez/circleci)
9
9
 
10
- Circle CI API Wrapper
10
+ Circle CI API Wrapper. Requires ruby `>= 2.0.0`.
11
11
 
12
12
  ## Install
13
13
 
@@ -49,12 +49,29 @@ Overriding request settings such as not verifying SSL
49
49
  ```ruby
50
50
  CircleCi.configure do |config|
51
51
  config.token = ENV['CIRCLECI_TOKEN']
52
+ config.host = 'http://ci.mycompany.com'
53
+ config.port = 80
52
54
  config.request_overrides = {
55
+ use_ssl: false,
53
56
  verify_ssl: false
54
57
  }
55
58
  end
56
59
  ```
57
60
 
61
+ Setup for proxying requests
62
+ ```ruby
63
+ require 'circleci'
64
+
65
+ CircleCi.configure do |config|
66
+ config.token = ENV['CIRCLECI_TOKEN']
67
+ config.proxy_host = 'http://ciproxy.mycompany.com'
68
+ config.proxy_port = 8000
69
+ config.proxy_user = 'myci'
70
+ config.proxy_pass = 'supersecret'
71
+ config.proxy = true
72
+ end
73
+ ```
74
+
58
75
  ## API Endpoints
59
76
 
60
77
  * [User](#user)
@@ -190,6 +207,18 @@ Build a specific branch of a project
190
207
  res = CircleCi::Project.build_branch 'username', 'reponame', 'branch'
191
208
  res.body['status'] # Not running
192
209
  res.body['build_url'] # Get url of build
210
+
211
+ # Passing build parameters in the post body
212
+ build_params = { build_parameters: { 'MY_TOKEN' => '123asd123asd' } }
213
+ res = CircleCi::Project.build_branch 'username', 'reponame', 'branch', {}, build_params
214
+ res.body['status'] # Not running
215
+ res.body['build_url'] # Get url of build
216
+
217
+ # Adding URL params for revision or parallel
218
+ params = { revision: 'fda12345asdf', parallel: 2 }
219
+ res = CircleCi::Project.build_branch 'username', 'reponame', 'branch', params
220
+ res.body['status'] # Not running
221
+ res.body['build_url'] # Get url of build
193
222
  ```
194
223
 
195
224
  Example response
@@ -1,14 +1,14 @@
1
+ # frozen_string_literal: true
1
2
  require 'json'
2
- require 'rest-client'
3
3
  require 'net/http'
4
+ require 'uri'
4
5
 
5
6
  files = %w[
6
7
  build
7
8
  config
8
- http
9
9
  project
10
10
  recent_builds
11
- request_error
11
+ request
12
12
  response
13
13
  user
14
14
  ]
@@ -27,7 +27,6 @@ module CircleCi
27
27
  # CircleCi.configure do |config|
28
28
  # config.token = 'my-token'
29
29
  # end
30
-
31
30
  def configure
32
31
  yield config
33
32
  end
@@ -35,12 +34,11 @@ module CircleCi
35
34
  ##
36
35
  #
37
36
  # @return [CircleCi::Config]
38
-
39
37
  def config
40
38
  @config ||= Config.new
41
39
  end
42
40
 
43
- def http # @private
44
- Http.new(config)
41
+ def request(path, params = {})
42
+ Request.new config, path, params
45
43
  end
46
44
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module CircleCi
2
3
  ##
3
4
  #
@@ -11,9 +12,8 @@ module CircleCi
11
12
  # @param project [String] - Name of project
12
13
  # @param build [String] - Build ID
13
14
  # @return [CircleCi::Response] - Response object
14
-
15
15
  def self.artifacts(username, project, build)
16
- CircleCi.http.get "/project/#{username}/#{project}/#{build}/artifacts"
16
+ CircleCi.request("/project/#{username}/#{project}/#{build}/artifacts").get
17
17
  end
18
18
 
19
19
  ##
@@ -24,9 +24,8 @@ module CircleCi
24
24
  # @param project [String] - Name of project
25
25
  # @param build [String] - Build ID
26
26
  # @return [CircleCi::Response] - Response object
27
-
28
27
  def self.cancel(username, project, build)
29
- CircleCi.http.post "/project/#{username}/#{project}/#{build}/cancel"
28
+ CircleCi.request("/project/#{username}/#{project}/#{build}/cancel").post
30
29
  end
31
30
 
32
31
  ##
@@ -37,9 +36,8 @@ module CircleCi
37
36
  # @param project [String] - Name of project
38
37
  # @param build [String] - Build ID
39
38
  # @return [CircleCi::Response] - Response object
40
-
41
39
  def self.get(username, project, build)
42
- CircleCi.http.get "/project/#{username}/#{project}/#{build}"
40
+ CircleCi.request("/project/#{username}/#{project}/#{build}").get
43
41
  end
44
42
 
45
43
  ##
@@ -50,9 +48,8 @@ module CircleCi
50
48
  # @param project [String] - Name of project
51
49
  # @param build [String] - Build ID
52
50
  # @return [CircleCi::Response] - Response object
53
-
54
51
  def self.retry(username, project, build)
55
- CircleCi.http.post "/project/#{username}/#{project}/#{build}/retry"
52
+ CircleCi.request("/project/#{username}/#{project}/#{build}/retry").post
56
53
  end
57
54
 
58
55
  ##
@@ -65,7 +62,7 @@ module CircleCi
65
62
  # @return [CircleCi::Response] - Response object
66
63
 
67
64
  def self.tests(username, project, build)
68
- CircleCi.http.get "/project/#{username}/#{project}/#{build}/tests"
65
+ CircleCi.request("/project/#{username}/#{project}/#{build}/tests").get
69
66
  end
70
67
  end
71
68
  end
@@ -1,41 +1,46 @@
1
+ # frozen_string_literal: true
1
2
  module CircleCi
2
3
  ##
3
4
  #
4
5
  # Config class used internally.
5
- # Configure API calls using AlPapi.configure
6
+ # Configure API calls using CircleCi.configure
6
7
  class Config
7
8
  DEFAULT_VERSION = 'v1'.freeze
8
9
  DEFAULT_HOST = 'https://circleci.com'.freeze
9
10
  DEFAULT_URI = "#{DEFAULT_HOST}/api/#{DEFAULT_VERSION}".freeze
10
- DEFAULT_PORT = 80
11
+ DEFAULT_PORT = 443
11
12
 
12
- attr_accessor :token, :host, :port, :request_overrides, :version
13
+ attr_accessor :token, :host, :port, :request_overrides, :version, :proxy,
14
+ :proxy_host, :proxy_port, :proxy_user, :proxy_pass
13
15
 
14
16
  ##
15
17
  #
16
18
  # @private
17
-
18
19
  def initialize
19
20
  @host = DEFAULT_HOST
20
21
  @port = DEFAULT_PORT
22
+ @proxy = false
21
23
  @version = DEFAULT_VERSION
22
24
  @request_overrides = {}
23
25
  end
24
26
 
25
27
  def uri
26
- base = @host
27
- base += ":#{@port}" unless port_80? || host_has_port?
28
- base + "/api/#{@version}"
28
+ URI.parse("#{@host || DEFAULT_HOST}:#{@port || DEFAULT_PORT}/api/#{@version || DEFAULT_VERSION}")
29
29
  end
30
30
 
31
- private
31
+ def proxy_userinfo?
32
+ @proxy_user && @proxy_pass
33
+ end
32
34
 
33
- def port_80?
34
- @port == DEFAULT_PORT
35
+ def proxy_port
36
+ @proxy_port ? @proxy_port : 80
35
37
  end
36
38
 
37
- def host_has_port?
38
- @host =~ /:\d{1,7}$/
39
+ def proxy_uri
40
+ return unless @proxy && @proxy_host
41
+ host_uri = URI.parse(@proxy_host)
42
+ userinfo = proxy_userinfo? ? "#{@proxy_user}:#{@proxy_pass}@" : ''
43
+ URI.parse("#{host_uri.scheme}://#{userinfo}#{host_uri.host}:#{proxy_port}#{host_uri.path}")
39
44
  end
40
45
  end
41
46
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module CircleCi
2
3
  ##
3
4
  #
@@ -8,9 +9,8 @@ module CircleCi
8
9
  # Return all projects for your API key
9
10
  #
10
11
  # @return [CircleCi::Response] - Response object
11
-
12
12
  def self.all
13
- CircleCi.http.get '/projects'
13
+ CircleCi.request('/projects').get
14
14
  end
15
15
 
16
16
  ##
@@ -20,9 +20,8 @@ module CircleCi
20
20
  # @param username [String] - User or org name who owns project
21
21
  # @param project [String] - Name of project
22
22
  # @return [CircleCi::Response] - Response object
23
-
24
23
  def self.build(username, project)
25
- CircleCi.http.post "/project/#{username}/#{project}"
24
+ CircleCi.request("/project/#{username}/#{project}").post
26
25
  end
27
26
 
28
27
  ##
@@ -32,13 +31,10 @@ module CircleCi
32
31
  # @param username [String] - User or org name who owns project
33
32
  # @param project [String] - Name of project
34
33
  # @param branch [String] - Name of branch
35
- # @param build_parameters [Hash] - Optional Build Parameters
34
+ # @param body [Hash] - Optional post body with build parameters
36
35
  # @return [CircleCi::Response] - Response object
37
-
38
- def self.build_branch(username, project, branch, build_parameters = {})
39
- body = {}
40
- body['build_parameters'] = build_parameters unless build_parameters.empty?
41
- CircleCi.http.post "/project/#{username}/#{project}/tree/#{branch}", {}, body
36
+ def self.build_branch(username, project, branch, params = {}, body = {})
37
+ CircleCi.request("/project/#{username}/#{project}/tree/#{branch}", params).post(body)
42
38
  end
43
39
 
44
40
  ##
@@ -53,7 +49,7 @@ module CircleCi
53
49
  # @return [CircleCi::Response] - Response object
54
50
  def self.build_ssh_key(username, project, build, key, hostname)
55
51
  body = { hostname: hostname, private_key: key }
56
- CircleCi.http.post "/project/#{username}/#{project}/#{build}/ssh-users", {}, body
52
+ CircleCi.request("/project/#{username}/#{project}/#{build}/ssh-users").post(body)
57
53
  end
58
54
 
59
55
  ##
@@ -63,9 +59,8 @@ module CircleCi
63
59
  # @param username [String] - User or org name who owns project
64
60
  # @param project [String] - Name of project
65
61
  # @return [CircleCi::Response] - Response object
66
-
67
62
  def self.clear_cache(username, project)
68
- CircleCi.http.delete "/project/#{username}/#{project}/build-cache"
63
+ CircleCi.request("/project/#{username}/#{project}/build-cache").delete
69
64
  end
70
65
 
71
66
  ##
@@ -76,9 +71,8 @@ module CircleCi
76
71
  # @param project [String] - Name of project
77
72
  # @param fingerprint [String] - Fingerprint of a checkout key
78
73
  # @return [CircleCi::Response] - Response object
79
-
80
74
  def self.delete_checkout_key(username, project, fingerprint)
81
- CircleCi.http.delete "/project/#{username}/#{project}/checkout-key/#{fingerprint}"
75
+ CircleCi.request("/project/#{username}/#{project}/checkout-key/#{fingerprint}").delete
82
76
  end
83
77
 
84
78
  ##
@@ -89,9 +83,8 @@ module CircleCi
89
83
  # @param username [String] - User or org name who owns project
90
84
  # @param project [String] - Name of project
91
85
  # @return [CircleCi::Response] - Response object
92
-
93
86
  def self.enable(username, project)
94
- CircleCi.http.post "/project/#{username}/#{project}/enable"
87
+ CircleCi.request("/project/#{username}/#{project}/enable").delete
95
88
  end
96
89
 
97
90
  ##
@@ -101,9 +94,18 @@ module CircleCi
101
94
  # @param username [String] - User or org name who owns project
102
95
  # @param project [String] - Name of project
103
96
  # @return [CircleCi::Response] - Response object
97
+ def self.envvar(username, project)
98
+ CircleCi.request("/project/#{username}/#{project}/envvar").get
99
+ end
104
100
 
101
+ ##
102
+ #
103
+ # @deprecated Please use [CircleCi::Project#envvar]
105
104
  def self.envvars(username, project)
106
- CircleCi.http.get "/project/#{username}/#{project}/envvar"
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
107
109
  end
108
110
 
109
111
  ##
@@ -114,10 +116,8 @@ module CircleCi
114
116
  # @param project [String] - Name of project
115
117
  # @param envvar [Hash] - {name: 'foo', value: 'bar'}
116
118
  # @return [CircleCi::Response] - Response object
117
-
118
119
  def self.set_envvar(username, project, envvar)
119
- body = envvar
120
- CircleCi.http.post "/project/#{username}/#{project}/envvar", {}, body
120
+ CircleCi.request("/project/#{username}/#{project}/envvar").post(envvar)
121
121
  end
122
122
 
123
123
  ##
@@ -127,9 +127,8 @@ module CircleCi
127
127
  # @param username [String] - User or org name who owns project
128
128
  # @param project [String] - Name of project
129
129
  # @return [CircleCi::Response] - Response object
130
-
131
130
  def self.follow(username, project)
132
- CircleCi.http.post "/project/#{username}/#{project}/follow"
131
+ CircleCi.request("/project/#{username}/#{project}/follow").post
133
132
  end
134
133
 
135
134
  ##
@@ -140,9 +139,8 @@ module CircleCi
140
139
  # @param project [String] - Name of project
141
140
  # @param fingerprint [String] - Fingerprint of a checkout key
142
141
  # @return [CircleCi::Response] - Response object
143
-
144
142
  def self.get_checkout_key(username, project, fingerprint)
145
- CircleCi.http.get "/project/#{username}/#{project}/checkout-key/#{fingerprint}"
143
+ CircleCi.request("/project/#{username}/#{project}/checkout-key/#{fingerprint}").get
146
144
  end
147
145
 
148
146
  ##
@@ -152,9 +150,8 @@ module CircleCi
152
150
  # @param username [String] - User or org name who owns project
153
151
  # @param project [String] - Name of project
154
152
  # @return [CircleCi::Response] - Response object
155
-
156
153
  def self.list_checkout_keys(username, project)
157
- CircleCi.http.get "/project/#{username}/#{project}/checkout-key"
154
+ CircleCi.request("/project/#{username}/#{project}/checkout-key").get
158
155
  end
159
156
 
160
157
  ##
@@ -167,8 +164,7 @@ module CircleCi
167
164
  # @return [CircleCi::Response] - Response object
168
165
 
169
166
  def self.new_checkout_key(username, project, type)
170
- body = { type: type }
171
- CircleCi.http.post "/project/#{username}/#{project}/checkout-key", {}, body
167
+ CircleCi.request("/project/#{username}/#{project}/checkout-key").post(type: type)
172
168
  end
173
169
 
174
170
  ##
@@ -181,7 +177,7 @@ module CircleCi
181
177
  # @return [CircleCi::Response] - Response object
182
178
 
183
179
  def self.recent_builds(username, project, params = {})
184
- CircleCi.http.get "/project/#{username}/#{project}", params
180
+ CircleCi.request("/project/#{username}/#{project}", params).get
185
181
  end
186
182
 
187
183
  ##
@@ -192,9 +188,8 @@ module CircleCi
192
188
  # @param project [String] - Name of project
193
189
  # @param branch [String] - Name of branch
194
190
  # @return [CircleCi::Response] - Response object
195
-
196
191
  def self.recent_builds_branch(username, project, branch)
197
- CircleCi.http.get "/project/#{username}/#{project}/tree/#{branch}"
192
+ CircleCi.request("/project/#{username}/#{project}/tree/#{branch}").get
198
193
  end
199
194
 
200
195
  ##
@@ -204,9 +199,8 @@ module CircleCi
204
199
  # @param username [String] - User or org name who owns project
205
200
  # @param project [String] - Name of project
206
201
  # @return [CircleCi::Response] - Response object
207
-
208
202
  def self.settings(username, project)
209
- CircleCi.http.get "/project/#{username}/#{project}/settings"
203
+ CircleCi.request("/project/#{username}/#{project}/settings").get
210
204
  end
211
205
 
212
206
  ##
@@ -218,10 +212,9 @@ module CircleCi
218
212
  # @param key [String] - The ssh private key
219
213
  # @param hostname [String] - The hostname identified by the key
220
214
  # @return [CircleCi::Response] - Response object
221
-
222
215
  def self.ssh_key(username, project, key, hostname)
223
216
  body = { hostname: hostname, private_key: key }
224
- CircleCi.http.post "/project/#{username}/#{project}/ssh-key", {}, body
217
+ CircleCi.request("/project/#{username}/#{project}/ssh-key").post(body)
225
218
  end
226
219
 
227
220
  ##
@@ -231,9 +224,8 @@ module CircleCi
231
224
  # @param username [String] - User or org name who owns project
232
225
  # @param project [String] - Name of project
233
226
  # @return [CircleCi::Response] - Response object
234
-
235
227
  def self.unfollow(username, project)
236
- CircleCi.http.post "/project/#{username}/#{project}/unfollow"
228
+ CircleCi.request("/project/#{username}/#{project}/unfollow").post
237
229
  end
238
230
  end
239
231
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module CircleCi
2
3
  ##
3
4
  #
@@ -9,9 +10,8 @@ module CircleCi
9
10
  #
10
11
  # @param params [Hash] - Params to send for recent builds (limit, offset)
11
12
  # @return [CircleCi::Response] - Response object
12
-
13
13
  def self.get(params = {})
14
- CircleCi.http.get '/recent-builds', params
14
+ CircleCi.request('/recent-builds', params).get
15
15
  end
16
16
  end
17
17
  end
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+ module CircleCi
3
+ ##
4
+ #
5
+ # Request class to handle HTTP API interactions
6
+ #
7
+ class Request
8
+ DEFAULT_OPTIONS = {
9
+ use_ssl: true,
10
+ verify_ssl: true,
11
+ verify_mode: OpenSSL::SSL::VERIFY_PEER
12
+ }.freeze
13
+
14
+ DEFAULT_HEADERS = {
15
+ 'accept' => 'application/json',
16
+ 'content-type' => 'application/json'
17
+ }.freeze
18
+
19
+ def initialize(config, path, params = {})
20
+ @config = config
21
+ @uri = build_uri(path, params)
22
+ @net = net_http
23
+ setup_http(@net)
24
+ end
25
+
26
+ def get
27
+ execute :get
28
+ end
29
+
30
+ def post(body = {})
31
+ execute :post, body
32
+ end
33
+
34
+ def delete
35
+ execute :delete
36
+ end
37
+
38
+ private
39
+
40
+ def execute(verb, body = {})
41
+ http = connection(verb, body)
42
+ setup_http(http)
43
+ transmit http
44
+ end
45
+
46
+ def connection(verb, body = {})
47
+ req = Net::HTTP.const_get(verb.to_s.capitalize, false).new(@uri, DEFAULT_HEADERS)
48
+ req.body = JSON.dump(body)
49
+ req
50
+ end
51
+
52
+ def setup_http(http)
53
+ options = DEFAULT_OPTIONS.merge(@config.request_overrides)
54
+ options.each do |option, value|
55
+ setter = "#{option.to_sym}="
56
+ http.send(setter, value) if http.respond_to?(setter)
57
+ end
58
+ end
59
+
60
+ def build_uri(path, params = {})
61
+ uri = @config.uri
62
+ uri.path += path
63
+ params['circle-token'] = @config.token
64
+ uri.query = URI.encode_www_form(params)
65
+ uri
66
+ end
67
+
68
+ def net_http
69
+ proxy_uri = @config.proxy_uri
70
+ if @config.proxy && proxy_uri
71
+ Net::HTTP.new(@uri.hostname, @uri.port,
72
+ proxy_uri.host, proxy_uri.port, proxy_uri.user, proxy_uri.password)
73
+ else
74
+ Net::HTTP.new(@uri.hostname, @uri.port, nil, nil, nil, nil)
75
+ end
76
+ end
77
+
78
+ def transmit(req)
79
+ response = nil
80
+ @net.start do |http|
81
+ response = http.request(req, nil, &:read_body)
82
+ end
83
+ Response.new response
84
+ end
85
+ end
86
+ end
@@ -1,39 +1,47 @@
1
+ # frozen_string_literal: true
1
2
  module CircleCi
2
3
  ##
3
4
  #
4
5
  # Response class is used to get access to raw HTTP request info
5
6
  class Response
6
- attr_reader :success, :body, :errors, :code, :path
7
+ extend Forwardable
8
+
9
+ def_delegators :@resp, :code, :message, :uri
10
+
11
+ attr_reader :body
12
+
7
13
  ##
8
14
  # Initializing response object to be returned from API calls, used internally.
9
15
  #
10
16
  # @private
11
-
12
- def initialize(http, resp_code, resp_path) # @private
13
- @success = http.success
14
- @body = http.response
15
- @errors = http.errors
16
- @code = resp_code
17
- @path = resp_path
17
+ def initialize(resp) # @private
18
+ @resp = resp
19
+ @body = parsed_body
18
20
  end
19
21
 
20
22
  ##
21
23
  #
22
24
  # Convenience method to determine if request was successfull or not
23
25
  # @return [Boolean]
24
-
25
26
  def success?
26
- @success == true
27
+ case @resp.code.to_i
28
+ when (200..299) then true
29
+ else
30
+ false
31
+ end
27
32
  end
28
33
 
34
+ private
35
+
29
36
  ##
37
+ # Attempts to parse the response as JSON. Will rescue and return original
38
+ # if unable to parse.
30
39
  #
31
- # *Deprecated* - To remove hashie dependency
32
- # Parses JSON body of request
33
- # @return [@body]
34
-
40
+ # @return [Hash,Array,String] A parsed JSON object or the original response body
35
41
  def parsed_body
36
- @body
42
+ JSON.parse @resp.body
43
+ rescue JSON::ParserError
44
+ @resp.body
37
45
  end
38
46
  end
39
47
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module CircleCi
2
3
  ##
3
4
  #
@@ -8,9 +9,8 @@ module CircleCi
8
9
  # Get user account details
9
10
  #
10
11
  # @return [CircleCi::Response] - Response object
11
-
12
12
  def self.me
13
- CircleCi.http.get '/me'
13
+ CircleCi.request('/me').get
14
14
  end
15
15
 
16
16
  ##
@@ -20,8 +20,7 @@ module CircleCi
20
20
  # @param apikey [String] - The Heroku API key
21
21
  # @return [CircleCi::Response] - Response object
22
22
  def self.heroku_key(apikey)
23
- body = { apikey: apikey }
24
- CircleCi.http.post '/user/heroku-key', {}, body
23
+ CircleCi.request('/user/heroku-key').post(apikey: apikey)
25
24
  end
26
25
  end
27
26
  end
metadata CHANGED
@@ -1,69 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: circleci
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chavez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-12 00:00:00.000000000 Z
11
+ date: 2016-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rest-client
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.8'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.8'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: coveralls
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
17
  - - "~>"
32
18
  - !ruby/object:Gem::Version
33
- version: 0.8.11
19
+ version: 0.8.14
34
20
  - - ">="
35
21
  - !ruby/object:Gem::Version
36
- version: 0.8.11
22
+ version: 0.8.14
37
23
  type: :development
38
24
  prerelease: false
39
25
  version_requirements: !ruby/object:Gem::Requirement
40
26
  requirements:
41
27
  - - "~>"
42
28
  - !ruby/object:Gem::Version
43
- version: 0.8.11
29
+ version: 0.8.14
44
30
  - - ">="
45
31
  - !ruby/object:Gem::Version
46
- version: 0.8.11
32
+ version: 0.8.14
47
33
  - !ruby/object:Gem::Dependency
48
34
  name: dotenv
49
35
  requirement: !ruby/object:Gem::Requirement
50
36
  requirements:
51
37
  - - "~>"
52
38
  - !ruby/object:Gem::Version
53
- version: 2.1.0
39
+ version: 2.1.1
54
40
  - - ">="
55
41
  - !ruby/object:Gem::Version
56
- version: 2.1.0
42
+ version: 2.1.1
57
43
  type: :development
58
44
  prerelease: false
59
45
  version_requirements: !ruby/object:Gem::Requirement
60
46
  requirements:
61
47
  - - "~>"
62
48
  - !ruby/object:Gem::Version
63
- version: 2.1.0
49
+ version: 2.1.1
64
50
  - - ">="
65
51
  - !ruby/object:Gem::Version
66
- version: 2.1.0
52
+ version: 2.1.1
67
53
  - !ruby/object:Gem::Dependency
68
54
  name: gemcutter
69
55
  requirement: !ruby/object:Gem::Requirement
@@ -90,60 +76,60 @@ dependencies:
90
76
  requirements:
91
77
  - - "~>"
92
78
  - !ruby/object:Gem::Version
93
- version: 1.11.2
79
+ version: 1.12.1
94
80
  - - ">="
95
81
  - !ruby/object:Gem::Version
96
- version: 1.11.2
82
+ version: 1.12.1
97
83
  type: :development
98
84
  prerelease: false
99
85
  version_requirements: !ruby/object:Gem::Requirement
100
86
  requirements:
101
87
  - - "~>"
102
88
  - !ruby/object:Gem::Version
103
- version: 1.11.2
89
+ version: 1.12.1
104
90
  - - ">="
105
91
  - !ruby/object:Gem::Version
106
- version: 1.11.2
92
+ version: 1.12.1
107
93
  - !ruby/object:Gem::Dependency
108
94
  name: pry
109
95
  requirement: !ruby/object:Gem::Requirement
110
96
  requirements:
111
97
  - - "~>"
112
98
  - !ruby/object:Gem::Version
113
- version: 0.10.3
99
+ version: 0.10.4
114
100
  - - ">="
115
101
  - !ruby/object:Gem::Version
116
- version: 0.10.3
102
+ version: 0.10.4
117
103
  type: :development
118
104
  prerelease: false
119
105
  version_requirements: !ruby/object:Gem::Requirement
120
106
  requirements:
121
107
  - - "~>"
122
108
  - !ruby/object:Gem::Version
123
- version: 0.10.3
109
+ version: 0.10.4
124
110
  - - ">="
125
111
  - !ruby/object:Gem::Version
126
- version: 0.10.3
112
+ version: 0.10.4
127
113
  - !ruby/object:Gem::Dependency
128
114
  name: rake
129
115
  requirement: !ruby/object:Gem::Requirement
130
116
  requirements:
131
117
  - - "~>"
132
118
  - !ruby/object:Gem::Version
133
- version: 10.5.0
119
+ version: 11.2.2
134
120
  - - ">="
135
121
  - !ruby/object:Gem::Version
136
- version: 10.5.0
122
+ version: 11.2.2
137
123
  type: :development
138
124
  prerelease: false
139
125
  version_requirements: !ruby/object:Gem::Requirement
140
126
  requirements:
141
127
  - - "~>"
142
128
  - !ruby/object:Gem::Version
143
- version: 10.5.0
129
+ version: 11.2.2
144
130
  - - ">="
145
131
  - !ruby/object:Gem::Version
146
- version: 10.5.0
132
+ version: 11.2.2
147
133
  - !ruby/object:Gem::Dependency
148
134
  name: redcarpet
149
135
  requirement: !ruby/object:Gem::Requirement
@@ -170,140 +156,140 @@ dependencies:
170
156
  requirements:
171
157
  - - "~>"
172
158
  - !ruby/object:Gem::Version
173
- version: 2.14.1
159
+ version: 3.5.0
174
160
  - - ">="
175
161
  - !ruby/object:Gem::Version
176
- version: 2.14.1
162
+ version: 3.5.0
177
163
  type: :development
178
164
  prerelease: false
179
165
  version_requirements: !ruby/object:Gem::Requirement
180
166
  requirements:
181
167
  - - "~>"
182
168
  - !ruby/object:Gem::Version
183
- version: 2.14.1
169
+ version: 3.5.0
184
170
  - - ">="
185
171
  - !ruby/object:Gem::Version
186
- version: 2.14.1
172
+ version: 3.5.0
187
173
  - !ruby/object:Gem::Dependency
188
174
  name: rubocop
189
175
  requirement: !ruby/object:Gem::Requirement
190
176
  requirements:
191
177
  - - "~>"
192
178
  - !ruby/object:Gem::Version
193
- version: 0.37.2
179
+ version: 0.42.0
194
180
  - - ">="
195
181
  - !ruby/object:Gem::Version
196
- version: 0.37.2
182
+ version: 0.42.0
197
183
  type: :development
198
184
  prerelease: false
199
185
  version_requirements: !ruby/object:Gem::Requirement
200
186
  requirements:
201
187
  - - "~>"
202
188
  - !ruby/object:Gem::Version
203
- version: 0.37.2
189
+ version: 0.42.0
204
190
  - - ">="
205
191
  - !ruby/object:Gem::Version
206
- version: 0.37.2
192
+ version: 0.42.0
207
193
  - !ruby/object:Gem::Dependency
208
194
  name: simplecov
209
195
  requirement: !ruby/object:Gem::Requirement
210
196
  requirements:
211
197
  - - "~>"
212
198
  - !ruby/object:Gem::Version
213
- version: 0.11.2
199
+ version: 0.12.0
214
200
  - - ">="
215
201
  - !ruby/object:Gem::Version
216
- version: 0.11.2
202
+ version: 0.12.0
217
203
  type: :development
218
204
  prerelease: false
219
205
  version_requirements: !ruby/object:Gem::Requirement
220
206
  requirements:
221
207
  - - "~>"
222
208
  - !ruby/object:Gem::Version
223
- version: 0.11.2
209
+ version: 0.12.0
224
210
  - - ">="
225
211
  - !ruby/object:Gem::Version
226
- version: 0.11.2
212
+ version: 0.12.0
227
213
  - !ruby/object:Gem::Dependency
228
214
  name: typhoeus
229
215
  requirement: !ruby/object:Gem::Requirement
230
216
  requirements:
231
217
  - - "~>"
232
218
  - !ruby/object:Gem::Version
233
- version: 1.0.1
219
+ version: 1.1.0
234
220
  - - ">="
235
221
  - !ruby/object:Gem::Version
236
- version: 1.0.1
222
+ version: 1.1.0
237
223
  type: :development
238
224
  prerelease: false
239
225
  version_requirements: !ruby/object:Gem::Requirement
240
226
  requirements:
241
227
  - - "~>"
242
228
  - !ruby/object:Gem::Version
243
- version: 1.0.1
229
+ version: 1.1.0
244
230
  - - ">="
245
231
  - !ruby/object:Gem::Version
246
- version: 1.0.1
232
+ version: 1.1.0
247
233
  - !ruby/object:Gem::Dependency
248
234
  name: vcr
249
235
  requirement: !ruby/object:Gem::Requirement
250
236
  requirements:
251
237
  - - "~>"
252
238
  - !ruby/object:Gem::Version
253
- version: 3.0.1
239
+ version: 3.0.3
254
240
  - - ">="
255
241
  - !ruby/object:Gem::Version
256
- version: 3.0.1
242
+ version: 3.0.3
257
243
  type: :development
258
244
  prerelease: false
259
245
  version_requirements: !ruby/object:Gem::Requirement
260
246
  requirements:
261
247
  - - "~>"
262
248
  - !ruby/object:Gem::Version
263
- version: 3.0.1
249
+ version: 3.0.3
264
250
  - - ">="
265
251
  - !ruby/object:Gem::Version
266
- version: 3.0.1
252
+ version: 3.0.3
267
253
  - !ruby/object:Gem::Dependency
268
254
  name: webmock
269
255
  requirement: !ruby/object:Gem::Requirement
270
256
  requirements:
271
257
  - - "~>"
272
258
  - !ruby/object:Gem::Version
273
- version: 1.24.0
259
+ version: 2.1.0
274
260
  - - ">="
275
261
  - !ruby/object:Gem::Version
276
- version: 1.24.0
262
+ version: 2.1.0
277
263
  type: :development
278
264
  prerelease: false
279
265
  version_requirements: !ruby/object:Gem::Requirement
280
266
  requirements:
281
267
  - - "~>"
282
268
  - !ruby/object:Gem::Version
283
- version: 1.24.0
269
+ version: 2.1.0
284
270
  - - ">="
285
271
  - !ruby/object:Gem::Version
286
- version: 1.24.0
272
+ version: 2.1.0
287
273
  - !ruby/object:Gem::Dependency
288
274
  name: yard
289
275
  requirement: !ruby/object:Gem::Requirement
290
276
  requirements:
291
277
  - - "~>"
292
278
  - !ruby/object:Gem::Version
293
- version: 0.8.7
279
+ version: 0.9.5
294
280
  - - ">="
295
281
  - !ruby/object:Gem::Version
296
- version: 0.8.7
282
+ version: 0.9.5
297
283
  type: :development
298
284
  prerelease: false
299
285
  version_requirements: !ruby/object:Gem::Requirement
300
286
  requirements:
301
287
  - - "~>"
302
288
  - !ruby/object:Gem::Version
303
- version: 0.8.7
289
+ version: 0.9.5
304
290
  - - ">="
305
291
  - !ruby/object:Gem::Version
306
- version: 0.8.7
292
+ version: 0.9.5
307
293
  description: Ruby gem for Circle CI REST API
308
294
  email: contact@el-chavez.me
309
295
  executables: []
@@ -315,10 +301,9 @@ files:
315
301
  - lib/circleci.rb
316
302
  - lib/circleci/build.rb
317
303
  - lib/circleci/config.rb
318
- - lib/circleci/http.rb
319
304
  - lib/circleci/project.rb
320
305
  - lib/circleci/recent_builds.rb
321
- - lib/circleci/request_error.rb
306
+ - lib/circleci/request.rb
322
307
  - lib/circleci/response.rb
323
308
  - lib/circleci/user.rb
324
309
  homepage: http://github.com/mtchavez/circleci
@@ -335,7 +320,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
335
320
  requirements:
336
321
  - - ">="
337
322
  - !ruby/object:Gem::Version
338
- version: '0'
323
+ version: 2.0.0
339
324
  required_rubygems_version: !ruby/object:Gem::Requirement
340
325
  requirements:
341
326
  - - ">="
@@ -343,7 +328,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
343
328
  version: '0'
344
329
  requirements: []
345
330
  rubyforge_project:
346
- rubygems_version: 2.2.2
331
+ rubygems_version: 2.5.1
347
332
  signing_key:
348
333
  specification_version: 4
349
334
  summary: Circle CI REST API gem
@@ -1,88 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module CircleCi
4
- ##
5
- #
6
- # Http class handles all HTTP requests
7
- class Http # @private
8
- attr_accessor :errors, :response, :success, :config, :over_limit, :suspended
9
-
10
- def initialize(config)
11
- @config = config
12
- @errors = []
13
- @success = false
14
- @over_limit = false
15
- @suspended = false
16
- end
17
-
18
- def get(path, params = {})
19
- request 'get', "#{path}?#{RestClient::Payload.generate(build_params(params))}"
20
- end
21
-
22
- def post(path, params = {}, body = {})
23
- request 'post', "#{path}?#{RestClient::Payload.generate(build_params(params))}", body
24
- end
25
-
26
- def delete(path, params = {})
27
- request 'delete', "#{path}?#{RestClient::Payload.generate(build_params(params))}"
28
- end
29
-
30
- def headers
31
- { 'accept' => 'application/json', 'content-type' => 'application/json' }
32
- end
33
-
34
- def build_params(params = {})
35
- params.merge('circle-token' => @config.token)
36
- end
37
-
38
- def create_request_args(http_verb, url, body)
39
- args = {
40
- method: http_verb.to_sym,
41
- url: url,
42
- headers: headers }
43
- args[:payload] = body if http_verb == 'post'
44
- args.merge!(@config.request_overrides)
45
- args
46
- end
47
-
48
- def request(http_verb, path, body = {})
49
- url = "#{@config.uri}#{path}"
50
- args = create_request_args http_verb, url, body
51
-
52
- RestClient::Request.execute(args) do |res, _, raw_res|
53
- body = res.body.to_s
54
- body.force_encoding(Encoding::UTF_8)
55
- code = raw_res.code.to_i
56
-
57
- self.response = body
58
- self.errors = []
59
-
60
- handle_response(body, code, path)
61
- Response.new(self, code, path)
62
- end
63
- end
64
-
65
- def parsed_body(body)
66
- JSON.parse(body)
67
- rescue
68
- nil
69
- end
70
-
71
- def handle_response(body, code, path)
72
- parsed = parsed_body(body)
73
- successful_code = (200..299).cover?(code)
74
- self.response = parsed if parsed
75
- self.success = true
76
-
77
- # Some responses are empty but are successful
78
- if body == '""' && successful_code
79
- self.response = ''
80
- elsif parsed && successful_code
81
- # Response is successful
82
- else
83
- self.success = false
84
- self.errors = [RequestError.new(body, code, path)]
85
- end
86
- end
87
- end
88
- end
@@ -1,14 +0,0 @@
1
- module CircleCi
2
- ##
3
- #
4
- # RequestError takes http request info to raise more meaningful errors
5
- class RequestError
6
- attr_reader :message, :code, :path
7
-
8
- def initialize(err_message, err_code, err_path) # @private
9
- @message = err_message
10
- @code = err_code
11
- @path = err_path
12
- end
13
- end
14
- end