Skip to content

Commit

Permalink
Merge pull request #65 from mtchavez/47-ssl-verify
Browse files Browse the repository at this point in the history
Request overriding
  • Loading branch information
mtchavez committed Mar 13, 2016
2 parents 1034d9d + ffe93e3 commit 03ef892
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* CircleCi::RecentBuilds#get - Replaces old CircleCi#organization endpoint to return all recent builds
* Remove CircleCi#organization for CircleCi::RecentBuilds#get
* CircleCi::Project#recent_builds - Takes params to supply limit, offset, and filter query params
* RestClient::Request overrides or configuration per request is configurable via Config.request_overrides hash

# Version 0.2.2 - (2016-02-26)

Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ CircleCi.configure do |config|
end
```

Overriding request settings such as not verifying SSL

```ruby
CircleCi.configure do |config|
config.token = ENV['CIRCLECI_TOKEN']
config.request_overrides = {
verify_ssl: false
}
end
```

## API Endpoints

* [User](#user)
Expand Down
3 changes: 2 additions & 1 deletion lib/circleci/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Config
DEFAULT_URI = "#{DEFAULT_HOST}/api/#{DEFAULT_VERSION}".freeze
DEFAULT_PORT = 80

attr_accessor :token, :host, :port, :version
attr_accessor :token, :host, :port, :request_overrides, :version

##
#
Expand All @@ -19,6 +19,7 @@ def initialize
@host = DEFAULT_HOST
@port = DEFAULT_PORT
@version = DEFAULT_VERSION
@request_overrides = {}
end

def uri
Expand Down
11 changes: 8 additions & 3 deletions lib/circleci/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,20 @@ def build_params(params = {})
end

def create_request_args(http_verb, url, body)
return [http_verb, url, body, headers] if http_verb == 'post'
[http_verb, url, headers]
args = {
method: http_verb.to_sym,
url: url,
headers: headers }
args[:payload] = body if http_verb == 'post'
args.merge!(@config.request_overrides)
args
end

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

RestClient.send(*args) do |res, _, raw_res|
RestClient::Request.execute(args) do |res, _, raw_res|
body = res.body.to_s
body.force_encoding(Encoding::UTF_8)
code = raw_res.code.to_i
Expand Down
3 changes: 3 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
config.before do
CircleCi.configure do |c|
c.token = ENV['TOKEN']
c.request_overrides = {
verify_ssl: false
}
end
end
end
Expand Down

0 comments on commit 03ef892

Please sign in to comment.