Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
203 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Ruby CircleCI 2.0 configuration file | ||
# | ||
# Check https://circleci.com/docs/2.0/language-ruby/ for more details | ||
# | ||
version: 2 | ||
jobs: | ||
build: | ||
docker: | ||
# specify the version you desire here | ||
- image: circleci/ruby:2.4.1-node-browsers | ||
environment: | ||
BUNDLER_VERSION: 2.0.1 | ||
|
||
# Specify service dependencies here if necessary | ||
# CircleCI maintains a library of pre-built images | ||
# documented at https://circleci.com/docs/2.0/circleci-images/ | ||
# - image: circleci/postgres:9.4 | ||
|
||
working_directory: ~/repo | ||
|
||
steps: | ||
- checkout | ||
|
||
# Download and cache dependencies | ||
- restore_cache: | ||
keys: | ||
- v1-dependencies-{{ checksum "Gemfile.lock" }} | ||
# fallback to using the latest cache if no exact match is found | ||
- v1-dependencies- | ||
|
||
- run: | ||
name: install bundler 2.0 | ||
command: | | ||
gem install bundler | ||
- run: | ||
name: install dependencies | ||
command: | | ||
bundle install --jobs=4 --retry=3 --path vendor/bundle | ||
- save_cache: | ||
paths: | ||
- ./vendor/bundle | ||
key: v1-dependencies-{{ checksum "Gemfile.lock" }} | ||
|
||
# run tests! | ||
- run: | ||
name: run tests | ||
command: | | ||
mkdir /tmp/test-results | ||
TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | \ | ||
circleci tests split --split-by=timings)" | ||
bundle exec rspec \ | ||
--format progress \ | ||
--format RspecJunitFormatter \ | ||
--out /tmp/test-results/rspec.xml \ | ||
--format progress \ | ||
$TEST_FILES | ||
# collect reports | ||
- store_test_results: | ||
path: /tmp/test-results | ||
- store_artifacts: | ||
path: /tmp/test-results | ||
destination: test-results |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ tmp | |
.rvmrc | ||
.ruby-version | ||
.yardoc | ||
.rspec_status | ||
|
||
## BUNDLER | ||
*.gem | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--require spec_helper | ||
--format documentation | ||
--color |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# frozen_string_literal: true | ||
|
||
module Faraday | ||
class Adapter | ||
# HTTP.rb adapter. | ||
class HTTP < Faraday::Adapter | ||
# Takes the environment and performs the request. | ||
# | ||
# @param env [Faraday::Env] the request environment. | ||
# | ||
# @return [Faraday::Response] the response. | ||
def call(env) | ||
super | ||
perform_request(env) | ||
@app.call(env) | ||
end | ||
|
||
private | ||
|
||
def perform_request(env) | ||
conn = setup_connection(env) | ||
|
||
resp = conn.request env[:method], env[:url], body: env[:body] | ||
save_response(env, resp.code, resp.body.to_s, resp.headers, resp.status.reason) | ||
rescue ::HTTP::TimeoutError | ||
raise Faraday::TimeoutError, $ERROR_INFO | ||
rescue ::HTTP::ConnectionError | ||
raise Faraday::ConnectionFailed, $ERROR_INFO | ||
end | ||
|
||
def setup_connection(env) | ||
conn = ::HTTP | ||
|
||
request_config(conn, env[:request]) if env[:request] | ||
conn.headers(env.request_headers) | ||
end | ||
|
||
def request_config(conn, config) | ||
if (timeout = config[:timeout]) | ||
conn = conn.timeout(connect: timeout, read: timeout, write: timeout) | ||
end | ||
|
||
if (timeout = config[:open_timeout]) | ||
conn = conn.timeout(connect: timeout, write: timeout) | ||
end | ||
|
||
if (proxy = config[:proxy]) | ||
conn = conn.via(proxy.uri.host, proxy.uri.port, proxy.user, proxy.password) | ||
end | ||
|
||
conn | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'faraday' | ||
require 'faraday/http/version' | ||
require 'faraday/adapter/http' | ||
|
||
# Extend the main Faraday module. | ||
module Faraday | ||
module Http | ||
class Error < StandardError; end | ||
# Your code goes here... | ||
end | ||
|
||
Faraday::Adapter.register_middleware http: Faraday::Adapter::HTTP | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe Faraday::Adapter::HTTP do | ||
features :request_body_on_query_methods, :reason_phrase_parse, :trace_method, :connect_method, | ||
:skip_response_body_on_head, :local_socket_binding | ||
|
||
it_behaves_like 'an adapter' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters