drip-ruby 3.4.1 → 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.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/.github/pull_request_template.md +39 -0
  3. data/.github/workflows/ci.yml +35 -0
  4. data/.rubocop.yml +27 -6
  5. data/.rubocop_todo.yml +1 -97
  6. data/CHANGELOG.md +48 -1
  7. data/Gemfile +9 -8
  8. data/README.md +1 -2
  9. data/drip-ruby.gemspec +4 -4
  10. data/flake.lock +61 -0
  11. data/flake.nix +32 -0
  12. data/lib/drip/client/accounts.rb +3 -1
  13. data/lib/drip/client/broadcasts.rb +3 -1
  14. data/lib/drip/client/campaign_subscriptions.rb +3 -1
  15. data/lib/drip/client/campaigns.rb +6 -4
  16. data/lib/drip/client/configuration.rb +9 -1
  17. data/lib/drip/client/conversions.rb +3 -1
  18. data/lib/drip/client/forms.rb +3 -1
  19. data/lib/drip/client/http_client.rb +30 -11
  20. data/lib/drip/client/orders.rb +1 -1
  21. data/lib/drip/client/shopper_activity.rb +26 -2
  22. data/lib/drip/client/subscribers.rb +18 -5
  23. data/lib/drip/client/webhooks.rb +4 -2
  24. data/lib/drip/client/workflow_triggers.rb +5 -3
  25. data/lib/drip/client/workflows.rb +5 -5
  26. data/lib/drip/client.rb +3 -3
  27. data/lib/drip/collection.rb +2 -2
  28. data/lib/drip/resource.rb +6 -6
  29. data/lib/drip/resources/tag.rb +0 -5
  30. data/lib/drip/response.rb +21 -18
  31. data/lib/drip/version.rb +1 -1
  32. data/test/drip/client/accounts_test.rb +18 -2
  33. data/test/drip/client/broadcasts_test.rb +2 -2
  34. data/test/drip/client/campaign_subscriptions_test.rb +1 -1
  35. data/test/drip/client/campaigns_test.rb +5 -5
  36. data/test/drip/client/configuration_test.rb +14 -1
  37. data/test/drip/client/conversions_test.rb +2 -2
  38. data/test/drip/client/custom_fields_test.rb +1 -1
  39. data/test/drip/client/events_test.rb +1 -1
  40. data/test/drip/client/forms_test.rb +2 -2
  41. data/test/drip/client/http_client_test.rb +32 -2
  42. data/test/drip/client/orders_test.rb +1 -1
  43. data/test/drip/client/shopper_activity_test.rb +35 -1
  44. data/test/drip/client/subscribers_test.rb +45 -2
  45. data/test/drip/client/tags_test.rb +1 -1
  46. data/test/drip/client/users_test.rb +1 -1
  47. data/test/drip/client/webhooks_test.rb +1 -1
  48. data/test/drip/client/workflow_triggers_test.rb +2 -2
  49. data/test/drip/client/workflows_test.rb +18 -2
  50. data/test/drip/client_test.rb +8 -6
  51. data/test/drip/collection_test.rb +1 -1
  52. data/test/drip/collections/account_test.rb +1 -1
  53. data/test/drip/collections/broadcasts_test.rb +1 -1
  54. data/test/drip/collections/campaign_subscriptions_test.rb +1 -1
  55. data/test/drip/collections/campaigns_test.rb +1 -1
  56. data/test/drip/collections/errors_test.rb +1 -1
  57. data/test/drip/collections/orders_test.rb +1 -1
  58. data/test/drip/collections/purchases_test.rb +1 -1
  59. data/test/drip/collections/tags_test.rb +1 -1
  60. data/test/drip/collections/webhooks_test.rb +1 -1
  61. data/test/drip/collections/workflow_triggers_test.rb +1 -1
  62. data/test/drip/collections/workflows_test.rb +1 -1
  63. data/test/drip/collections_test.rb +1 -1
  64. data/test/drip/request_test.rb +1 -1
  65. data/test/drip/resource_test.rb +1 -1
  66. data/test/drip/resources/account_test.rb +1 -1
  67. data/test/drip/resources/order_test.rb +1 -1
  68. data/test/drip/resources/subscriber_test.rb +1 -1
  69. data/test/drip/resources/tag_test.rb +1 -1
  70. data/test/drip/resources_test.rb +1 -1
  71. data/test/drip/response_test.rb +1 -1
  72. data/test/test_helper.rb +2 -2
  73. metadata +11 -53
  74. data/.travis.yml +0 -7
@@ -12,7 +12,7 @@ module Drip
12
12
  # Returns a Drip::Response.
13
13
  # See https://developer.drip.com/#orders
14
14
  def create_or_update_order(email, options = {})
15
- data = options.merge(email: email)
15
+ data = options.merge("email" => email)
16
16
  make_json_api_request :post, "v2/#{account_id}/orders", private_generate_resource("orders", data)
17
17
  end
18
18
 
@@ -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 !data.key?(:email) && !data.key?(:person_id) && !data.key?(:visitor_uuid)
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
- %i[provider action order_id].each do |key|
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
@@ -35,8 +35,10 @@ module Drip
35
35
  #
36
36
  # email - Optional. The String subscriber email address. (Deprecated in favor of a hash argument)
37
37
  # options - A Hash of options.
38
- # - email - Required (or id). Lookup the subscriber by email.
39
- # - id - Required (or email). Lookup the subscriber by Drip ID.
38
+ # - email - Required (or id, or bigcommerce_subscriber_id).
39
+ # Lookup the subscriber by email.
40
+ # - id - Required (or email, or bigcommerce_subscriber_id).
41
+ # Lookup the subscriber by Drip ID.
40
42
  # - new_email - Optional. A new email address for the subscriber.
41
43
  # If provided and a subscriber with the email above
42
44
  # does not exist, this address will be used to
@@ -45,6 +47,9 @@ module Drip
45
47
  # format). Defaults to Etc/UTC.
46
48
  # - custom_fields - Optional. A Hash of custom field data.
47
49
  # - tags - Optional. An Array of tags.
50
+ # - external_ids - Optional. A hash of relevant ids for other integrations.
51
+ # For unsubscribing BigCommerce subscribers, a bigcommerce_subscriber_id
52
+ # can be provided in external_ids rather than email or id as the required field.
48
53
  #
49
54
  # Returns a Drip::Response.
50
55
  # See https://www.getdrip.com/docs/rest-api#create_or_update_subscriber
@@ -52,7 +57,8 @@ module Drip
52
57
  data = {}
53
58
  data[:email] = args[0] if args[0].is_a? String
54
59
  data.merge!(args.last) if args.last.is_a? Hash
55
- raise ArgumentError, 'email: or id: parameter required' if !data.key?(:email) && !data.key?(:id)
60
+ raise ArgumentError, 'email: or id: or bigcommerce_subscriber_id: parameter required' if missing_subscriber_identifier?(data)
61
+
56
62
  make_json_api_request :post, "v2/#{account_id}/subscribers", private_generate_resource("subscribers", data)
57
63
  end
58
64
 
@@ -99,7 +105,7 @@ module Drip
99
105
  # See https://www.getdrip.com/docs/rest-api#unsubscribe
100
106
  def unsubscribe(id_or_email, options = {})
101
107
  url = "v2/#{account_id}/subscribers/#{CGI.escape id_or_email}/remove"
102
- url += options[:campaign_id] ? "?campaign_id=#{options[:campaign_id]}" : ""
108
+ url += options[:campaign_id] ? "?campaign_id=#{CGI.escape options[:campaign_id].to_s}" : ""
103
109
  make_json_api_request :post, url
104
110
  end
105
111
 
@@ -128,7 +134,7 @@ module Drip
128
134
  # See https://www.getdrip.com/docs/rest-api#subscribe
129
135
  def subscribe(email, campaign_id, options = {})
130
136
  data = options.merge("email" => email)
131
- url = "v2/#{account_id}/campaigns/#{campaign_id}/subscribers"
137
+ url = "v2/#{account_id}/campaigns/#{CGI.escape campaign_id.to_s}/subscribers"
132
138
  make_json_api_request :post, url, private_generate_resource("subscribers", data)
133
139
  end
134
140
 
@@ -152,5 +158,12 @@ module Drip
152
158
  make_json_api_request :post, "v2/#{account_id}/subscribers/#{CGI.escape id_or_email}/unsubscribe_all"
153
159
  end
154
160
  end
161
+
162
+ private
163
+
164
+ def missing_subscriber_identifier?(data)
165
+ external_ids = data[:external_ids] || {}
166
+ !data.key?(:email) && !data.key?(:id) && !external_ids.key?("bigcommerce_subscriber_id")
167
+ end
155
168
  end
156
169
  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 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}=".to_sym
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.keys.each do |verb|
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(&block)
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
@@ -34,8 +34,8 @@ module Drip
34
34
  items.length < 2
35
35
  end
36
36
 
37
- def each(&block)
38
- items.each { |item| yield(item) }
37
+ def each(&)
38
+ items.each(&)
39
39
  end
40
40
  end
41
41
  end
data/lib/drip/resource.rb CHANGED
@@ -19,26 +19,26 @@ module Drip
19
19
  true
20
20
  end
21
21
 
22
- def respond_to?(method_name, include_private = false)
23
- attributes.keys.include?(method_name.to_s) || super
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, &block)
27
- attributes.keys.include?(method_name.to_s) ? attributes[method_name.to_s] : super
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.keys.each do |key|
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 =~ /_at$/ # auto-coerce times
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
@@ -7,10 +7,5 @@ module Drip
7
7
  def self.resource_name
8
8
  "tag"
9
9
  end
10
-
11
- def initialize(raw_data = {})
12
- @raw_attributes = raw_data.dup.freeze
13
- @attributes = @raw_attributes
14
- end
15
10
  end
16
11
  end
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 respond_to?(method_name, include_private = false)
30
- member_map.keys.include?(method_name) || super
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, &block)
34
- return super unless member_map.keys.include?(method_name)
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
- if body.is_a?(Hash)
52
- body.each do |key, value|
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.each { |key, _value| map[key.to_sym] = key }
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,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Drip
4
- VERSION = "3.4.1"
4
+ VERSION = "3.5.0"
5
5
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require File.dirname(__FILE__) + '/../../test_helper.rb'
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 = 9999999
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
- require File.dirname(__FILE__) + '/../../test_helper.rb'
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 = 99999
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
- require File.dirname(__FILE__) + '/../../test_helper.rb'
3
+ require_relative '../../test_helper'
4
4
 
5
5
  class Drip::Client::CampaignSubscriptionsTest < Drip::TestCase
6
6
  def setup
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require File.dirname(__FILE__) + '/../../test_helper.rb'
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 = 9999999
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 = 9999999
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 = 9999999
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 = 9999999
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
- require File.dirname(__FILE__) + '/../../test_helper.rb'
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
- require File.dirname(__FILE__) + '/../../test_helper.rb'
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 = 9999999
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
- require File.dirname(__FILE__) + '/../../test_helper.rb'
3
+ require_relative '../../test_helper'
4
4
 
5
5
  class Drip::Client::CustomFieldsTest < Drip::TestCase
6
6
  def setup
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require File.dirname(__FILE__) + '/../../test_helper.rb'
3
+ require_relative '../../test_helper'
4
4
 
5
5
  class Drip::Client::EventsTest < Drip::TestCase
6
6
  def setup
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require File.dirname(__FILE__) + '/../../test_helper.rb'
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 = 9999999
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
- require File.dirname(__FILE__) + '/../../test_helper.rb'
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 + ':')}".strip
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
- require File.dirname(__FILE__) + '/../../test_helper.rb'
3
+ require_relative '../../test_helper'
4
4
 
5
5
  class Drip::Client::OrdersTest < Drip::TestCase
6
6
  def setup