drip-ruby 0.0.12 → 1.0.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 +17 -0
- data/.rubocop_todo.yml +134 -0
- data/README.md +107 -13
- data/Rakefile +1 -1
- data/drip-ruby.gemspec +2 -2
- data/lib/drip/client.rb +23 -7
- data/lib/drip/client/accounts.rb +10 -0
- data/lib/drip/client/broadcasts.rb +29 -0
- data/lib/drip/client/campaign_subscriptions.rb +15 -0
- data/lib/drip/client/campaigns.rb +54 -0
- data/lib/drip/client/conversions.rb +27 -0
- data/lib/drip/client/custom_fields.rb +13 -0
- data/lib/drip/client/events.rb +13 -0
- data/lib/drip/client/forms.rb +23 -0
- data/lib/drip/client/purchases.rb +1 -1
- data/lib/drip/client/subscribers.rb +28 -6
- data/lib/drip/client/webhooks.rb +59 -0
- data/lib/drip/client/workflow_triggers.rb +44 -0
- data/lib/drip/client/workflows.rb +80 -0
- data/lib/drip/collections.rb +17 -5
- data/lib/drip/collections/broadcasts.rb +13 -0
- data/lib/drip/collections/campaign_subscriptions.rb +13 -0
- data/lib/drip/collections/campaigns.rb +13 -0
- data/lib/drip/collections/webhooks.rb +13 -0
- data/lib/drip/collections/workflow_triggers.rb +13 -0
- data/lib/drip/collections/workflows.rb +13 -0
- data/lib/drip/resources.rb +17 -5
- data/lib/drip/resources/broadcast.rb +9 -0
- data/lib/drip/resources/campaign.rb +9 -0
- data/lib/drip/resources/campaign_subscription.rb +9 -0
- data/lib/drip/resources/webhook.rb +9 -0
- data/lib/drip/resources/workflow.rb +9 -0
- data/lib/drip/resources/workflow_trigger.rb +9 -0
- data/lib/drip/response.rb +1 -1
- data/lib/drip/version.rb +1 -1
- data/test/drip/client/accounts_test.rb +17 -0
- data/test/drip/client/broadcasts_test.rb +47 -0
- data/test/drip/client/campaign_subscriptions_test.rb +31 -0
- data/test/drip/client/campaigns_test.rb +68 -0
- data/test/drip/client/conversions_test.rb +47 -0
- data/test/drip/client/custom_fields_test.rb +30 -0
- data/test/drip/client/events_test.rb +21 -5
- data/test/drip/client/forms_test.rb +47 -0
- data/test/drip/client/purchases_test.rb +0 -1
- data/test/drip/client/subscribers_test.rb +52 -9
- data/test/drip/client/webhooks_test.rb +91 -0
- data/test/drip/client/workflow_triggers_test.rb +85 -0
- data/test/drip/client/workflows_test.rb +122 -0
- data/test/drip/collection_test.rb +1 -1
- data/test/drip/collections_test.rb +8 -1
- data/test/drip/resources_test.rb +8 -1
- data/test/drip/response_test.rb +2 -2
- data/test/test_helper.rb +1 -1
- metadata +40 -2
@@ -76,16 +76,16 @@ class Drip::Client::EventsTest < Drip::TestCase
|
|
76
76
|
setup do
|
77
77
|
@events = [
|
78
78
|
{
|
79
|
-
:
|
80
|
-
:
|
79
|
+
email: "derrick@getdrip.com",
|
80
|
+
action: "subscribed"
|
81
81
|
},
|
82
82
|
{
|
83
|
-
:
|
84
|
-
:
|
83
|
+
email: "darin@getdrip.com",
|
84
|
+
action: "unsubscribed"
|
85
85
|
}
|
86
86
|
]
|
87
87
|
|
88
|
-
@payload = { "batches" => [
|
88
|
+
@payload = { "batches" => [{ "events" => @events }] }.to_json
|
89
89
|
@response_status = 201
|
90
90
|
@response_body = stub
|
91
91
|
|
@@ -99,4 +99,20 @@ class Drip::Client::EventsTest < Drip::TestCase
|
|
99
99
|
assert_equal expected, @client.track_events(@events)
|
100
100
|
end
|
101
101
|
end
|
102
|
+
|
103
|
+
context "#event_actions" do
|
104
|
+
setup do
|
105
|
+
@response_status = 200
|
106
|
+
@response_body = stub
|
107
|
+
|
108
|
+
@stubs.get "12345/event_actions" do
|
109
|
+
[@response_status, {}, @response_body]
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
should "send the right request" do
|
114
|
+
expected = Drip::Response.new(@response_status, @response_body)
|
115
|
+
assert_equal expected, @client.event_actions
|
116
|
+
end
|
117
|
+
end
|
102
118
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../test_helper.rb'
|
2
|
+
|
3
|
+
class Drip::Client::FormsTest < Drip::TestCase
|
4
|
+
def setup
|
5
|
+
@stubs = Faraday::Adapter::Test::Stubs.new
|
6
|
+
|
7
|
+
@connection = Faraday.new do |builder|
|
8
|
+
builder.adapter :test, @stubs
|
9
|
+
end
|
10
|
+
|
11
|
+
@client = Drip::Client.new { |c| c.account_id = "12345" }
|
12
|
+
@client.expects(:connection).at_least_once.returns(@connection)
|
13
|
+
end
|
14
|
+
|
15
|
+
context "#forms" do
|
16
|
+
setup do
|
17
|
+
@response_status = 200
|
18
|
+
@response_body = stub
|
19
|
+
|
20
|
+
@stubs.get "12345/forms" do
|
21
|
+
[@response_status, {}, @response_body]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
should "send the right request" do
|
26
|
+
expected = Drip::Response.new(@response_status, @response_body)
|
27
|
+
assert_equal expected, @client.forms
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "#form" do
|
32
|
+
setup do
|
33
|
+
@response_status = 200
|
34
|
+
@response_body = stub
|
35
|
+
@id = 9999999
|
36
|
+
|
37
|
+
@stubs.get "12345/forms/#{@id}" do
|
38
|
+
[@response_status, {}, @response_body]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
should "send the right request" do
|
43
|
+
expected = Drip::Response.new(@response_status, @response_body)
|
44
|
+
assert_equal expected, @client.form(@id)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -66,7 +66,7 @@ class Drip::Client::SubscribersTest < Drip::TestCase
|
|
66
66
|
setup do
|
67
67
|
@email = "derrick@getdrip.com"
|
68
68
|
@data = { "time_zone" => "America/Los_Angeles" }
|
69
|
-
@payload = { "subscribers" => [@data.merge(:
|
69
|
+
@payload = { "subscribers" => [@data.merge(email: @email)] }.to_json
|
70
70
|
|
71
71
|
@response_status = 201
|
72
72
|
@response_body = stub
|
@@ -86,16 +86,16 @@ class Drip::Client::SubscribersTest < Drip::TestCase
|
|
86
86
|
setup do
|
87
87
|
@subscribers = [
|
88
88
|
{
|
89
|
-
:
|
90
|
-
:
|
89
|
+
email: "derrick@getdrip.com",
|
90
|
+
time_zone: "America/Los_Angeles"
|
91
91
|
},
|
92
92
|
{
|
93
|
-
:
|
94
|
-
:
|
93
|
+
email: "darin@getdrip.com",
|
94
|
+
time_zone: "America/Los_Angeles"
|
95
95
|
}
|
96
96
|
]
|
97
97
|
|
98
|
-
@payload = { "batches" => [
|
98
|
+
@payload = { "batches" => [{ "subscribers" => @subscribers }] }.to_json
|
99
99
|
@response_status = 201
|
100
100
|
@response_body = stub
|
101
101
|
|
@@ -110,12 +110,38 @@ class Drip::Client::SubscribersTest < Drip::TestCase
|
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
113
|
+
context "#unsubscribe_subscribers" do
|
114
|
+
setup do
|
115
|
+
@subscribers = [
|
116
|
+
{
|
117
|
+
email: "someone@example.com"
|
118
|
+
},
|
119
|
+
{
|
120
|
+
email: "other@example.com"
|
121
|
+
}
|
122
|
+
]
|
123
|
+
|
124
|
+
@payload = { "batches" => [{ "subscribers" => @subscribers }] }.to_json
|
125
|
+
@response_status = 204
|
126
|
+
@response_body = stub
|
127
|
+
|
128
|
+
@stubs.post "12345/unsubscribes/batches", @payload do
|
129
|
+
[@response_status, {}, @response_body]
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
should "send the right request" do
|
134
|
+
expected = Drip::Response.new(@response_status, @response_body)
|
135
|
+
assert_equal expected, @client.unsubscribe_subscribers(@subscribers)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
113
139
|
context "#subscribe" do
|
114
140
|
setup do
|
115
141
|
@email = "derrick@getdrip.com"
|
116
142
|
@campaign_id = "12345"
|
117
143
|
@data = { "time_zone" => "America/Los_Angeles" }
|
118
|
-
@payload = { "subscribers" => [@data.merge(:
|
144
|
+
@payload = { "subscribers" => [@data.merge(email: @email)] }.to_json
|
119
145
|
|
120
146
|
@response_status = 201
|
121
147
|
@response_body = stub
|
@@ -139,7 +165,7 @@ class Drip::Client::SubscribersTest < Drip::TestCase
|
|
139
165
|
@response_status = 201
|
140
166
|
@response_body = stub
|
141
167
|
|
142
|
-
@stubs.post "12345/subscribers/#{CGI.escape @id}/
|
168
|
+
@stubs.post "12345/subscribers/#{CGI.escape @id}/remove" do
|
143
169
|
[@response_status, {}, @response_body]
|
144
170
|
end
|
145
171
|
end
|
@@ -158,7 +184,7 @@ class Drip::Client::SubscribersTest < Drip::TestCase
|
|
158
184
|
@response_status = 201
|
159
185
|
@response_body = stub
|
160
186
|
|
161
|
-
@stubs.post "12345/subscribers/#{CGI.escape @id}/
|
187
|
+
@stubs.post "12345/subscribers/#{CGI.escape @id}/remove?campaign_id=#{@campaign}" do
|
162
188
|
[@response_status, {}, @response_body]
|
163
189
|
end
|
164
190
|
end
|
@@ -170,6 +196,23 @@ class Drip::Client::SubscribersTest < Drip::TestCase
|
|
170
196
|
end
|
171
197
|
end
|
172
198
|
|
199
|
+
context "#unsubscribe_from_all" do
|
200
|
+
setup do
|
201
|
+
@id = "derrick@getdrip.com"
|
202
|
+
@response_status = 200
|
203
|
+
@response_body = stub
|
204
|
+
|
205
|
+
@stubs.post "12345/subscribers/#{CGI.escape @id}/unsubscribe_all" do
|
206
|
+
[@response_status, {}, @response_body]
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
should "send the right request" do
|
211
|
+
expected = Drip::Response.new(@response_status, @response_body)
|
212
|
+
assert_equal expected, @client.unsubscribe_from_all(@id)
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
173
216
|
context "#apply_tag" do
|
174
217
|
setup do
|
175
218
|
@email = "derrick@getdrip.com"
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../test_helper.rb'
|
2
|
+
|
3
|
+
class Drip::Client::WebhooksTest < Drip::TestCase
|
4
|
+
def setup
|
5
|
+
@stubs = Faraday::Adapter::Test::Stubs.new
|
6
|
+
|
7
|
+
@connection = Faraday.new do |builder|
|
8
|
+
builder.adapter :test, @stubs
|
9
|
+
end
|
10
|
+
|
11
|
+
@client = Drip::Client.new { |c| c.account_id = "12345" }
|
12
|
+
@client.expects(:connection).at_least_once.returns(@connection)
|
13
|
+
end
|
14
|
+
|
15
|
+
context "#webhooks" do
|
16
|
+
setup do
|
17
|
+
@response_status = 200
|
18
|
+
@response_body = stub
|
19
|
+
|
20
|
+
@stubs.get "12345/webhooks" do
|
21
|
+
[@response_status, {}, @response_body]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
should "send the right request" do
|
26
|
+
expected = Drip::Response.new(@response_status, @response_body)
|
27
|
+
assert_equal expected, @client.webhooks
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "#webhook" do
|
32
|
+
setup do
|
33
|
+
@response_status = 200
|
34
|
+
@response_body = stub
|
35
|
+
@id = 1234
|
36
|
+
|
37
|
+
@stubs.get "12345/webhooks/#{@id}" do
|
38
|
+
[@response_status, {}, @response_body]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
should "send the right request" do
|
43
|
+
expected = Drip::Response.new(@response_status, @response_body)
|
44
|
+
assert_equal expected, @client.webhook(@id)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "#create_webhook" do
|
49
|
+
setup do
|
50
|
+
@post_url = "https://www.example.com"
|
51
|
+
@include_received_email = true
|
52
|
+
@events = ["subscriber.deleted", "subscriber.created"]
|
53
|
+
|
54
|
+
@options = {
|
55
|
+
"post_url" => @post_url,
|
56
|
+
"include_received_email" => @include_received_email,
|
57
|
+
"events" => @events
|
58
|
+
}
|
59
|
+
|
60
|
+
@payload = { "webhooks" => [@options] }.to_json
|
61
|
+
@response_status = 201
|
62
|
+
@response_body = stub
|
63
|
+
|
64
|
+
@stubs.post "12345/webhooks", @payload do
|
65
|
+
[@response_status, {}, @response_body]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
should "send the right request" do
|
70
|
+
expected = Drip::Response.new(@response_status, @response_body)
|
71
|
+
assert_equal expected, @client.create_webhook(@post_url, @include_received_email, @events)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context "#delete_webhook" do
|
76
|
+
setup do
|
77
|
+
@response_status = 200
|
78
|
+
@response_body = stub
|
79
|
+
@id = 1234
|
80
|
+
|
81
|
+
@stubs.delete "12345/webhooks/#{@id}" do
|
82
|
+
[@response_status, {}, @response_body]
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
should "send the right request" do
|
87
|
+
expected = Drip::Response.new(@response_status, @response_body)
|
88
|
+
assert_equal expected, @client.delete_webhook(@id)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../test_helper.rb'
|
2
|
+
|
3
|
+
class Drip::Client::WorkflowTriggersTest < Drip::TestCase
|
4
|
+
def setup
|
5
|
+
@stubs = Faraday::Adapter::Test::Stubs.new
|
6
|
+
|
7
|
+
@connection = Faraday.new do |builder|
|
8
|
+
builder.adapter :test, @stubs
|
9
|
+
end
|
10
|
+
|
11
|
+
@client = Drip::Client.new { |c| c.account_id = "12345" }
|
12
|
+
@client.expects(:connection).at_least_once.returns(@connection)
|
13
|
+
end
|
14
|
+
|
15
|
+
context "#workflow_triggers" do
|
16
|
+
setup do
|
17
|
+
@id = 9999999
|
18
|
+
@response_status = 200
|
19
|
+
@response_body = stub
|
20
|
+
|
21
|
+
@stubs.get "12345/workflows/#{@id}/triggers" do
|
22
|
+
[@response_status, {}, @response_body]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
should "send the right request" do
|
27
|
+
expected = Drip::Response.new(@response_status, @response_body)
|
28
|
+
assert_equal expected, @client.workflow_triggers(@id)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "#create_workflow_trigger" do
|
33
|
+
setup do
|
34
|
+
@id = 1234
|
35
|
+
@data = {
|
36
|
+
"provider" => "leadpages",
|
37
|
+
"trigger_type" => "submitted_landing_page",
|
38
|
+
"properties" => {
|
39
|
+
"landing_page" => "My Landing Page"
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
@payload = { "triggers" => [@data] }.to_json
|
44
|
+
|
45
|
+
@response_status = 200
|
46
|
+
@response_body = stub
|
47
|
+
|
48
|
+
@stubs.post "12345/workflows/#{@id}/triggers", @payload do
|
49
|
+
[@response_status, {}, @response_body]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
should "send the right request" do
|
54
|
+
expected = Drip::Response.new(@response_status, @response_body)
|
55
|
+
assert_equal expected, @client.create_workflow_trigger(@id, @data)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context "#update_workflow_trigger" do
|
60
|
+
setup do
|
61
|
+
@id = 1234
|
62
|
+
@data = {
|
63
|
+
"provider" => "other_provider",
|
64
|
+
"trigger_type" => "submitted_landing_page",
|
65
|
+
"properties" => {
|
66
|
+
"landing_page" => "My Landing Page"
|
67
|
+
}
|
68
|
+
}
|
69
|
+
|
70
|
+
@payload = { "triggers" => [@data] }.to_json
|
71
|
+
|
72
|
+
@response_status = 200
|
73
|
+
@response_body = stub
|
74
|
+
|
75
|
+
@stubs.put "12345/workflows/#{@id}/triggers", @payload do
|
76
|
+
[@response_status, {}, @response_body]
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
should "send the right request" do
|
81
|
+
expected = Drip::Response.new(@response_status, @response_body)
|
82
|
+
assert_equal expected, @client.update_workflow_trigger(@id, @data)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../test_helper.rb'
|
2
|
+
|
3
|
+
class Drip::Client::WorkflowsTest < Drip::TestCase
|
4
|
+
def setup
|
5
|
+
@stubs = Faraday::Adapter::Test::Stubs.new
|
6
|
+
|
7
|
+
@connection = Faraday.new do |builder|
|
8
|
+
builder.adapter :test, @stubs
|
9
|
+
end
|
10
|
+
|
11
|
+
@client = Drip::Client.new { |c| c.account_id = "12345" }
|
12
|
+
@client.expects(:connection).at_least_once.returns(@connection)
|
13
|
+
end
|
14
|
+
|
15
|
+
context "#workflows" do
|
16
|
+
setup do
|
17
|
+
@response_status = 200
|
18
|
+
@response_body = stub
|
19
|
+
|
20
|
+
@stubs.get "12345/workflows" do
|
21
|
+
[@response_status, {}, @response_body]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
should "send the right request" do
|
26
|
+
expected = Drip::Response.new(@response_status, @response_body)
|
27
|
+
assert_equal expected, @client.workflows
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "#workflow" do
|
32
|
+
setup do
|
33
|
+
@response_status = 200
|
34
|
+
@response_body = stub
|
35
|
+
@id = 1234
|
36
|
+
|
37
|
+
@stubs.get "12345/workflows/#{@id}" do
|
38
|
+
[@response_status, {}, @response_body]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
should "send the right request" do
|
43
|
+
expected = Drip::Response.new(@response_status, @response_body)
|
44
|
+
assert_equal expected, @client.workflow(@id)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "#activate_workflow" do
|
49
|
+
setup do
|
50
|
+
@response_status = 204
|
51
|
+
@response_body = stub
|
52
|
+
@id = 1234
|
53
|
+
|
54
|
+
@stubs.post "12345/workflows/#{@id}/activate" do
|
55
|
+
[@response_status, {}, @response_body]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
should "send the right request" do
|
60
|
+
expected = Drip::Response.new(@response_status, @response_body)
|
61
|
+
assert_equal expected, @client.activate_workflow(@id)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context "#pause_workflow" do
|
66
|
+
setup do
|
67
|
+
@response_status = 204
|
68
|
+
@response_body = stub
|
69
|
+
@id = 1234
|
70
|
+
|
71
|
+
@stubs.post "12345/workflows/#{@id}/pause" do
|
72
|
+
[@response_status, {}, @response_body]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
should "send the right request" do
|
77
|
+
expected = Drip::Response.new(@response_status, @response_body)
|
78
|
+
assert_equal expected, @client.pause_workflow(@id)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context "#start_subscriber_workflow" do
|
83
|
+
setup do
|
84
|
+
@data = {
|
85
|
+
"email" => "someone@example.com",
|
86
|
+
"time_zone" => "America/Los_Angeles"
|
87
|
+
}
|
88
|
+
@id = 9999999
|
89
|
+
@payload = { "subscribers" => [@data] }.to_json
|
90
|
+
|
91
|
+
@response_status = 204
|
92
|
+
@response_body = stub
|
93
|
+
|
94
|
+
@stubs.post "12345/workflows/#{@id}/subscribers", @payload do
|
95
|
+
[@response_status, {}, @response_body]
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
should "send the right request" do
|
100
|
+
expected = Drip::Response.new(@response_status, @response_body)
|
101
|
+
assert_equal expected, @client.start_subscriber_workflow(@id, @data)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context "#remove_subscriber_workflow" do
|
106
|
+
setup do
|
107
|
+
@response_status = 200
|
108
|
+
@response_body = stub
|
109
|
+
@id = 1234
|
110
|
+
@email = "someone@example.com"
|
111
|
+
|
112
|
+
@stubs.delete "12345/workflows/#{@id}/subscribers/#{CGI.escape @email}" do
|
113
|
+
[@response_status, {}, @response_body]
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
should "send the right request" do
|
118
|
+
expected = Drip::Response.new(@response_status, @response_body)
|
119
|
+
assert_equal expected, @client.remove_subscriber_workflow(@id, @email)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|