drip-ruby 3.2.0 → 3.4.2

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 (104) hide show
  1. checksums.yaml +5 -5
  2. data/.github/pull_request_template.md +39 -0
  3. data/.rubocop.yml +5 -1
  4. data/.rubocop_todo.yml +17 -9
  5. data/.travis.yml +2 -4
  6. data/CHANGELOG.md +51 -1
  7. data/Gemfile +12 -0
  8. data/README.md +6 -0
  9. data/Rakefile +2 -0
  10. data/drip-ruby.gemspec +4 -11
  11. data/lib/drip.rb +2 -0
  12. data/lib/drip/client.rb +48 -66
  13. data/lib/drip/client/accounts.rb +4 -2
  14. data/lib/drip/client/broadcasts.rb +4 -2
  15. data/lib/drip/client/campaign_subscriptions.rb +3 -1
  16. data/lib/drip/client/campaigns.rb +7 -5
  17. data/lib/drip/client/configuration.rb +30 -0
  18. data/lib/drip/client/conversions.rb +4 -2
  19. data/lib/drip/client/custom_fields.rb +3 -1
  20. data/lib/drip/client/events.rb +6 -4
  21. data/lib/drip/client/forms.rb +4 -2
  22. data/lib/drip/client/http_client.rb +66 -0
  23. data/lib/drip/client/orders.rb +5 -3
  24. data/lib/drip/client/shopper_activity.rb +80 -0
  25. data/lib/drip/client/subscribers.rb +30 -16
  26. data/lib/drip/client/tags.rb +5 -3
  27. data/lib/drip/client/users.rb +17 -0
  28. data/lib/drip/client/webhooks.rb +7 -5
  29. data/lib/drip/client/workflow_triggers.rb +5 -3
  30. data/lib/drip/client/workflows.rb +8 -6
  31. data/lib/drip/collection.rb +2 -0
  32. data/lib/drip/collections.rb +2 -0
  33. data/lib/drip/collections/accounts.rb +2 -0
  34. data/lib/drip/collections/broadcasts.rb +2 -0
  35. data/lib/drip/collections/campaign_subscriptions.rb +2 -0
  36. data/lib/drip/collections/campaigns.rb +2 -0
  37. data/lib/drip/collections/errors.rb +2 -0
  38. data/lib/drip/collections/orders.rb +2 -0
  39. data/lib/drip/collections/purchases.rb +2 -0
  40. data/lib/drip/collections/subscribers.rb +2 -0
  41. data/lib/drip/collections/tags.rb +2 -0
  42. data/lib/drip/collections/webhooks.rb +2 -0
  43. data/lib/drip/collections/workflow_triggers.rb +2 -0
  44. data/lib/drip/collections/workflows.rb +2 -0
  45. data/lib/drip/errors.rb +2 -0
  46. data/lib/drip/request.rb +33 -0
  47. data/lib/drip/resource.rb +2 -0
  48. data/lib/drip/resources.rb +2 -0
  49. data/lib/drip/resources/account.rb +2 -0
  50. data/lib/drip/resources/broadcast.rb +2 -0
  51. data/lib/drip/resources/campaign.rb +2 -0
  52. data/lib/drip/resources/campaign_subscription.rb +2 -0
  53. data/lib/drip/resources/error.rb +2 -0
  54. data/lib/drip/resources/order.rb +2 -0
  55. data/lib/drip/resources/purchase.rb +2 -0
  56. data/lib/drip/resources/subscriber.rb +2 -0
  57. data/lib/drip/resources/tag.rb +2 -0
  58. data/lib/drip/resources/webhook.rb +2 -0
  59. data/lib/drip/resources/workflow.rb +2 -0
  60. data/lib/drip/resources/workflow_trigger.rb +2 -0
  61. data/lib/drip/response.rb +15 -13
  62. data/lib/drip/version.rb +3 -1
  63. data/test/drip/client/accounts_test.rb +2 -0
  64. data/test/drip/client/broadcasts_test.rb +2 -0
  65. data/test/drip/client/campaign_subscriptions_test.rb +2 -0
  66. data/test/drip/client/campaigns_test.rb +2 -0
  67. data/test/drip/client/configuration_test.rb +112 -0
  68. data/test/drip/client/conversions_test.rb +2 -0
  69. data/test/drip/client/custom_fields_test.rb +2 -0
  70. data/test/drip/client/events_test.rb +2 -0
  71. data/test/drip/client/forms_test.rb +2 -0
  72. data/test/drip/client/http_client_test.rb +98 -0
  73. data/test/drip/client/orders_test.rb +2 -0
  74. data/test/drip/client/shopper_activity_test.rb +189 -0
  75. data/test/drip/client/subscribers_test.rb +8 -0
  76. data/test/drip/client/tags_test.rb +2 -0
  77. data/test/drip/client/users_test.rb +24 -0
  78. data/test/drip/client/webhooks_test.rb +2 -0
  79. data/test/drip/client/workflow_triggers_test.rb +2 -0
  80. data/test/drip/client/workflows_test.rb +2 -0
  81. data/test/drip/client_test.rb +34 -97
  82. data/test/drip/collection_test.rb +16 -0
  83. data/test/drip/collections/account_test.rb +10 -0
  84. data/test/drip/collections/broadcasts_test.rb +10 -0
  85. data/test/drip/collections/campaign_subscriptions_test.rb +10 -0
  86. data/test/drip/collections/campaigns_test.rb +10 -0
  87. data/test/drip/collections/errors_test.rb +10 -0
  88. data/test/drip/collections/orders_test.rb +10 -0
  89. data/test/drip/collections/purchases_test.rb +10 -0
  90. data/test/drip/collections/tags_test.rb +10 -0
  91. data/test/drip/collections/webhooks_test.rb +10 -0
  92. data/test/drip/collections/workflow_triggers_test.rb +10 -0
  93. data/test/drip/collections/workflows_test.rb +10 -0
  94. data/test/drip/collections_test.rb +2 -0
  95. data/test/drip/request_test.rb +60 -0
  96. data/test/drip/resource_test.rb +14 -0
  97. data/test/drip/resources/account_test.rb +2 -0
  98. data/test/drip/resources/order_test.rb +2 -0
  99. data/test/drip/resources/subscriber_test.rb +2 -0
  100. data/test/drip/resources/tag_test.rb +15 -0
  101. data/test/drip/resources_test.rb +2 -0
  102. data/test/drip/response_test.rb +35 -0
  103. data/test/test_helper.rb +5 -0
  104. metadata +50 -109
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "cgi"
2
4
 
3
5
  module Drip
@@ -8,7 +10,7 @@ module Drip
8
10
  # Returns a Drip::Response.
9
11
  # See https://www.getdrip.com/docs/rest-api#tags
10
12
  def tags
11
- get "#{account_id}/tags"
13
+ make_json_api_request :get, "v2/#{account_id}/tags"
12
14
  end
13
15
 
14
16
  # Public: Apply a tag to a subscriber.
@@ -20,7 +22,7 @@ module Drip
20
22
  # See https://www.getdrip.com/docs/rest-api#apply_tag
21
23
  def apply_tag(email, tag)
22
24
  data = { "email" => email, "tag" => tag }
23
- post "#{account_id}/tags", generate_resource("tags", data)
25
+ make_json_api_request :post, "v2/#{account_id}/tags", private_generate_resource("tags", data)
24
26
  end
25
27
 
26
28
  # Public: Remove a tag from a subscriber.
@@ -31,7 +33,7 @@ module Drip
31
33
  # Returns a Drip::Response.
32
34
  # See https://www.getdrip.com/docs/rest-api#remove_tag
33
35
  def remove_tag(email, tag)
34
- delete "#{account_id}/subscribers/#{CGI.escape email}/tags/#{CGI.escape tag}"
36
+ make_json_api_request :delete, "v2/#{account_id}/subscribers/#{CGI.escape email}/tags/#{CGI.escape tag}"
35
37
  end
36
38
  end
37
39
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "cgi"
4
+
5
+ module Drip
6
+ class Client
7
+ module Users
8
+ # Public: Fetch the authenticated user
9
+ #
10
+ # Returns a Drip::Response.
11
+ # See https://developer.drip.com/#users
12
+ def user
13
+ make_json_api_request :get, "v2/user"
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Drip
2
4
  class Client
3
5
  module Webhooks
@@ -6,7 +8,7 @@ module Drip
6
8
  # Returns a Drip::Response.
7
9
  # See https://www.getdrip.com/docs/rest-api#webhooks
8
10
  def webhooks
9
- get "#{account_id}/webhooks"
11
+ make_json_api_request :get, "v2/#{account_id}/webhooks"
10
12
  end
11
13
 
12
14
  # Public: Fetch a webhook
@@ -15,7 +17,7 @@ module Drip
15
17
  # Returns a Drip::Response.
16
18
  # See https://www.getdrip.com/docs/rest-api#webhooks
17
19
  def webhook(id)
18
- get "#{account_id}/webhooks/#{id}"
20
+ make_json_api_request :get, "v2/#{account_id}/webhooks/#{id}"
19
21
  end
20
22
 
21
23
  # Public: Create a webhook.
@@ -34,9 +36,9 @@ module Drip
34
36
  # See https://www.getdrip.com/docs/rest-api#subscriber_batches
35
37
  def create_webhook(post_url, include_received_email, events)
36
38
  include_received_email = include_received_email ? true : false
37
- url = "#{account_id}/webhooks"
39
+ url = "v2/#{account_id}/webhooks"
38
40
 
39
- post url, generate_resource(
41
+ make_json_api_request :post, url, private_generate_resource(
40
42
  "webhooks",
41
43
  {
42
44
  "post_url" => post_url,
@@ -52,7 +54,7 @@ module Drip
52
54
  # Returns a Drip::Response.
53
55
  # See https://www.getdrip.com/docs/rest-api#webhooks
54
56
  def delete_webhook(id)
55
- delete "#{account_id}/webhooks/#{id}"
57
+ make_json_api_request :delete, "v2/#{account_id}/webhooks/#{id}"
56
58
  end
57
59
  end
58
60
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Drip
2
4
  class Client
3
5
  module WorkflowTriggers
@@ -7,7 +9,7 @@ module Drip
7
9
  # Returns a Drip::Response.
8
10
  # See https://www.getdrip.com/docs/rest-api#workflow_triggers
9
11
  def workflow_triggers(id)
10
- get "#{account_id}/workflows/#{id}/triggers"
12
+ make_json_api_request :get, "v2/#{account_id}/workflows/#{id}/triggers"
11
13
  end
12
14
 
13
15
  # Public: Create a workflow trigger.
@@ -22,7 +24,7 @@ module Drip
22
24
  # Returns a Drip::Response.
23
25
  # See https://www.getdrip.com/docs/rest-api#workflows
24
26
  def create_workflow_trigger(id, options = {})
25
- post "#{account_id}/workflows/#{id}/triggers", generate_resource("triggers", options)
27
+ make_json_api_request :post, "v2/#{account_id}/workflows/#{id}/triggers", private_generate_resource("triggers", options)
26
28
  end
27
29
 
28
30
  # Public: Update a workflow trigger.
@@ -37,7 +39,7 @@ module Drip
37
39
  # Returns a Drip::Response.
38
40
  # See https://www.getdrip.com/docs/rest-api#workflows
39
41
  def update_workflow_trigger(id, options = {})
40
- put "#{account_id}/workflows/#{id}/triggers", generate_resource("triggers", options)
42
+ make_json_api_request :put, "v2/#{account_id}/workflows/#{id}/triggers", private_generate_resource("triggers", options)
41
43
  end
42
44
  end
43
45
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "cgi"
2
4
 
3
5
  module Drip
@@ -12,7 +14,7 @@ module Drip
12
14
  # Returns a Drip::Response.
13
15
  # See https://www.getdrip.com/docs/rest-api#workflows
14
16
  def workflows(options = {})
15
- get "#{account_id}/workflows", options
17
+ make_json_api_request :get, "v2/#{account_id}/workflows", options
16
18
  end
17
19
 
18
20
  # Public: Fetch a workflow.
@@ -21,7 +23,7 @@ module Drip
21
23
  # Returns a Drip::Response.
22
24
  # See https://www.getdrip.com/docs/rest-api#workflows
23
25
  def workflow(id)
24
- get "#{account_id}/workflows/#{id}"
26
+ make_json_api_request :get, "v2/#{account_id}/workflows/#{id}"
25
27
  end
26
28
 
27
29
  # Public: Activate a workflow.
@@ -30,7 +32,7 @@ module Drip
30
32
  # Returns a Drip::Response.
31
33
  # See https://www.getdrip.com/docs/rest-api#workflows
32
34
  def activate_workflow(id)
33
- post "#{account_id}/workflows/#{id}/activate"
35
+ make_json_api_request :post, "v2/#{account_id}/workflows/#{id}/activate"
34
36
  end
35
37
 
36
38
  # Public: Pause a workflow.
@@ -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 pause_workflow(id)
42
- post "#{account_id}/workflows/#{id}/pause"
44
+ make_json_api_request :post, "v2/#{account_id}/workflows/#{id}/pause"
43
45
  end
44
46
 
45
47
  # Public: Start someone on a workflow.
@@ -63,7 +65,7 @@ module Drip
63
65
  # Returns a Drip::Response.
64
66
  # See https://www.getdrip.com/docs/rest-api#workflows
65
67
  def start_subscriber_workflow(id, options = {})
66
- post "#{account_id}/workflows/#{id}/subscribers", generate_resource("subscribers", options)
68
+ make_json_api_request :post, "v2/#{account_id}/workflows/#{id}/subscribers", private_generate_resource("subscribers", options)
67
69
  end
68
70
 
69
71
  # Public: Remove someone from a workflow.
@@ -73,7 +75,7 @@ module Drip
73
75
  # Returns a Drip::Response.
74
76
  # See https://www.getdrip.com/docs/rest-api#workflows
75
77
  def remove_subscriber_workflow(workflow_id, id_or_email)
76
- delete "#{account_id}/workflows/#{workflow_id}/subscribers/#{CGI.escape id_or_email}"
78
+ make_json_api_request :delete, "v2/#{account_id}/workflows/#{workflow_id}/subscribers/#{CGI.escape id_or_email}"
77
79
  end
78
80
  end
79
81
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Drip
2
4
  class Collection
3
5
  include Enumerable
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "drip/collections/accounts"
2
4
  require "drip/collections/broadcasts"
3
5
  require "drip/collections/campaigns"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "drip/collection"
2
4
 
3
5
  module Drip
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "drip/collection"
2
4
 
3
5
  module Drip
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "drip/collection"
2
4
 
3
5
  module Drip
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "drip/collection"
2
4
 
3
5
  module Drip
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "drip/collection"
2
4
 
3
5
  module Drip
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "drip/collection"
2
4
 
3
5
  module Drip
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "drip/collection"
2
4
 
3
5
  module Drip
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "drip/collection"
2
4
 
3
5
  module Drip
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "drip/collection"
2
4
 
3
5
  module Drip
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "drip/collection"
2
4
 
3
5
  module Drip
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "drip/collection"
2
4
 
3
5
  module Drip
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "drip/collection"
2
4
 
3
5
  module Drip
data/lib/drip/errors.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Drip
2
4
  class TooManyRedirectsError < StandardError; end
3
5
  end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "net/http"
4
+
5
+ module Drip
6
+ class Request
7
+ attr_reader :http_verb, :url, :options, :content_type
8
+
9
+ VERB_CLASS_MAPPING = {
10
+ get: Net::HTTP::Get,
11
+ post: Net::HTTP::Post,
12
+ put: Net::HTTP::Put,
13
+ delete: Net::HTTP::Delete
14
+ }.freeze
15
+
16
+ def initialize(http_verb, url, options = {}, content_type = nil)
17
+ @http_verb = http_verb
18
+ @url = url
19
+ @options = options
20
+ @content_type = content_type
21
+ end
22
+
23
+ def verb_klass
24
+ VERB_CLASS_MAPPING[http_verb]
25
+ end
26
+
27
+ def body
28
+ return if http_verb == :get
29
+
30
+ options.to_json
31
+ end
32
+ end
33
+ end
data/lib/drip/resource.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "time"
2
4
 
3
5
  module Drip
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "drip/resources/account"
2
4
  require "drip/resources/broadcast"
3
5
  require "drip/resources/campaign"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "drip/resource"
2
4
 
3
5
  module Drip
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "drip/resource"
2
4
 
3
5
  module Drip
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "drip/resource"
2
4
 
3
5
  module Drip
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "drip/resource"
2
4
 
3
5
  module Drip
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "drip/resource"
2
4
 
3
5
  module Drip
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "drip/resource"
2
4
 
3
5
  module Drip
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "drip/resource"
2
4
 
3
5
  module Drip
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "drip/resource"
2
4
 
3
5
  module Drip
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "drip/resource"
2
4
 
3
5
  module Drip
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "drip/resource"
2
4
 
3
5
  module Drip
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "drip/resource"
2
4
 
3
5
  module Drip
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "drip/resource"
2
4
 
3
5
  module Drip
data/lib/drip/response.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "drip/resources"
2
4
  require "drip/collections"
3
5
 
@@ -44,20 +46,20 @@ module Drip
44
46
  end
45
47
 
46
48
  def parse_members
47
- if status == 429
48
- body
49
- else
50
- {}.tap do |members|
51
- if body.is_a?(Hash)
52
- body.each do |key, value|
53
- klass = if value.is_a?(Array)
54
- Drip::Collections.find_class(key)
55
- else
56
- Drip::Resources.find_class(key)
57
- end
49
+ return body unless success?
50
+ {}.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
58
61
 
59
- members[key] = klass.new(value)
60
- end
62
+ members[key] = klass.new(value)
61
63
  end
62
64
  end
63
65
  end