drip-ruby 3.2.0 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +5 -1
- data/.rubocop_todo.yml +17 -9
- data/.travis.yml +1 -1
- data/CHANGELOG.md +20 -1
- data/Gemfile +10 -0
- data/drip-ruby.gemspec +3 -11
- data/lib/drip/client.rb +44 -66
- data/lib/drip/client/accounts.rb +2 -2
- data/lib/drip/client/broadcasts.rb +2 -2
- data/lib/drip/client/campaign_subscriptions.rb +1 -1
- data/lib/drip/client/campaigns.rb +5 -5
- data/lib/drip/client/configuration.rb +28 -0
- data/lib/drip/client/conversions.rb +2 -2
- data/lib/drip/client/custom_fields.rb +1 -1
- data/lib/drip/client/events.rb +4 -4
- data/lib/drip/client/forms.rb +2 -2
- data/lib/drip/client/http_client.rb +64 -0
- data/lib/drip/client/orders.rb +3 -3
- data/lib/drip/client/shopper_activity.rb +78 -0
- data/lib/drip/client/subscribers.rb +13 -13
- data/lib/drip/client/tags.rb +3 -3
- data/lib/drip/client/webhooks.rb +5 -5
- data/lib/drip/client/workflow_triggers.rb +3 -3
- data/lib/drip/client/workflows.rb +6 -6
- data/lib/drip/request.rb +31 -0
- data/lib/drip/response.rb +13 -13
- data/lib/drip/version.rb +1 -1
- data/test/drip/client/configuration_test.rb +122 -0
- data/test/drip/client/http_client_test.rb +96 -0
- data/test/drip/client/shopper_activity_test.rb +175 -0
- data/test/drip/client_test.rb +32 -97
- data/test/drip/collection_test.rb +14 -0
- data/test/drip/collections/account_test.rb +8 -0
- data/test/drip/collections/broadcasts_test.rb +8 -0
- data/test/drip/collections/campaign_subscriptions_test.rb +8 -0
- data/test/drip/collections/campaigns_test.rb +8 -0
- data/test/drip/collections/errors_test.rb +8 -0
- data/test/drip/collections/orders_test.rb +8 -0
- data/test/drip/collections/purchases_test.rb +8 -0
- data/test/drip/collections/tags_test.rb +8 -0
- data/test/drip/collections/webhooks_test.rb +8 -0
- data/test/drip/collections/workflow_triggers_test.rb +8 -0
- data/test/drip/collections/workflows_test.rb +8 -0
- data/test/drip/request_test.rb +58 -0
- data/test/drip/resource_test.rb +12 -0
- data/test/drip/resources/tag_test.rb +13 -0
- data/test/drip/response_test.rb +33 -0
- data/test/test_helper.rb +3 -0
- metadata +42 -104
data/test/drip/client_test.rb
CHANGED
@@ -19,11 +19,6 @@ class Drip::ClientTest < Drip::TestCase
|
|
19
19
|
assert_equal "aaaa", client.url_prefix
|
20
20
|
end
|
21
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
|
-
|
27
22
|
should "accept access token" do
|
28
23
|
client = Drip::Client.new do |config|
|
29
24
|
config.access_token = "aaaa"
|
@@ -55,36 +50,12 @@ class Drip::ClientTest < Drip::TestCase
|
|
55
50
|
assert_equal 20, client.http_open_timeout
|
56
51
|
assert_equal 25, client.http_timeout
|
57
52
|
end
|
58
|
-
end
|
59
53
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
should "return a JSON API payload" do
|
68
|
-
assert_equal({ @key => [@data] }, @client.generate_resource(@key, @data))
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
context "given a personal api key" do
|
73
|
-
setup do
|
74
|
-
@key = "aaaa"
|
75
|
-
@client = Drip::Client.new do |config|
|
76
|
-
config.api_key = @key
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
should "use Basic authentication" do
|
81
|
-
stub_request(:get, "https://api.getdrip.com/v2/testpath").
|
82
|
-
to_return(status: 200, body: "", headers: {})
|
83
|
-
|
84
|
-
@client.get("testpath")
|
85
|
-
|
86
|
-
header = "Basic #{Base64.encode64(@key + ':')}".strip
|
87
|
-
assert_requested :get, "https://api.getdrip.com/v2/testpath", headers: { 'Authorization' => header }
|
54
|
+
should "accept options after initialization" do
|
55
|
+
# Deprecated
|
56
|
+
client = Drip::Client.new
|
57
|
+
assert_output(nil, /^\[DEPRECATED\] Setting configuration/) { client.account_id = "12345" }
|
58
|
+
assert_equal "12345", client.account_id
|
88
59
|
end
|
89
60
|
end
|
90
61
|
|
@@ -98,6 +69,7 @@ class Drip::ClientTest < Drip::TestCase
|
|
98
69
|
|
99
70
|
should "return objects" do
|
100
71
|
stub_request(:get, "https://api.getdrip.com/v2/12345/subscribers/jdoe%40example.com").
|
72
|
+
with(headers: { "Content-Type" => "application/vnd.api+json" }).
|
101
73
|
to_return(status: 200, body: "{\"links\":{\"subscribers.account\":\"https://api.getdrip.com/v2/accounts/{subscribers.account}\"},\"subscribers\":[{\"id\":\"randomid\",\"href\":\"https://api.getdrip.com/v2/1234/subscribers/randomid\",\"status\":\"active\",\"email\":\"jdoe@example.com\",\"time_zone\":null,\"utc_offset\":0,\"visitor_uuid\":null,\"custom_fields\":{\"first_name\":\"John\"},\"tags\":[\"customer\"],\"created_at\":\"2018-06-04T21:29:49Z\",\"ip_address\":null,\"user_agent\":null,\"lifetime_value\":null,\"original_referrer\":null,\"landing_url\":null,\"prospect\":null,\"base_lead_score\":null,\"eu_consent\":\"unknown\",\"lead_score\":null,\"user_id\":\"123\",\"links\":{\"account\":\"1234\"}}]}")
|
102
74
|
|
103
75
|
response = @client.subscriber('jdoe@example.com')
|
@@ -120,85 +92,48 @@ class Drip::ClientTest < Drip::TestCase
|
|
120
92
|
@client = Drip::Client.new do |config|
|
121
93
|
config.api_key = @key
|
122
94
|
config.url_prefix = @url_prefix
|
95
|
+
config.account_id = "12345"
|
123
96
|
end
|
124
97
|
end
|
125
98
|
|
126
|
-
should "connect to alternate prefix" do
|
127
|
-
stub_request(:get, "https://api.example.com/v9001/
|
99
|
+
should "connect to alternate prefix with prepended v2" do
|
100
|
+
stub_request(:get, "https://api.example.com/v9001/v2/12345/subscribers/blah").
|
128
101
|
to_return(status: 200, body: "", headers: {})
|
129
|
-
@client.
|
102
|
+
@client.subscriber("blah")
|
130
103
|
|
131
|
-
assert_requested :get, "https://api.example.com/v9001/
|
104
|
+
assert_requested :get, "https://api.example.com/v9001/v2/12345/subscribers/blah"
|
132
105
|
end
|
133
106
|
end
|
134
107
|
|
135
|
-
context "
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
should "use Bearer token authentication" do
|
144
|
-
stub_request(:get, "https://api.getdrip.com/v2/testpath").
|
145
|
-
to_return(status: 200, body: "", headers: {})
|
146
|
-
@client.get("testpath")
|
147
|
-
header = "Bearer #{@key}"
|
148
|
-
assert_requested :get, "https://api.getdrip.com/v2/testpath", headers: { 'Authorization' => header }
|
108
|
+
context "#generate_resource" do
|
109
|
+
# Deprecated
|
110
|
+
should "return a resource and note deprecation" do
|
111
|
+
client = Drip::Client.new
|
112
|
+
resource = nil
|
113
|
+
assert_output(nil, /^\[DEPRECATED\] Drip\:\:Client\#generate_resource is deprecated/) { resource = client.generate_resource("hello", {}) }
|
114
|
+
assert_equal({ "hello" => [{}] }, resource)
|
149
115
|
end
|
150
116
|
end
|
151
117
|
|
152
|
-
context "
|
153
|
-
|
154
|
-
|
118
|
+
context "#content_type" do
|
119
|
+
# Deprecated
|
120
|
+
should "return default content type and print warning" do
|
121
|
+
client = Drip::Client.new
|
122
|
+
content_type = nil
|
123
|
+
assert_output(nil, /^\[DEPRECATED\] Drip\:\:Client\#content_type is deprecated/) { content_type = client.content_type }
|
124
|
+
assert_equal "application/vnd.api+json", content_type
|
155
125
|
end
|
126
|
+
end
|
156
127
|
|
157
|
-
|
128
|
+
context "#get et all" do
|
129
|
+
# Deprecated
|
130
|
+
should "delegate with v2 and print deprecation warning" do
|
158
131
|
stub_request(:get, "https://api.getdrip.com/v2/testpath").
|
159
|
-
to_return(status: 301, body: "", headers: { "Location" => "https://api.example.com/mytestpath" })
|
160
|
-
stub_request(:get, "https://api.example.com/mytestpath").
|
161
132
|
to_return(status: 200, body: "{}")
|
162
|
-
response = @client.get("testpath")
|
163
|
-
assert_requested :get, "https://api.getdrip.com/v2/testpath"
|
164
|
-
assert_requested :get, "https://api.example.com/mytestpath"
|
165
|
-
assert_equal({}, response.body)
|
166
|
-
end
|
167
133
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
stub_request(:get, "https://api.example.com/mytestpath").
|
172
|
-
to_return(status: 302, body: "", headers: { "Location" => "https://api.getdrip.com/v2/testpath" })
|
173
|
-
assert_raises(Drip::TooManyRedirectsError) { @client.get("testpath") }
|
174
|
-
assert_requested :get, "https://api.getdrip.com/v2/testpath", times: 5
|
175
|
-
assert_requested :get, "https://api.example.com/mytestpath", times: 5
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
context "given a get request" do
|
180
|
-
setup do
|
181
|
-
@client = Drip::Client.new
|
182
|
-
@response = mock
|
183
|
-
@response.stubs(:code).returns('200')
|
184
|
-
@response.stubs(:body).returns('{}')
|
185
|
-
|
186
|
-
@http = mock
|
187
|
-
@http.expects(:request).returns(@response)
|
188
|
-
|
189
|
-
@request = mock
|
190
|
-
@request.stubs(:[]=)
|
191
|
-
@request.stubs(:basic_auth)
|
192
|
-
end
|
193
|
-
|
194
|
-
should "encode query and not set body" do
|
195
|
-
Net::HTTP::Get.expects(:new).returns(@request)
|
196
|
-
Net::HTTP.expects(:start).yields(@http).returns(@response)
|
197
|
-
|
198
|
-
@request.expects(:body=).never
|
199
|
-
URI.expects(:encode_www_form).once
|
200
|
-
|
201
|
-
response = @client.get("testpath")
|
134
|
+
client = Drip::Client.new
|
135
|
+
response = nil
|
136
|
+
assert_output(nil, /^\[DEPRECATED\] Drip\:\:Client\#get please use the API endpoint specific methods/) { response = client.get("testpath") }
|
202
137
|
assert_equal({}, response.body)
|
203
138
|
end
|
204
139
|
end
|
@@ -42,6 +42,19 @@ class Drip::CollectionTest < Drip::TestCase
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
+
context ".collection_name" do
|
46
|
+
should "return default value" do
|
47
|
+
assert_equal "resources", Drip::Collection.collection_name
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context ".resource_name" do
|
52
|
+
should "return default value" do
|
53
|
+
assert_equal "resource", Drip::Collection.resource_name
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# :nocov:
|
45
58
|
class TestCollection < Drip::Collection
|
46
59
|
def self.collection_name
|
47
60
|
"subscribers"
|
@@ -51,4 +64,5 @@ class Drip::CollectionTest < Drip::TestCase
|
|
51
64
|
"subscriber"
|
52
65
|
end
|
53
66
|
end
|
67
|
+
# :nocov:
|
54
68
|
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../test_helper.rb'
|
2
|
+
require "drip/collections/campaign_subscriptions"
|
3
|
+
|
4
|
+
class Drip::CampaignSubscriptionsTest < Drip::TestCase
|
5
|
+
should "have a resource name" do
|
6
|
+
assert_equal "campaign_subscription", Drip::CampaignSubscriptions.resource_name
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../test_helper.rb'
|
2
|
+
require "drip/collections/workflow_triggers"
|
3
|
+
|
4
|
+
class Drip::WorkflowTriggersTest < Drip::TestCase
|
5
|
+
should "have a resource name" do
|
6
|
+
assert_equal "workflow_trigger", Drip::WorkflowTriggers.resource_name
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper.rb'
|
2
|
+
require "drip/request"
|
3
|
+
|
4
|
+
class Drip::RequestTest < Drip::TestCase
|
5
|
+
context "basic data" do
|
6
|
+
should "pass through data" do
|
7
|
+
request = Drip::Request.new(:get, "https://www.example.com/blah", { hello: "world" }, "application/vnd.visio")
|
8
|
+
assert_equal :get, request.http_verb
|
9
|
+
assert_equal "https://www.example.com/blah", request.url
|
10
|
+
assert_equal({ hello: "world" }, request.options)
|
11
|
+
assert_equal "application/vnd.visio", request.content_type
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context "#verb_klass" do
|
16
|
+
context "when a supported verb" do
|
17
|
+
setup do
|
18
|
+
@subject = Drip::Request.new(:get, "https://www.example.com/blah", { hello: "world" }, "application/vnd.visio")
|
19
|
+
end
|
20
|
+
|
21
|
+
should "return a useful http class" do
|
22
|
+
assert_equal Net::HTTP::Get, @subject.verb_klass
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "when an unsupported verb" do
|
27
|
+
setup do
|
28
|
+
@subject = Drip::Request.new(:garbage, "https://www.example.com/blah", { hello: "world" }, "application/vnd.visio")
|
29
|
+
end
|
30
|
+
|
31
|
+
should "return nil" do
|
32
|
+
assert_nil @subject.verb_klass
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "#body" do
|
38
|
+
context "when HTTP GET" do
|
39
|
+
setup do
|
40
|
+
@subject = Drip::Request.new(:get, "https://www.example.com/blah", { hello: "world" }, "application/vnd.visio")
|
41
|
+
end
|
42
|
+
|
43
|
+
should "return nil" do
|
44
|
+
assert_nil @subject.body
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "when HTTP POST" do
|
49
|
+
setup do
|
50
|
+
@subject = Drip::Request.new(:post, "https://www.example.com/blah", { hello: "world" }, "application/vnd.visio")
|
51
|
+
end
|
52
|
+
|
53
|
+
should "return JSON" do
|
54
|
+
assert_equal '{"hello":"world"}', @subject.body
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/test/drip/resource_test.rb
CHANGED
@@ -19,4 +19,16 @@ class Drip::ResourceTest < Drip::TestCase
|
|
19
19
|
resource = TestResource.new("created_at" => "2015-06-15T10:00:00Z")
|
20
20
|
assert_equal Time.utc(2015, 6, 15, 10, 0, 0), resource.created_at
|
21
21
|
end
|
22
|
+
|
23
|
+
context ".resource_name" do
|
24
|
+
should "return default value" do
|
25
|
+
assert_equal "resource", Drip::Resource.resource_name
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "#singular?" do
|
30
|
+
should "return default value" do
|
31
|
+
assert_equal true, Drip::Resource.new({}).singular?
|
32
|
+
end
|
33
|
+
end
|
22
34
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../test_helper.rb'
|
2
|
+
require "drip/resources/tag"
|
3
|
+
|
4
|
+
class Drip::TagTest < Drip::TestCase
|
5
|
+
should "have a resource name" do
|
6
|
+
assert_equal "tag", Drip::Tag.resource_name
|
7
|
+
end
|
8
|
+
|
9
|
+
should "accept data" do
|
10
|
+
tag = Drip::Tag.new({ attr1: "hello" })
|
11
|
+
assert_equal "hello", tag.attributes[:attr1]
|
12
|
+
end
|
13
|
+
end
|
data/test/drip/response_test.rb
CHANGED
@@ -120,6 +120,23 @@ class Drip::ResponseTest < Drip::TestCase
|
|
120
120
|
assert @subject.subscribers.is_a?(Drip::Subscribers)
|
121
121
|
assert_equal 1, @subject.subscribers.count
|
122
122
|
end
|
123
|
+
|
124
|
+
should "parse resource" do
|
125
|
+
body = { "subscriber" => @members[0] }
|
126
|
+
subject = Drip::Response.new(200, body)
|
127
|
+
assert_equal "john@acme.com", subject.subscriber.email
|
128
|
+
end
|
129
|
+
|
130
|
+
context "with v3 response" do
|
131
|
+
setup do
|
132
|
+
@body = { "request_id" => "9f119d4b-893a-4279-adb2-c920b6c2034b" }
|
133
|
+
@subject = Drip::Response.new(200, @body)
|
134
|
+
end
|
135
|
+
|
136
|
+
should "be accessible via method call" do
|
137
|
+
assert_equal "9f119d4b-893a-4279-adb2-c920b6c2034b", @subject.request_id
|
138
|
+
end
|
139
|
+
end
|
123
140
|
end
|
124
141
|
|
125
142
|
context "rate limit response" do
|
@@ -133,4 +150,20 @@ class Drip::ResponseTest < Drip::TestCase
|
|
133
150
|
assert_equal @body["message"], @subject.message
|
134
151
|
end
|
135
152
|
end
|
153
|
+
|
154
|
+
context "#respond_to?" do
|
155
|
+
setup do
|
156
|
+
@members = [load_json_fixture("resources/subscriber.json")]
|
157
|
+
@body = { "subscribers" => @members }
|
158
|
+
@subject = Drip::Response.new(200, @body)
|
159
|
+
end
|
160
|
+
|
161
|
+
should "respond to fixture members" do
|
162
|
+
assert @subject.respond_to?(:subscribers)
|
163
|
+
end
|
164
|
+
|
165
|
+
should "not respond to randomness" do
|
166
|
+
refute @subject.respond_to?(:blahdeblah)
|
167
|
+
end
|
168
|
+
end
|
136
169
|
end
|