drip-ruby 2.0.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +14 -1
- data/.rubocop_todo.yml +51 -85
- data/.travis.yml +1 -0
- data/CHANGELOG.md +62 -0
- data/Rakefile +4 -2
- data/drip-ruby.gemspec +6 -6
- data/lib/drip/client.rb +45 -34
- data/lib/drip/client/orders.rb +4 -4
- data/lib/drip/errors.rb +3 -0
- data/lib/drip/response.rb +5 -5
- data/lib/drip/version.rb +1 -1
- data/test/drip/client/accounts_test.rb +6 -15
- data/test/drip/client/broadcasts_test.rb +6 -15
- data/test/drip/client/campaign_subscriptions_test.rb +3 -11
- data/test/drip/client/campaigns_test.rb +15 -27
- data/test/drip/client/conversions_test.rb +6 -15
- data/test/drip/client/custom_fields_test.rb +3 -11
- data/test/drip/client/events_test.rb +12 -23
- data/test/drip/client/forms_test.rb +6 -15
- data/test/drip/client/orders_test.rb +48 -58
- data/test/drip/client/subscribers_test.rb +33 -51
- data/test/drip/client/tags_test.rb +9 -19
- data/test/drip/client/webhooks_test.rb +12 -23
- data/test/drip/client/workflow_triggers_test.rb +9 -19
- data/test/drip/client/workflows_test.rb +18 -31
- data/test/drip/client_test.rb +70 -3
- data/test/test_helper.rb +1 -8
- metadata +26 -27
- data/lib/drip/client/purchases.rb +0 -23
- data/test/drip/client/purchases_test.rb +0 -47
@@ -2,40 +2,32 @@ require File.dirname(__FILE__) + '/../../test_helper.rb'
|
|
2
2
|
|
3
3
|
class Drip::Client::OrdersTest < Drip::TestCase
|
4
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
5
|
@client = Drip::Client.new { |c| c.account_id = "12345" }
|
12
|
-
@client.expects(:connection).at_least_once.returns(@connection)
|
13
6
|
end
|
14
7
|
|
15
8
|
context "#create_or_update_order" do
|
16
9
|
setup do
|
17
10
|
@email = "drippy@drip.com"
|
18
11
|
@options = {
|
19
|
-
"email"
|
20
|
-
"provider"
|
21
|
-
"upstream_id"
|
22
|
-
"amount"
|
23
|
-
"tax"
|
24
|
-
"fees"
|
25
|
-
"discount"
|
26
|
-
"currency_code"
|
27
|
-
"properties"
|
28
|
-
"size"
|
29
|
-
"color"
|
12
|
+
"email" => @email,
|
13
|
+
"provider" => "shopify",
|
14
|
+
"upstream_id" => "abcdef",
|
15
|
+
"amount" => 4900,
|
16
|
+
"tax" => 100,
|
17
|
+
"fees" => 0,
|
18
|
+
"discount" => 0,
|
19
|
+
"currency_code" => "USD",
|
20
|
+
"properties" => {
|
21
|
+
"size" => "medium",
|
22
|
+
"color" => "red"
|
30
23
|
}
|
31
24
|
}
|
32
25
|
@payload = { "orders" => [@options] }.to_json
|
33
26
|
@response_status = 202
|
34
|
-
@response_body = stub
|
27
|
+
@response_body = "stub"
|
35
28
|
|
36
|
-
|
37
|
-
|
38
|
-
end
|
29
|
+
stub_request(:post, "https://api.getdrip.com/v2/12345/orders").
|
30
|
+
to_return(status: @response_status, body: @response_body, headers: {})
|
39
31
|
end
|
40
32
|
|
41
33
|
should "send the correct request" do
|
@@ -48,42 +40,41 @@ class Drip::Client::OrdersTest < Drip::TestCase
|
|
48
40
|
setup do
|
49
41
|
@orders = [
|
50
42
|
{
|
51
|
-
"email"
|
52
|
-
"provider"
|
53
|
-
"upstream_id"
|
54
|
-
"amount"
|
55
|
-
"tax"
|
56
|
-
"fees"
|
57
|
-
"discount"
|
58
|
-
"currency_code"
|
59
|
-
"properties"
|
60
|
-
"size"
|
61
|
-
"color"
|
43
|
+
"email" => "drippy@drip.com",
|
44
|
+
"provider" => "shopify",
|
45
|
+
"upstream_id" => "abcdef",
|
46
|
+
"amount" => 4900,
|
47
|
+
"tax" => 100,
|
48
|
+
"fees" => 0,
|
49
|
+
"discount" => 0,
|
50
|
+
"currency_code" => "USD",
|
51
|
+
"properties" => {
|
52
|
+
"size" => "medium",
|
53
|
+
"color" => "red"
|
62
54
|
}
|
63
55
|
},
|
64
56
|
{
|
65
|
-
"email"
|
66
|
-
"provider"
|
67
|
-
"upstream_id"
|
68
|
-
"amount"
|
69
|
-
"tax"
|
70
|
-
"fees"
|
71
|
-
"discount"
|
72
|
-
"currency_code"
|
73
|
-
"properties"
|
74
|
-
"size"
|
75
|
-
"color"
|
57
|
+
"email" => "dripster@drip.com",
|
58
|
+
"provider" => "shopify",
|
59
|
+
"upstream_id" => "abcdef",
|
60
|
+
"amount" => 1500,
|
61
|
+
"tax" => 10,
|
62
|
+
"fees" => 0,
|
63
|
+
"discount" => 0,
|
64
|
+
"currency_code" => "SGD",
|
65
|
+
"properties" => {
|
66
|
+
"size" => "medium",
|
67
|
+
"color" => "black"
|
76
68
|
}
|
77
69
|
}
|
78
70
|
]
|
79
71
|
|
80
72
|
@payload = { "batches" => [{ "orders" => @orders }] }.to_json
|
81
73
|
@response_status = 202
|
82
|
-
@response_body = stub
|
74
|
+
@response_body = "stub"
|
83
75
|
|
84
|
-
|
85
|
-
|
86
|
-
end
|
76
|
+
stub_request(:post, "https://api.getdrip.com/v2/12345/orders/batches").
|
77
|
+
to_return(status: @response_status, body: @response_body, headers: {})
|
87
78
|
end
|
88
79
|
|
89
80
|
should "send the correct request" do
|
@@ -95,21 +86,20 @@ class Drip::Client::OrdersTest < Drip::TestCase
|
|
95
86
|
context "#create_or_update_refund" do
|
96
87
|
setup do
|
97
88
|
@options = {
|
98
|
-
"provider"
|
99
|
-
"order_upstream_id"
|
100
|
-
"amount"
|
101
|
-
"upstream_id"
|
102
|
-
"note"
|
103
|
-
"processed_at"
|
89
|
+
"provider" => "shopify",
|
90
|
+
"order_upstream_id" => "abcdef",
|
91
|
+
"amount" => 4900,
|
92
|
+
"upstream_id" => "tuvwx",
|
93
|
+
"note" => "Incorrect size",
|
94
|
+
"processed_at" => "2013-06-22T10:41:11Z"
|
104
95
|
}
|
105
96
|
|
106
97
|
@payload = { "refunds" => [@options] }.to_json
|
107
98
|
@response_status = 202
|
108
|
-
@response_body = stub
|
99
|
+
@response_body = "stub"
|
109
100
|
|
110
|
-
|
111
|
-
|
112
|
-
end
|
101
|
+
stub_request(:post, "https://api.getdrip.com/v2/12345/refunds").
|
102
|
+
to_return(status: @response_status, body: @response_body, headers: {})
|
113
103
|
end
|
114
104
|
|
115
105
|
should "send the correct request" do
|
@@ -2,24 +2,16 @@ require File.dirname(__FILE__) + '/../../test_helper.rb'
|
|
2
2
|
|
3
3
|
class Drip::Client::SubscribersTest < Drip::TestCase
|
4
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
5
|
@client = Drip::Client.new { |c| c.account_id = "12345" }
|
12
|
-
@client.expects(:connection).at_least_once.returns(@connection)
|
13
6
|
end
|
14
7
|
|
15
8
|
context "#subscribers" do
|
16
9
|
setup do
|
17
10
|
@response_status = 200
|
18
|
-
@response_body = stub
|
11
|
+
@response_body = "stub"
|
19
12
|
|
20
|
-
|
21
|
-
|
22
|
-
end
|
13
|
+
stub_request(:get, "https://api.getdrip.com/v2/12345/subscribers").
|
14
|
+
to_return(status: @response_status, body: @response_body, headers: {})
|
23
15
|
end
|
24
16
|
|
25
17
|
should "send the right request" do
|
@@ -32,11 +24,10 @@ class Drip::Client::SubscribersTest < Drip::TestCase
|
|
32
24
|
setup do
|
33
25
|
@id = "derrick@getdrip.com"
|
34
26
|
@response_status = 201
|
35
|
-
@response_body = stub
|
27
|
+
@response_body = "stub"
|
36
28
|
|
37
|
-
|
38
|
-
|
39
|
-
end
|
29
|
+
stub_request(:get, "https://api.getdrip.com/v2/12345/subscribers/#{CGI.escape @id}").
|
30
|
+
to_return(status: @response_status, body: @response_body, headers: {})
|
40
31
|
end
|
41
32
|
|
42
33
|
should "send the right request" do
|
@@ -49,11 +40,10 @@ class Drip::Client::SubscribersTest < Drip::TestCase
|
|
49
40
|
setup do
|
50
41
|
@id = "derrick@getdrip.com"
|
51
42
|
@response_status = 204
|
52
|
-
@response_body =
|
43
|
+
@response_body = nil
|
53
44
|
|
54
|
-
|
55
|
-
|
56
|
-
end
|
45
|
+
stub_request(:delete, "https://api.getdrip.com/v2/12345/subscribers/#{CGI.escape @id}").
|
46
|
+
to_return(status: @response_status, body: @response_body, headers: {})
|
57
47
|
end
|
58
48
|
|
59
49
|
should "send the right request" do
|
@@ -69,11 +59,10 @@ class Drip::Client::SubscribersTest < Drip::TestCase
|
|
69
59
|
@payload = { "subscribers" => [@data.merge(email: @email)] }.to_json
|
70
60
|
|
71
61
|
@response_status = 201
|
72
|
-
@response_body = stub
|
62
|
+
@response_body = "stub"
|
73
63
|
|
74
|
-
|
75
|
-
|
76
|
-
end
|
64
|
+
stub_request(:post, "https://api.getdrip.com/v2/12345/subscribers").
|
65
|
+
to_return(status: @response_status, body: @response_body, headers: {})
|
77
66
|
end
|
78
67
|
|
79
68
|
should "send the right request" do
|
@@ -97,11 +86,10 @@ class Drip::Client::SubscribersTest < Drip::TestCase
|
|
97
86
|
|
98
87
|
@payload = { "batches" => [{ "subscribers" => @subscribers }] }.to_json
|
99
88
|
@response_status = 201
|
100
|
-
@response_body = stub
|
89
|
+
@response_body = "stub"
|
101
90
|
|
102
|
-
|
103
|
-
|
104
|
-
end
|
91
|
+
stub_request(:post, "https://api.getdrip.com/v2/12345/subscribers/batches").
|
92
|
+
to_return(status: @response_status, body: @response_body, headers: {})
|
105
93
|
end
|
106
94
|
|
107
95
|
should "send the right request" do
|
@@ -123,11 +111,10 @@ class Drip::Client::SubscribersTest < Drip::TestCase
|
|
123
111
|
|
124
112
|
@payload = { "batches" => [{ "subscribers" => @subscribers }] }.to_json
|
125
113
|
@response_status = 204
|
126
|
-
@response_body =
|
114
|
+
@response_body = nil
|
127
115
|
|
128
|
-
|
129
|
-
|
130
|
-
end
|
116
|
+
stub_request(:post, "https://api.getdrip.com/v2/12345/unsubscribes/batches").
|
117
|
+
to_return(status: @response_status, body: @response_body, headers: {})
|
131
118
|
end
|
132
119
|
|
133
120
|
should "send the right request" do
|
@@ -144,11 +131,10 @@ class Drip::Client::SubscribersTest < Drip::TestCase
|
|
144
131
|
@payload = { "subscribers" => [@data.merge(email: @email)] }.to_json
|
145
132
|
|
146
133
|
@response_status = 201
|
147
|
-
@response_body = stub
|
134
|
+
@response_body = "stub"
|
148
135
|
|
149
|
-
|
150
|
-
|
151
|
-
end
|
136
|
+
stub_request(:post, "https://api.getdrip.com/v2/12345/campaigns/#{@campaign_id}/subscribers").
|
137
|
+
to_return(status: @response_status, body: @response_body, headers: {})
|
152
138
|
end
|
153
139
|
|
154
140
|
should "send the right request" do
|
@@ -163,11 +149,10 @@ class Drip::Client::SubscribersTest < Drip::TestCase
|
|
163
149
|
@id = "derrick@getdrip.com"
|
164
150
|
|
165
151
|
@response_status = 201
|
166
|
-
@response_body = stub
|
152
|
+
@response_body = "stub"
|
167
153
|
|
168
|
-
|
169
|
-
|
170
|
-
end
|
154
|
+
stub_request(:post, "https://api.getdrip.com/v2/12345/subscribers/#{CGI.escape @id}/remove").
|
155
|
+
to_return(status: @response_status, body: @response_body, headers: {})
|
171
156
|
end
|
172
157
|
|
173
158
|
should "send the right request" do
|
@@ -182,11 +167,10 @@ class Drip::Client::SubscribersTest < Drip::TestCase
|
|
182
167
|
@campaign = "12345"
|
183
168
|
|
184
169
|
@response_status = 201
|
185
|
-
@response_body = stub
|
170
|
+
@response_body = "stub"
|
186
171
|
|
187
|
-
|
188
|
-
|
189
|
-
end
|
172
|
+
stub_request(:post, "https://api.getdrip.com/v2/12345/subscribers/#{CGI.escape @id}/remove?campaign_id=#{@campaign}").
|
173
|
+
to_return(status: @response_status, body: @response_body, headers: {})
|
190
174
|
end
|
191
175
|
|
192
176
|
should "send the right request" do
|
@@ -200,11 +184,10 @@ class Drip::Client::SubscribersTest < Drip::TestCase
|
|
200
184
|
setup do
|
201
185
|
@id = "derrick@getdrip.com"
|
202
186
|
@response_status = 200
|
203
|
-
@response_body = stub
|
187
|
+
@response_body = "stub"
|
204
188
|
|
205
|
-
|
206
|
-
|
207
|
-
end
|
189
|
+
stub_request(:post, "https://api.getdrip.com/v2/12345/subscribers/#{CGI.escape @id}/unsubscribe_all").
|
190
|
+
to_return(status: @response_status, body: @response_body, headers: {})
|
208
191
|
end
|
209
192
|
|
210
193
|
should "send the right request" do
|
@@ -220,11 +203,10 @@ class Drip::Client::SubscribersTest < Drip::TestCase
|
|
220
203
|
@payload = { "tags" => [{ "email" => @email, "tag" => @tag }] }.to_json
|
221
204
|
|
222
205
|
@response_status = 201
|
223
|
-
@response_body = stub
|
206
|
+
@response_body = "stub"
|
224
207
|
|
225
|
-
|
226
|
-
|
227
|
-
end
|
208
|
+
stub_request(:post, "https://api.getdrip.com/v2/12345/tags").
|
209
|
+
to_return(status: @response_status, body: @response_body, headers: {})
|
228
210
|
end
|
229
211
|
|
230
212
|
should "send the right request" do
|
@@ -2,24 +2,16 @@ require File.dirname(__FILE__) + '/../../test_helper.rb'
|
|
2
2
|
|
3
3
|
class Drip::Client::TagsTest < Drip::TestCase
|
4
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
5
|
@client = Drip::Client.new { |c| c.account_id = "12345" }
|
12
|
-
@client.expects(:connection).at_least_once.returns(@connection)
|
13
6
|
end
|
14
7
|
|
15
8
|
context "#tags" do
|
16
9
|
setup do
|
17
10
|
@response_status = 200
|
18
|
-
@response_body = stub
|
11
|
+
@response_body = "stub"
|
19
12
|
|
20
|
-
|
21
|
-
|
22
|
-
end
|
13
|
+
stub_request(:get, "https://api.getdrip.com/v2/12345/tags").
|
14
|
+
to_return(status: @response_status, body: @response_body, headers: {})
|
23
15
|
end
|
24
16
|
|
25
17
|
should "send the right request" do
|
@@ -35,11 +27,10 @@ class Drip::Client::TagsTest < Drip::TestCase
|
|
35
27
|
@payload = { "tags" => [{ "email" => @email, "tag" => @tag }] }.to_json
|
36
28
|
|
37
29
|
@response_status = 201
|
38
|
-
@response_body = stub
|
30
|
+
@response_body = "stub"
|
39
31
|
|
40
|
-
|
41
|
-
|
42
|
-
end
|
32
|
+
stub_request(:post, "https://api.getdrip.com/v2/12345/tags").
|
33
|
+
to_return(status: @response_status, body: @response_body, headers: {})
|
43
34
|
end
|
44
35
|
|
45
36
|
should "send the right request" do
|
@@ -54,11 +45,10 @@ class Drip::Client::TagsTest < Drip::TestCase
|
|
54
45
|
@tag = "Customer"
|
55
46
|
|
56
47
|
@response_status = 204
|
57
|
-
@response_body =
|
48
|
+
@response_body = nil
|
58
49
|
|
59
|
-
|
60
|
-
|
61
|
-
end
|
50
|
+
stub_request(:delete, "https://api.getdrip.com/v2/12345/subscribers/#{CGI.escape @email}/tags/#{CGI.escape @tag}").
|
51
|
+
to_return(status: @response_status, body: @response_body, headers: {})
|
62
52
|
end
|
63
53
|
|
64
54
|
should "send the right request" do
|
@@ -2,24 +2,16 @@ require File.dirname(__FILE__) + '/../../test_helper.rb'
|
|
2
2
|
|
3
3
|
class Drip::Client::WebhooksTest < Drip::TestCase
|
4
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
5
|
@client = Drip::Client.new { |c| c.account_id = "12345" }
|
12
|
-
@client.expects(:connection).at_least_once.returns(@connection)
|
13
6
|
end
|
14
7
|
|
15
8
|
context "#webhooks" do
|
16
9
|
setup do
|
17
10
|
@response_status = 200
|
18
|
-
@response_body = stub
|
11
|
+
@response_body = "stub"
|
19
12
|
|
20
|
-
|
21
|
-
|
22
|
-
end
|
13
|
+
stub_request(:get, "https://api.getdrip.com/v2/12345/webhooks").
|
14
|
+
to_return(status: @response_status, body: @response_body, headers: {})
|
23
15
|
end
|
24
16
|
|
25
17
|
should "send the right request" do
|
@@ -31,12 +23,11 @@ class Drip::Client::WebhooksTest < Drip::TestCase
|
|
31
23
|
context "#webhook" do
|
32
24
|
setup do
|
33
25
|
@response_status = 200
|
34
|
-
@response_body = stub
|
26
|
+
@response_body = "stub"
|
35
27
|
@id = 1234
|
36
28
|
|
37
|
-
|
38
|
-
|
39
|
-
end
|
29
|
+
stub_request(:get, "https://api.getdrip.com/v2/12345/webhooks/#{@id}").
|
30
|
+
to_return(status: @response_status, body: @response_body, headers: {})
|
40
31
|
end
|
41
32
|
|
42
33
|
should "send the right request" do
|
@@ -59,11 +50,10 @@ class Drip::Client::WebhooksTest < Drip::TestCase
|
|
59
50
|
|
60
51
|
@payload = { "webhooks" => [@options] }.to_json
|
61
52
|
@response_status = 201
|
62
|
-
@response_body = stub
|
53
|
+
@response_body = "stub"
|
63
54
|
|
64
|
-
|
65
|
-
|
66
|
-
end
|
55
|
+
stub_request(:post, "https://api.getdrip.com/v2/12345/webhooks").
|
56
|
+
to_return(status: @response_status, body: @response_body, headers: {})
|
67
57
|
end
|
68
58
|
|
69
59
|
should "send the right request" do
|
@@ -75,12 +65,11 @@ class Drip::Client::WebhooksTest < Drip::TestCase
|
|
75
65
|
context "#delete_webhook" do
|
76
66
|
setup do
|
77
67
|
@response_status = 200
|
78
|
-
@response_body = stub
|
68
|
+
@response_body = "stub"
|
79
69
|
@id = 1234
|
80
70
|
|
81
|
-
|
82
|
-
|
83
|
-
end
|
71
|
+
stub_request(:delete, "https://api.getdrip.com/v2/12345/webhooks/#{@id}").
|
72
|
+
to_return(status: @response_status, body: @response_body, headers: {})
|
84
73
|
end
|
85
74
|
|
86
75
|
should "send the right request" do
|