Skip to content

Commit f4a0c0c

Browse files
authored
Merge pull request #38 from DripEmail/allow_alternative_url_prefix
Allow alternative url prefix
2 parents 77f5ff9 + 5d0812d commit f4a0c0c

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

lib/drip/client.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@ class Client
3636
include Workflows
3737
include WorkflowTriggers
3838

39-
attr_accessor :access_token, :api_key, :account_id
39+
attr_accessor :access_token, :api_key, :account_id, :url_prefix
4040

4141
def initialize(options = {})
4242
@account_id = options[:account_id]
4343
@access_token = options[:access_token]
4444
@api_key = options[:api_key]
45+
@url_prefix = options[:url_prefix] || "https://api.getdrip.com/v2/"
4546
yield(self) if block_given?
4647
end
4748

@@ -90,7 +91,7 @@ def build_response(&block)
9091

9192
def connection
9293
@connection ||= Faraday.new do |f|
93-
f.url_prefix = "https://api.getdrip.com/v2/"
94+
f.url_prefix = url_prefix
9495
f.headers['User-Agent'] = "Drip Ruby v#{Drip::VERSION}"
9596
f.headers['Content-Type'] = content_type
9697
f.headers['Accept'] = "*/*"

test/drip/client_test.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@ class Drip::ClientTest < Drip::TestCase
1111
assert_equal "aaaa", client.api_key
1212
end
1313

14+
should "accept url prefix" do
15+
client = Drip::Client.new do |config|
16+
config.url_prefix = "aaaa"
17+
end
18+
19+
assert_equal "aaaa", client.url_prefix
20+
end
21+
22+
should "have default url prefix" do
23+
client = Drip::Client.new
24+
assert_equal "https://api.getdrip.com/v2/", client.url_prefix
25+
end
26+
1427
should "accept access token" do
1528
client = Drip::Client.new do |config|
1629
config.access_token = "aaaa"
@@ -66,6 +79,21 @@ class Drip::ClientTest < Drip::TestCase
6679
end
6780
end
6881

82+
context "given a different url prefix" do
83+
setup do
84+
@key = "aaaa"
85+
@url_prefix = "https://api.example.com/v9001/"
86+
@client = Drip::Client.new do |config|
87+
config.api_key = @key
88+
config.url_prefix = @url_prefix
89+
end
90+
end
91+
92+
should "connect to alternate prefix" do
93+
assert_equal @url_prefix, @client.connection.url_prefix.to_s
94+
end
95+
end
96+
6997
context "given a OAuth access token" do
7098
setup do
7199
@key = "aaaa"

0 commit comments

Comments
 (0)