Skip to content

Commit 03ef892

Browse files
committed
Merge pull request #65 from mtchavez/47-ssl-verify
Request overriding
2 parents 1034d9d + ffe93e3 commit 03ef892

File tree

5 files changed

+25
-4
lines changed

5 files changed

+25
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* CircleCi::RecentBuilds#get - Replaces old CircleCi#organization endpoint to return all recent builds
44
* Remove CircleCi#organization for CircleCi::RecentBuilds#get
55
* CircleCi::Project#recent_builds - Takes params to supply limit, offset, and filter query params
6+
* RestClient::Request overrides or configuration per request is configurable via Config.request_overrides hash
67

78
# Version 0.2.2 - (2016-02-26)
89

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ CircleCi.configure do |config|
4444
end
4545
```
4646

47+
Overriding request settings such as not verifying SSL
48+
49+
```ruby
50+
CircleCi.configure do |config|
51+
config.token = ENV['CIRCLECI_TOKEN']
52+
config.request_overrides = {
53+
verify_ssl: false
54+
}
55+
end
56+
```
57+
4758
## API Endpoints
4859

4960
* [User](#user)

lib/circleci/config.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Config
99
DEFAULT_URI = "#{DEFAULT_HOST}/api/#{DEFAULT_VERSION}".freeze
1010
DEFAULT_PORT = 80
1111

12-
attr_accessor :token, :host, :port, :version
12+
attr_accessor :token, :host, :port, :request_overrides, :version
1313

1414
##
1515
#
@@ -19,6 +19,7 @@ def initialize
1919
@host = DEFAULT_HOST
2020
@port = DEFAULT_PORT
2121
@version = DEFAULT_VERSION
22+
@request_overrides = {}
2223
end
2324

2425
def uri

lib/circleci/http.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,20 @@ def build_params(params = {})
3636
end
3737

3838
def create_request_args(http_verb, url, body)
39-
return [http_verb, url, body, headers] if http_verb == 'post'
40-
[http_verb, url, headers]
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
4146
end
4247

4348
def request(http_verb, path, body = {})
4449
url = "#{@config.uri}#{path}"
4550
args = create_request_args http_verb, url, body
4651

47-
RestClient.send(*args) do |res, _, raw_res|
52+
RestClient::Request.execute(args) do |res, _, raw_res|
4853
body = res.body.to_s
4954
body.force_encoding(Encoding::UTF_8)
5055
code = raw_res.code.to_i

spec/spec_helper.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
config.before do
2828
CircleCi.configure do |c|
2929
c.token = ENV['TOKEN']
30+
c.request_overrides = {
31+
verify_ssl: false
32+
}
3033
end
3134
end
3235
end

0 commit comments

Comments
 (0)