Skip to content

Commit

Permalink
Replace RestClient with Net::HTTP (#75)
Browse files Browse the repository at this point in the history
* Remove RestClient dependency
* Remove HTTP internal class
* Add a Request class
* Update API calls for Request class
* Re-record all cassettes
  • Loading branch information
mtchavez committed Jul 29, 2016
1 parent b601b39 commit 81da24f
Show file tree
Hide file tree
Showing 92 changed files with 3,829 additions and 4,032 deletions.
16 changes: 1 addition & 15 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ PATH
remote: .
specs:
circleci (0.2.3)
rest-client (~> 1.8)

GEM
remote: https://rubygems.org/
Expand All @@ -21,21 +20,15 @@ GEM
safe_yaml (~> 1.0.0)
diff-lcs (1.2.5)
docile (1.1.5)
domain_name (0.5.20160615)
unf (>= 0.0.5, < 1.0.0)
dotenv (2.1.1)
ethon (0.9.0)
ffi (>= 1.3.0)
ffi (1.9.14)
gemcutter (0.7.1)
hashdiff (0.3.0)
http-cookie (1.0.2)
domain_name (~> 0.5)
json (2.0.1)
method_source (0.8.2)
mime-types (2.99.2)
multi_json (1.12.1)
netrc (0.11.0)
parser (2.3.1.2)
ast (~> 2.2)
powerpack (0.1.1)
Expand All @@ -46,10 +39,6 @@ GEM
rainbow (2.1.0)
rake (11.2.2)
redcarpet (3.3.4)
rest-client (1.8.0)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 3.0)
netrc (~> 0.7)
rspec (3.5.0)
rspec-core (~> 3.5.0)
rspec-expectations (~> 3.5.0)
Expand Down Expand Up @@ -86,9 +75,6 @@ GEM
tins (1.6.0)
typhoeus (1.1.0)
ethon (>= 0.9.0)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.2)
unicode-display_width (1.1.0)
vcr (3.0.3)
webmock (2.1.0)
Expand Down Expand Up @@ -119,4 +105,4 @@ DEPENDENCIES
yard (~> 0.9.5, >= 0.9.5)

BUNDLED WITH
1.11.2
1.12.5
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ Overriding request settings such as not verifying SSL
```ruby
CircleCi.configure do |config|
config.token = ENV['CIRCLECI_TOKEN']
config.host = 'http://ci.mycompany.com'
config.port = 80
config.request_overrides = {
use_ssl: false,
verify_ssl: false
}
end
Expand Down
3 changes: 0 additions & 3 deletions circleci.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ Gem::Specification.new do |s|
s.required_ruby_version = '>= 2.0.0'
s.metadata['yard.run'] = 'yri' # use "yard" to build full HTML docs.

# Gem Dependencies
s.add_dependency 'rest-client', '~> 1.8'

# Dev Dependencies
s.add_development_dependency 'coveralls', '~> 0.8.14', '>= 0.8.14'
s.add_development_dependency 'dotenv', '~> 2.1.1', '>= 2.1.1'
Expand Down
11 changes: 4 additions & 7 deletions lib/circleci.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
# frozen_string_literal: true
require 'json'
require 'rest-client'
require 'net/http'
require 'uri'

files = %w[
build
config
http
project
recent_builds
request_error
request
response
user
]
Expand All @@ -28,20 +27,18 @@ module CircleCi
# CircleCi.configure do |config|
# config.token = 'my-token'
# end

def configure
yield config
end

##
#
# @return [CircleCi::Config]

def config
@config ||= Config.new
end

def http # @private
Http.new(config)
def request(path, params = {})
Request.new config, path, params
end
end
14 changes: 5 additions & 9 deletions lib/circleci/build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ class Build
# @param project [String] - Name of project
# @param build [String] - Build ID
# @return [CircleCi::Response] - Response object

def self.artifacts(username, project, build)
CircleCi.http.get "/project/#{username}/#{project}/#{build}/artifacts"
CircleCi.request("/project/#{username}/#{project}/#{build}/artifacts").get
end

##
Expand All @@ -25,9 +24,8 @@ def self.artifacts(username, project, build)
# @param project [String] - Name of project
# @param build [String] - Build ID
# @return [CircleCi::Response] - Response object

def self.cancel(username, project, build)
CircleCi.http.post "/project/#{username}/#{project}/#{build}/cancel"
CircleCi.request("/project/#{username}/#{project}/#{build}/cancel").post
end

##
Expand All @@ -38,9 +36,8 @@ def self.cancel(username, project, build)
# @param project [String] - Name of project
# @param build [String] - Build ID
# @return [CircleCi::Response] - Response object

def self.get(username, project, build)
CircleCi.http.get "/project/#{username}/#{project}/#{build}"
CircleCi.request("/project/#{username}/#{project}/#{build}").get
end

##
Expand All @@ -51,9 +48,8 @@ def self.get(username, project, build)
# @param project [String] - Name of project
# @param build [String] - Build ID
# @return [CircleCi::Response] - Response object

def self.retry(username, project, build)
CircleCi.http.post "/project/#{username}/#{project}/#{build}/retry"
CircleCi.request("/project/#{username}/#{project}/#{build}/retry").post
end

##
Expand All @@ -66,7 +62,7 @@ def self.retry(username, project, build)
# @return [CircleCi::Response] - Response object

def self.tests(username, project, build)
CircleCi.http.get "/project/#{username}/#{project}/#{build}/tests"
CircleCi.request("/project/#{username}/#{project}/#{build}/tests").get
end
end
end
19 changes: 3 additions & 16 deletions lib/circleci/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@ module CircleCi
##
#
# Config class used internally.
# Configure API calls using AlPapi.configure
# Configure API calls using CircleCi.configure
class Config
DEFAULT_VERSION = 'v1'.freeze
DEFAULT_HOST = 'https://circleci.com'.freeze
DEFAULT_URI = "#{DEFAULT_HOST}/api/#{DEFAULT_VERSION}".freeze
DEFAULT_PORT = 80
DEFAULT_PORT = 443

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

##
#
# @private

def initialize
@host = DEFAULT_HOST
@port = DEFAULT_PORT
Expand All @@ -24,19 +23,7 @@ def initialize
end

def uri
base = @host
base += ":#{@port}" unless port_80? || host_has_port?
base + "/api/#{@version}"
end

private

def port_80?
@port == DEFAULT_PORT
end

def host_has_port?
@host =~ /:\d{1,7}$/
URI.parse("#{@host || DEFAULT_HOST}:#{@port || DEFAULT_PORT}/api/#{@version || DEFAULT_VERSION}")
end
end
end
85 changes: 0 additions & 85 deletions lib/circleci/http.rb

This file was deleted.

Loading

0 comments on commit 81da24f

Please sign in to comment.