Skip to content

Commit 60fc0b5

Browse files
committed
Add support for proxy client/endpoint.
1 parent 690038b commit 60fc0b5

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ language: ruby
22
dist: xenial
33
cache: bundler
44

5+
addons:
6+
apt:
7+
packages:
8+
- squid
9+
510
matrix:
611
include:
712
- rvm: 2.4
@@ -13,6 +18,9 @@ matrix:
1318
env: JRUBY_OPTS="--debug -X+O"
1419
- rvm: truffleruby
1520
- rvm: ruby-head
21+
- rvm: 2.6
22+
env: CLOUDFLARE_PROXY=http://localhost:3128
23+
before_script: sudo service squid start
1624
allow_failures:
1725
- rvm: ruby-head
1826
- rvm: jruby-head

cloudflare.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
2121

2222
spec.required_ruby_version = '>= 2.0.0'
2323

24-
spec.add_dependency 'async-rest', '~> 0.9.0'
24+
spec.add_dependency 'async-rest', '~> 0.10.0'
2525

2626
spec.add_development_dependency 'async-rspec'
2727

lib/cloudflare.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
require_relative 'cloudflare/connection'
2626

2727
module Cloudflare
28-
DEFAULT_URL = 'https://api.cloudflare.com/client/v4'
28+
DEFAULT_ENDPOINT = Async::HTTP::Endpoint.parse('https://api.cloudflare.com/client/v4')
2929

30-
def self.connect(key: nil, email: nil)
31-
representation = Connection.for(DEFAULT_URL)
30+
def self.connect(endpoint = DEFAULT_ENDPOINT, key: nil, email: nil)
31+
representation = Connection.for(endpoint)
3232

3333
if key
3434
representation = representation.authenticated(key, email)

lib/cloudflare/rspec/connection.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
# THE SOFTWARE.
2222

2323
require 'async/rspec'
24+
require 'async/http/proxy'
25+
2426
require_relative '../../cloudflare'
2527

2628
module Cloudflare
@@ -35,10 +37,20 @@ module Connection
3537
let(:email) {ENV['CLOUDFLARE_EMAIL']}
3638
let(:key) {ENV['CLOUDFLARE_KEY']}
3739

38-
let(:connection) {@connection = Cloudflare.connect(key: key, email: email)}
40+
let(:connection) do
41+
if proxy_url = ENV['CLOUDFLARE_PROXY']
42+
proxy_endpoint = Async::HTTP::Endpoint.parse(proxy_url)
43+
@proxy = Async::HTTP::Proxy.new(proxy_endpoint)
44+
@connection = Cloudflare.connect(proxy.endpoint(DEFAULT_ENDPOINT.url), key: key, email: email)
45+
else
46+
@proxy = nil
47+
@connection = Cloudflare.connect(key: key, email: email)
48+
end
49+
end
3950

4051
after do
4152
@connection&.close
53+
@proxy&.close
4254
end
4355
end
4456
end

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy