drip-ruby 3.4.2 → 3.5.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/.github/workflows/ci.yml +35 -0
- data/.rubocop.yml +27 -6
- data/.rubocop_todo.yml +1 -97
- data/CHANGELOG.md +41 -1
- data/Gemfile +9 -8
- data/README.md +1 -2
- data/drip-ruby.gemspec +4 -4
- data/flake.lock +61 -0
- data/flake.nix +32 -0
- data/lib/drip/client/accounts.rb +3 -1
- data/lib/drip/client/broadcasts.rb +3 -1
- data/lib/drip/client/campaign_subscriptions.rb +3 -1
- data/lib/drip/client/campaigns.rb +6 -4
- data/lib/drip/client/configuration.rb +9 -1
- data/lib/drip/client/conversions.rb +3 -1
- data/lib/drip/client/forms.rb +3 -1
- data/lib/drip/client/http_client.rb +30 -11
- data/lib/drip/client/orders.rb +1 -1
- data/lib/drip/client/shopper_activity.rb +26 -2
- data/lib/drip/client/subscribers.rb +5 -4
- data/lib/drip/client/webhooks.rb +4 -2
- data/lib/drip/client/workflow_triggers.rb +5 -3
- data/lib/drip/client/workflows.rb +5 -5
- data/lib/drip/client.rb +3 -3
- data/lib/drip/collection.rb +2 -2
- data/lib/drip/resource.rb +6 -6
- data/lib/drip/resources/tag.rb +0 -5
- data/lib/drip/response.rb +21 -18
- data/lib/drip/version.rb +1 -1
- data/test/drip/client/accounts_test.rb +18 -2
- data/test/drip/client/broadcasts_test.rb +2 -2
- data/test/drip/client/campaign_subscriptions_test.rb +1 -1
- data/test/drip/client/campaigns_test.rb +5 -5
- data/test/drip/client/configuration_test.rb +14 -1
- data/test/drip/client/conversions_test.rb +2 -2
- data/test/drip/client/custom_fields_test.rb +1 -1
- data/test/drip/client/events_test.rb +1 -1
- data/test/drip/client/forms_test.rb +2 -2
- data/test/drip/client/http_client_test.rb +32 -2
- data/test/drip/client/orders_test.rb +1 -1
- data/test/drip/client/shopper_activity_test.rb +35 -1
- data/test/drip/client/subscribers_test.rb +39 -2
- data/test/drip/client/tags_test.rb +1 -1
- data/test/drip/client/users_test.rb +1 -1
- data/test/drip/client/webhooks_test.rb +1 -1
- data/test/drip/client/workflow_triggers_test.rb +2 -2
- data/test/drip/client/workflows_test.rb +18 -2
- data/test/drip/client_test.rb +8 -6
- data/test/drip/collection_test.rb +1 -1
- data/test/drip/collections/account_test.rb +1 -1
- data/test/drip/collections/broadcasts_test.rb +1 -1
- data/test/drip/collections/campaign_subscriptions_test.rb +1 -1
- data/test/drip/collections/campaigns_test.rb +1 -1
- data/test/drip/collections/errors_test.rb +1 -1
- data/test/drip/collections/orders_test.rb +1 -1
- data/test/drip/collections/purchases_test.rb +1 -1
- data/test/drip/collections/tags_test.rb +1 -1
- data/test/drip/collections/webhooks_test.rb +1 -1
- data/test/drip/collections/workflow_triggers_test.rb +1 -1
- data/test/drip/collections/workflows_test.rb +1 -1
- data/test/drip/collections_test.rb +1 -1
- data/test/drip/request_test.rb +1 -1
- data/test/drip/resource_test.rb +1 -1
- data/test/drip/resources/account_test.rb +1 -1
- data/test/drip/resources/order_test.rb +1 -1
- data/test/drip/resources/subscriber_test.rb +1 -1
- data/test/drip/resources/tag_test.rb +1 -1
- data/test/drip/resources_test.rb +1 -1
- data/test/drip/response_test.rb +1 -1
- data/test/test_helper.rb +2 -2
- metadata +10 -53
- data/.travis.yml +0 -7
|
@@ -11,7 +11,7 @@ module Drip
|
|
|
11
11
|
# Returns a Drip::Response.
|
|
12
12
|
# See https://developer.drip.com/#cart-activity
|
|
13
13
|
def create_cart_activity_event(data = {})
|
|
14
|
-
raise ArgumentError, 'email:, person_id:, or :visitor_uuid parameter required' if
|
|
14
|
+
raise ArgumentError, 'email:, person_id:, or :visitor_uuid parameter required' if missing_cart_identifier?(data)
|
|
15
15
|
|
|
16
16
|
%i[provider action cart_id cart_url].each do |key|
|
|
17
17
|
raise ArgumentError, "#{key}: parameter required" unless data.key?(key)
|
|
@@ -47,10 +47,12 @@ module Drip
|
|
|
47
47
|
# Returns a Drip::Response.
|
|
48
48
|
# See https://developer.drip.com/#create-or-update-a-batch-of-orders
|
|
49
49
|
def create_order_activity_events(records = [])
|
|
50
|
+
required_keys = %i[provider action order_id]
|
|
51
|
+
|
|
50
52
|
records.each_with_index do |record, i|
|
|
51
53
|
raise ArgumentError, "email: or person_id: parameter required in record #{i}" if !record.key?(:email) && !record.key?(:person_id)
|
|
52
54
|
|
|
53
|
-
|
|
55
|
+
required_keys.each do |key|
|
|
54
56
|
raise ArgumentError, "#{key}: parameter required in record #{i}" unless record.key?(key)
|
|
55
57
|
end
|
|
56
58
|
|
|
@@ -75,6 +77,28 @@ module Drip
|
|
|
75
77
|
data[:occurred_at] = Time.now.iso8601 unless data.key?(:occurred_at)
|
|
76
78
|
make_json_request :post, "v3/#{account_id}/shopper_activity/product", data
|
|
77
79
|
end
|
|
80
|
+
|
|
81
|
+
# Public: Create a checkout activity event.
|
|
82
|
+
#
|
|
83
|
+
# options - Required. A Hash of additional checkout options. Refer to the
|
|
84
|
+
# Drip API docs for the required schema.
|
|
85
|
+
#
|
|
86
|
+
# Returns a Drip::Response.
|
|
87
|
+
# See https://developer.drip.com/#checkout-activity
|
|
88
|
+
def create_checkout_activity_event(data = {})
|
|
89
|
+
%i[provider action checkout_id].each do |key|
|
|
90
|
+
raise ArgumentError, "#{key}: parameter required" unless data.key?(key)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
data[:occurred_at] = Time.now.iso8601 unless data.key?(:occurred_at)
|
|
94
|
+
make_json_request :post, "v3/#{account_id}/shopper_activity/checkout", data
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
private
|
|
99
|
+
|
|
100
|
+
def missing_cart_identifier?(data)
|
|
101
|
+
!data.key?(:email) && !data.key?(:person_id) && !data.key?(:visitor_uuid)
|
|
78
102
|
end
|
|
79
103
|
end
|
|
80
104
|
end
|
|
@@ -57,7 +57,8 @@ module Drip
|
|
|
57
57
|
data = {}
|
|
58
58
|
data[:email] = args[0] if args[0].is_a? String
|
|
59
59
|
data.merge!(args.last) if args.last.is_a? Hash
|
|
60
|
-
raise ArgumentError, 'email: or id: or bigcommerce_subscriber_id: parameter required' if missing_subscriber_identifier(data)
|
|
60
|
+
raise ArgumentError, 'email: or id: or bigcommerce_subscriber_id: parameter required' if missing_subscriber_identifier?(data)
|
|
61
|
+
|
|
61
62
|
make_json_api_request :post, "v2/#{account_id}/subscribers", private_generate_resource("subscribers", data)
|
|
62
63
|
end
|
|
63
64
|
|
|
@@ -104,7 +105,7 @@ module Drip
|
|
|
104
105
|
# See https://www.getdrip.com/docs/rest-api#unsubscribe
|
|
105
106
|
def unsubscribe(id_or_email, options = {})
|
|
106
107
|
url = "v2/#{account_id}/subscribers/#{CGI.escape id_or_email}/remove"
|
|
107
|
-
url += options[:campaign_id] ? "?campaign_id=#{options[:campaign_id]}" : ""
|
|
108
|
+
url += options[:campaign_id] ? "?campaign_id=#{CGI.escape options[:campaign_id].to_s}" : ""
|
|
108
109
|
make_json_api_request :post, url
|
|
109
110
|
end
|
|
110
111
|
|
|
@@ -133,7 +134,7 @@ module Drip
|
|
|
133
134
|
# See https://www.getdrip.com/docs/rest-api#subscribe
|
|
134
135
|
def subscribe(email, campaign_id, options = {})
|
|
135
136
|
data = options.merge("email" => email)
|
|
136
|
-
url = "v2/#{account_id}/campaigns/#{campaign_id}/subscribers"
|
|
137
|
+
url = "v2/#{account_id}/campaigns/#{CGI.escape campaign_id.to_s}/subscribers"
|
|
137
138
|
make_json_api_request :post, url, private_generate_resource("subscribers", data)
|
|
138
139
|
end
|
|
139
140
|
|
|
@@ -160,7 +161,7 @@ module Drip
|
|
|
160
161
|
|
|
161
162
|
private
|
|
162
163
|
|
|
163
|
-
def missing_subscriber_identifier(data)
|
|
164
|
+
def missing_subscriber_identifier?(data)
|
|
164
165
|
external_ids = data[:external_ids] || {}
|
|
165
166
|
!data.key?(:email) && !data.key?(:id) && !external_ids.key?("bigcommerce_subscriber_id")
|
|
166
167
|
end
|
data/lib/drip/client/webhooks.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "cgi"
|
|
4
|
+
|
|
3
5
|
module Drip
|
|
4
6
|
class Client
|
|
5
7
|
module Webhooks
|
|
@@ -17,7 +19,7 @@ module Drip
|
|
|
17
19
|
# Returns a Drip::Response.
|
|
18
20
|
# See https://www.getdrip.com/docs/rest-api#webhooks
|
|
19
21
|
def webhook(id)
|
|
20
|
-
make_json_api_request :get, "v2/#{account_id}/webhooks/#{id}"
|
|
22
|
+
make_json_api_request :get, "v2/#{account_id}/webhooks/#{CGI.escape id.to_s}"
|
|
21
23
|
end
|
|
22
24
|
|
|
23
25
|
# Public: Create a webhook.
|
|
@@ -54,7 +56,7 @@ module Drip
|
|
|
54
56
|
# Returns a Drip::Response.
|
|
55
57
|
# See https://www.getdrip.com/docs/rest-api#webhooks
|
|
56
58
|
def delete_webhook(id)
|
|
57
|
-
make_json_api_request :delete, "v2/#{account_id}/webhooks/#{id}"
|
|
59
|
+
make_json_api_request :delete, "v2/#{account_id}/webhooks/#{CGI.escape id.to_s}"
|
|
58
60
|
end
|
|
59
61
|
end
|
|
60
62
|
end
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "cgi"
|
|
4
|
+
|
|
3
5
|
module Drip
|
|
4
6
|
class Client
|
|
5
7
|
module WorkflowTriggers
|
|
@@ -9,7 +11,7 @@ module Drip
|
|
|
9
11
|
# Returns a Drip::Response.
|
|
10
12
|
# See https://www.getdrip.com/docs/rest-api#workflow_triggers
|
|
11
13
|
def workflow_triggers(id)
|
|
12
|
-
make_json_api_request :get, "v2/#{account_id}/workflows/#{id}/triggers"
|
|
14
|
+
make_json_api_request :get, "v2/#{account_id}/workflows/#{CGI.escape id.to_s}/triggers"
|
|
13
15
|
end
|
|
14
16
|
|
|
15
17
|
# Public: Create a workflow trigger.
|
|
@@ -24,7 +26,7 @@ module Drip
|
|
|
24
26
|
# Returns a Drip::Response.
|
|
25
27
|
# See https://www.getdrip.com/docs/rest-api#workflows
|
|
26
28
|
def create_workflow_trigger(id, options = {})
|
|
27
|
-
make_json_api_request :post, "v2/#{account_id}/workflows/#{id}/triggers", private_generate_resource("triggers", options)
|
|
29
|
+
make_json_api_request :post, "v2/#{account_id}/workflows/#{CGI.escape id.to_s}/triggers", private_generate_resource("triggers", options)
|
|
28
30
|
end
|
|
29
31
|
|
|
30
32
|
# Public: Update a workflow trigger.
|
|
@@ -39,7 +41,7 @@ module Drip
|
|
|
39
41
|
# Returns a Drip::Response.
|
|
40
42
|
# See https://www.getdrip.com/docs/rest-api#workflows
|
|
41
43
|
def update_workflow_trigger(id, options = {})
|
|
42
|
-
make_json_api_request :put, "v2/#{account_id}/workflows/#{id}/triggers", private_generate_resource("triggers", options)
|
|
44
|
+
make_json_api_request :put, "v2/#{account_id}/workflows/#{CGI.escape id.to_s}/triggers", private_generate_resource("triggers", options)
|
|
43
45
|
end
|
|
44
46
|
end
|
|
45
47
|
end
|
|
@@ -23,7 +23,7 @@ module Drip
|
|
|
23
23
|
# Returns a Drip::Response.
|
|
24
24
|
# See https://www.getdrip.com/docs/rest-api#workflows
|
|
25
25
|
def workflow(id)
|
|
26
|
-
make_json_api_request :get, "v2/#{account_id}/workflows/#{id}"
|
|
26
|
+
make_json_api_request :get, "v2/#{account_id}/workflows/#{CGI.escape id.to_s}"
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
# Public: Activate a workflow.
|
|
@@ -32,7 +32,7 @@ module Drip
|
|
|
32
32
|
# Returns a Drip::Response.
|
|
33
33
|
# See https://www.getdrip.com/docs/rest-api#workflows
|
|
34
34
|
def activate_workflow(id)
|
|
35
|
-
make_json_api_request :post, "v2/#{account_id}/workflows/#{id}/activate"
|
|
35
|
+
make_json_api_request :post, "v2/#{account_id}/workflows/#{CGI.escape id.to_s}/activate"
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
# Public: Pause a workflow.
|
|
@@ -41,7 +41,7 @@ module Drip
|
|
|
41
41
|
# Returns a Drip::Response.
|
|
42
42
|
# See https://www.getdrip.com/docs/rest-api#workflows
|
|
43
43
|
def pause_workflow(id)
|
|
44
|
-
make_json_api_request :post, "v2/#{account_id}/workflows/#{id}/pause"
|
|
44
|
+
make_json_api_request :post, "v2/#{account_id}/workflows/#{CGI.escape id.to_s}/pause"
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
# Public: Start someone on a workflow.
|
|
@@ -65,7 +65,7 @@ module Drip
|
|
|
65
65
|
# Returns a Drip::Response.
|
|
66
66
|
# See https://www.getdrip.com/docs/rest-api#workflows
|
|
67
67
|
def start_subscriber_workflow(id, options = {})
|
|
68
|
-
make_json_api_request :post, "v2/#{account_id}/workflows/#{id}/subscribers", private_generate_resource("subscribers", options)
|
|
68
|
+
make_json_api_request :post, "v2/#{account_id}/workflows/#{CGI.escape id.to_s}/subscribers", private_generate_resource("subscribers", options)
|
|
69
69
|
end
|
|
70
70
|
|
|
71
71
|
# Public: Remove someone from a workflow.
|
|
@@ -75,7 +75,7 @@ module Drip
|
|
|
75
75
|
# Returns a Drip::Response.
|
|
76
76
|
# See https://www.getdrip.com/docs/rest-api#workflows
|
|
77
77
|
def remove_subscriber_workflow(workflow_id, id_or_email)
|
|
78
|
-
make_json_api_request :delete, "v2/#{account_id}/workflows/#{workflow_id}/subscribers/#{CGI.escape id_or_email}"
|
|
78
|
+
make_json_api_request :delete, "v2/#{account_id}/workflows/#{CGI.escape workflow_id.to_s}/subscribers/#{CGI.escape id_or_email}"
|
|
79
79
|
end
|
|
80
80
|
end
|
|
81
81
|
end
|
data/lib/drip/client.rb
CHANGED
|
@@ -49,7 +49,7 @@ module Drip
|
|
|
49
49
|
@config.public_send(config_key)
|
|
50
50
|
end
|
|
51
51
|
|
|
52
|
-
setter_name = "#{config_key}="
|
|
52
|
+
setter_name = :"#{config_key}="
|
|
53
53
|
define_method(setter_name) do |val|
|
|
54
54
|
warn "[DEPRECATED] Setting configuration on Drip::Client after initialization will be removed in a future version"
|
|
55
55
|
@config.public_send(setter_name, val)
|
|
@@ -77,7 +77,7 @@ module Drip
|
|
|
77
77
|
JSON_API_CONTENT_TYPE
|
|
78
78
|
end
|
|
79
79
|
|
|
80
|
-
Drip::Request::VERB_CLASS_MAPPING.
|
|
80
|
+
Drip::Request::VERB_CLASS_MAPPING.each_key do |verb|
|
|
81
81
|
define_method(verb) do |path, options = {}|
|
|
82
82
|
warn "[DEPRECATED] Drip::Client##{verb} please use the API endpoint specific methods"
|
|
83
83
|
make_json_api_request(verb, "v2/#{path}", options)
|
|
@@ -109,7 +109,7 @@ module Drip
|
|
|
109
109
|
end
|
|
110
110
|
end
|
|
111
111
|
|
|
112
|
-
def build_response(&
|
|
112
|
+
def build_response(&)
|
|
113
113
|
response = yield
|
|
114
114
|
Drip::Response.new(response.code.to_i, response.body || response.body == "" ? JSON.parse(response.body) : nil)
|
|
115
115
|
rescue JSON::ParserError
|
data/lib/drip/collection.rb
CHANGED
data/lib/drip/resource.rb
CHANGED
|
@@ -19,26 +19,26 @@ module Drip
|
|
|
19
19
|
true
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
def
|
|
23
|
-
attributes.
|
|
22
|
+
def respond_to_missing?(method_name, include_private = false)
|
|
23
|
+
attributes.key?(method_name.to_s) || super
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
def method_missing(method_name, *args, &
|
|
27
|
-
attributes.
|
|
26
|
+
def method_missing(method_name, *args, &)
|
|
27
|
+
attributes.key?(method_name.to_s) ? attributes[method_name.to_s] : super
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
private
|
|
31
31
|
|
|
32
32
|
def process(attributes)
|
|
33
33
|
{}.tap do |attrs|
|
|
34
|
-
attributes.
|
|
34
|
+
attributes.each_key do |key|
|
|
35
35
|
attrs[key] = process_attribute(key, attributes[key])
|
|
36
36
|
end
|
|
37
37
|
end
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
def process_attribute(key, raw_value)
|
|
41
|
-
if key.to_s
|
|
41
|
+
if key.to_s.match?(/_at$/) # auto-coerce times
|
|
42
42
|
raw_value ? Time.parse(raw_value) : nil
|
|
43
43
|
else
|
|
44
44
|
raw_value
|
data/lib/drip/resources/tag.rb
CHANGED
data/lib/drip/response.rb
CHANGED
|
@@ -26,12 +26,13 @@ module Drip
|
|
|
26
26
|
(200..299).cover?(status)
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
-
def
|
|
30
|
-
member_map.
|
|
29
|
+
def respond_to_missing?(method_name, include_private = false)
|
|
30
|
+
member_map.key?(method_name) || super
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
-
def method_missing(method_name, *args, &
|
|
34
|
-
return super unless member_map.
|
|
33
|
+
def method_missing(method_name, *args, &)
|
|
34
|
+
return super unless member_map.key?(method_name)
|
|
35
|
+
|
|
35
36
|
members[member_map[method_name]]
|
|
36
37
|
end
|
|
37
38
|
|
|
@@ -47,27 +48,29 @@ module Drip
|
|
|
47
48
|
|
|
48
49
|
def parse_members
|
|
49
50
|
return body unless success?
|
|
51
|
+
return {} unless body.is_a?(Hash)
|
|
52
|
+
|
|
50
53
|
{}.tap do |members|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
klass = case value
|
|
54
|
-
when Array
|
|
55
|
-
Drip::Collections.find_class(key)
|
|
56
|
-
when String
|
|
57
|
-
String
|
|
58
|
-
else
|
|
59
|
-
Drip::Resources.find_class(key)
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
members[key] = klass.new(value)
|
|
63
|
-
end
|
|
54
|
+
body.each do |key, value|
|
|
55
|
+
members[key] = member_class(key, value).new(value)
|
|
64
56
|
end
|
|
65
57
|
end
|
|
66
58
|
end
|
|
67
59
|
|
|
60
|
+
def member_class(key, value)
|
|
61
|
+
case value
|
|
62
|
+
when Array
|
|
63
|
+
Drip::Collections.find_class(key)
|
|
64
|
+
when String
|
|
65
|
+
String
|
|
66
|
+
else
|
|
67
|
+
Drip::Resources.find_class(key)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
68
71
|
def member_map
|
|
69
72
|
@member_map ||= {}.tap do |map|
|
|
70
|
-
members.
|
|
73
|
+
members.each_key { |key| map[key.to_sym] = key }
|
|
71
74
|
end
|
|
72
75
|
end
|
|
73
76
|
end
|
data/lib/drip/version.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
require_relative '../../test_helper'
|
|
4
4
|
|
|
5
5
|
class Drip::Client::AccountsTest < Drip::TestCase
|
|
6
6
|
def setup
|
|
@@ -26,7 +26,7 @@ class Drip::Client::AccountsTest < Drip::TestCase
|
|
|
26
26
|
setup do
|
|
27
27
|
@response_status = 200
|
|
28
28
|
@response_body = "{}"
|
|
29
|
-
@id =
|
|
29
|
+
@id = 9_999_999
|
|
30
30
|
|
|
31
31
|
stub_request(:get, "https://api.getdrip.com/v2/accounts/#{@id}").
|
|
32
32
|
to_return(status: @response_status, body: @response_body, headers: {})
|
|
@@ -37,4 +37,20 @@ class Drip::Client::AccountsTest < Drip::TestCase
|
|
|
37
37
|
assert_equal expected, @client.account(@id)
|
|
38
38
|
end
|
|
39
39
|
end
|
|
40
|
+
|
|
41
|
+
context "#account with an id that needs escaping" do
|
|
42
|
+
setup do
|
|
43
|
+
@response_status = 200
|
|
44
|
+
@response_body = "{}"
|
|
45
|
+
@id = "abc/123 xyz"
|
|
46
|
+
|
|
47
|
+
stub_request(:get, "https://api.getdrip.com/v2/accounts/#{CGI.escape @id}").
|
|
48
|
+
to_return(status: @response_status, body: @response_body, headers: {})
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
should "escape the id in the request path" do
|
|
52
|
+
expected = Drip::Response.new(@response_status, JSON.parse(@response_body))
|
|
53
|
+
assert_equal expected, @client.account(@id)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
40
56
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
require_relative '../../test_helper'
|
|
4
4
|
|
|
5
5
|
class Drip::Client::BroadcastsTest < Drip::TestCase
|
|
6
6
|
def setup
|
|
@@ -26,7 +26,7 @@ class Drip::Client::BroadcastsTest < Drip::TestCase
|
|
|
26
26
|
setup do
|
|
27
27
|
@response_status = 200
|
|
28
28
|
@response_body = "{}"
|
|
29
|
-
@id =
|
|
29
|
+
@id = 99_999
|
|
30
30
|
|
|
31
31
|
stub_request(:get, "https://api.getdrip.com/v2/12345/broadcasts/#{@id}").
|
|
32
32
|
to_return(status: @response_status, body: @response_body, headers: {})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
require_relative '../../test_helper'
|
|
4
4
|
|
|
5
5
|
class Drip::Client::CampaignsTest < Drip::TestCase
|
|
6
6
|
def setup
|
|
@@ -26,7 +26,7 @@ class Drip::Client::CampaignsTest < Drip::TestCase
|
|
|
26
26
|
setup do
|
|
27
27
|
@response_status = 200
|
|
28
28
|
@response_body = "{}"
|
|
29
|
-
@id =
|
|
29
|
+
@id = 9_999_999
|
|
30
30
|
|
|
31
31
|
stub_request(:get, "https://api.getdrip.com/v2/12345/campaigns/#{@id}").
|
|
32
32
|
to_return(status: @response_status, body: @response_body, headers: {})
|
|
@@ -42,7 +42,7 @@ class Drip::Client::CampaignsTest < Drip::TestCase
|
|
|
42
42
|
setup do
|
|
43
43
|
@response_status = 204
|
|
44
44
|
@response_body = nil
|
|
45
|
-
@id =
|
|
45
|
+
@id = 9_999_999
|
|
46
46
|
|
|
47
47
|
stub_request(:post, "https://api.getdrip.com/v2/12345/campaigns/#{@id}/activate").
|
|
48
48
|
to_return(status: @response_status, body: @response_body, headers: {})
|
|
@@ -58,7 +58,7 @@ class Drip::Client::CampaignsTest < Drip::TestCase
|
|
|
58
58
|
setup do
|
|
59
59
|
@response_status = 204
|
|
60
60
|
@response_body = nil
|
|
61
|
-
@id =
|
|
61
|
+
@id = 9_999_999
|
|
62
62
|
|
|
63
63
|
stub_request(:post, "https://api.getdrip.com/v2/12345/campaigns/#{@id}/pause").
|
|
64
64
|
to_return(status: @response_status, body: @response_body, headers: {})
|
|
@@ -74,7 +74,7 @@ class Drip::Client::CampaignsTest < Drip::TestCase
|
|
|
74
74
|
setup do
|
|
75
75
|
@response_status = 200
|
|
76
76
|
@response_body = "{}"
|
|
77
|
-
@id =
|
|
77
|
+
@id = 9_999_999
|
|
78
78
|
|
|
79
79
|
stub_request(:get, "https://api.getdrip.com/v2/12345/campaigns/#{@id}/subscribers").
|
|
80
80
|
to_return(status: @response_status, body: @response_body, headers: {})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
require_relative '../../test_helper'
|
|
4
4
|
require "drip/client/configuration"
|
|
5
5
|
|
|
6
6
|
class Drip::Client::ConfigurationTest < Drip::TestCase
|
|
@@ -109,4 +109,17 @@ class Drip::Client::ConfigurationTest < Drip::TestCase
|
|
|
109
109
|
assert_equal 42, config.http_timeout
|
|
110
110
|
end
|
|
111
111
|
end
|
|
112
|
+
|
|
113
|
+
context "#skip_analytics" do
|
|
114
|
+
should "accept passed parameter" do
|
|
115
|
+
config = Drip::Client::Configuration.new(skip_analytics: true)
|
|
116
|
+
assert_equal true, config.skip_analytics
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
should "allow setter" do
|
|
120
|
+
config = Drip::Client::Configuration.new
|
|
121
|
+
config.skip_analytics = true
|
|
122
|
+
assert_equal true, config.skip_analytics
|
|
123
|
+
end
|
|
124
|
+
end
|
|
112
125
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
require_relative '../../test_helper'
|
|
4
4
|
|
|
5
5
|
class Drip::Client::ConversionsTest < Drip::TestCase
|
|
6
6
|
def setup
|
|
@@ -26,7 +26,7 @@ class Drip::Client::ConversionsTest < Drip::TestCase
|
|
|
26
26
|
setup do
|
|
27
27
|
@response_status = 200
|
|
28
28
|
@response_body = "{}"
|
|
29
|
-
@id =
|
|
29
|
+
@id = 9_999_999
|
|
30
30
|
|
|
31
31
|
stub_request(:get, "https://api.getdrip.com/v2/12345/goals/#{@id}").
|
|
32
32
|
to_return(status: @response_status, body: @response_body, headers: {})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
require_relative '../../test_helper'
|
|
4
4
|
|
|
5
5
|
class Drip::Client::FormsTest < Drip::TestCase
|
|
6
6
|
def setup
|
|
@@ -26,7 +26,7 @@ class Drip::Client::FormsTest < Drip::TestCase
|
|
|
26
26
|
setup do
|
|
27
27
|
@response_status = 200
|
|
28
28
|
@response_body = "{}"
|
|
29
|
-
@id =
|
|
29
|
+
@id = 9_999_999
|
|
30
30
|
|
|
31
31
|
stub_request(:get, "https://api.getdrip.com/v2/12345/forms/#{@id}").
|
|
32
32
|
to_return(status: @response_status, body: @response_body, headers: {})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
require_relative '../../test_helper'
|
|
4
4
|
require "drip/client/configuration"
|
|
5
5
|
require "drip/client/http_client"
|
|
6
6
|
require "drip/request"
|
|
@@ -19,7 +19,7 @@ class Drip::Client::HTTPClientTest < Drip::TestCase
|
|
|
19
19
|
|
|
20
20
|
@client.make_request(Drip::Request.new(:get, URI("https://api.getdrip.com/v2/testpath")))
|
|
21
21
|
|
|
22
|
-
header = "Basic #{Base64.encode64(@key
|
|
22
|
+
header = "Basic #{Base64.encode64("#{@key}:")}".strip
|
|
23
23
|
assert_requested :get, "https://api.getdrip.com/v2/testpath", headers: { 'Authorization' => header }
|
|
24
24
|
end
|
|
25
25
|
end
|
|
@@ -68,6 +68,36 @@ class Drip::Client::HTTPClientTest < Drip::TestCase
|
|
|
68
68
|
end
|
|
69
69
|
end
|
|
70
70
|
|
|
71
|
+
context "given a redirect to a different host" do
|
|
72
|
+
setup do
|
|
73
|
+
@config = Drip::Client::Configuration.new(api_key: "secret-key")
|
|
74
|
+
@client = Drip::Client::HTTPClient.new(@config)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
should "not forward credentials to the redirect target" do
|
|
78
|
+
stub_request(:get, "https://api.getdrip.com/v2/testpath").
|
|
79
|
+
to_return(status: 301, body: "", headers: { "Location" => "https://evil.example.com/steal" })
|
|
80
|
+
stub_request(:get, "https://evil.example.com/steal").
|
|
81
|
+
to_return(status: 200, body: "{}")
|
|
82
|
+
|
|
83
|
+
@client.make_request(Drip::Request.new(:get, URI("https://api.getdrip.com/v2/testpath")))
|
|
84
|
+
|
|
85
|
+
assert_requested(:get, "https://api.getdrip.com/v2/testpath") { |req| req.headers.key?("Authorization") }
|
|
86
|
+
assert_requested(:get, "https://evil.example.com/steal") { |req| !req.headers.key?("Authorization") }
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
should "still forward credentials when the redirect stays on the same host" do
|
|
90
|
+
stub_request(:get, "https://api.getdrip.com/v2/testpath").
|
|
91
|
+
to_return(status: 301, body: "", headers: { "Location" => "https://api.getdrip.com/v2/othertestpath" })
|
|
92
|
+
stub_request(:get, "https://api.getdrip.com/v2/othertestpath").
|
|
93
|
+
to_return(status: 200, body: "{}")
|
|
94
|
+
|
|
95
|
+
@client.make_request(Drip::Request.new(:get, URI("https://api.getdrip.com/v2/testpath")))
|
|
96
|
+
|
|
97
|
+
assert_requested(:get, "https://api.getdrip.com/v2/othertestpath") { |req| req.headers.key?("Authorization") }
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
71
101
|
context "given a get request" do
|
|
72
102
|
setup do
|
|
73
103
|
@config = Drip::Client::Configuration.new(http_open_timeout: 20)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
require_relative '../../test_helper'
|
|
4
4
|
|
|
5
5
|
class Drip::Client::ShopperActivityTest < Drip::TestCase
|
|
6
6
|
def setup
|
|
@@ -186,4 +186,38 @@ class Drip::Client::ShopperActivityTest < Drip::TestCase
|
|
|
186
186
|
assert_raises(ArgumentError) { @client.create_product_activity_event(@options) }
|
|
187
187
|
end
|
|
188
188
|
end
|
|
189
|
+
|
|
190
|
+
context "#create_checkout_activity_event" do
|
|
191
|
+
setup do
|
|
192
|
+
@email = "drippy@drip.com"
|
|
193
|
+
@options = {
|
|
194
|
+
email: @email,
|
|
195
|
+
provider: "shopify",
|
|
196
|
+
action: "created",
|
|
197
|
+
occurred_at: "2019-01-28T12:15:23Z",
|
|
198
|
+
checkout_id: "B01J4",
|
|
199
|
+
total_price: 11.16
|
|
200
|
+
}
|
|
201
|
+
@response_status = 202
|
|
202
|
+
@response_body = "{}"
|
|
203
|
+
|
|
204
|
+
stub_request(:post, "https://api.getdrip.com/v3/12345/shopper_activity/checkout").
|
|
205
|
+
with(headers: { "Content-Type" => "application/json" }).
|
|
206
|
+
to_return(status: @response_status, body: @response_body, headers: {})
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
should "send the right request" do
|
|
210
|
+
expected = Drip::Response.new(@response_status, JSON.parse(@response_body))
|
|
211
|
+
assert_equal expected, @client.create_checkout_activity_event(@options)
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
should "return error with missing fields" do
|
|
215
|
+
%i[provider action checkout_id].each do |key|
|
|
216
|
+
params = @options.dup
|
|
217
|
+
params.delete(key)
|
|
218
|
+
|
|
219
|
+
assert_raises(ArgumentError) { @client.create_checkout_activity_event(params) }
|
|
220
|
+
end
|
|
221
|
+
end
|
|
222
|
+
end
|
|
189
223
|
end
|