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.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +17 -0
  3. data/.rubocop_todo.yml +134 -0
  4. data/README.md +107 -13
  5. data/Rakefile +1 -1
  6. data/drip-ruby.gemspec +2 -2
  7. data/lib/drip/client.rb +23 -7
  8. data/lib/drip/client/accounts.rb +10 -0
  9. data/lib/drip/client/broadcasts.rb +29 -0
  10. data/lib/drip/client/campaign_subscriptions.rb +15 -0
  11. data/lib/drip/client/campaigns.rb +54 -0
  12. data/lib/drip/client/conversions.rb +27 -0
  13. data/lib/drip/client/custom_fields.rb +13 -0
  14. data/lib/drip/client/events.rb +13 -0
  15. data/lib/drip/client/forms.rb +23 -0
  16. data/lib/drip/client/purchases.rb +1 -1
  17. data/lib/drip/client/subscribers.rb +28 -6
  18. data/lib/drip/client/webhooks.rb +59 -0
  19. data/lib/drip/client/workflow_triggers.rb +44 -0
  20. data/lib/drip/client/workflows.rb +80 -0
  21. data/lib/drip/collections.rb +17 -5
  22. data/lib/drip/collections/broadcasts.rb +13 -0
  23. data/lib/drip/collections/campaign_subscriptions.rb +13 -0
  24. data/lib/drip/collections/campaigns.rb +13 -0
  25. data/lib/drip/collections/webhooks.rb +13 -0
  26. data/lib/drip/collections/workflow_triggers.rb +13 -0
  27. data/lib/drip/collections/workflows.rb +13 -0
  28. data/lib/drip/resources.rb +17 -5
  29. data/lib/drip/resources/broadcast.rb +9 -0
  30. data/lib/drip/resources/campaign.rb +9 -0
  31. data/lib/drip/resources/campaign_subscription.rb +9 -0
  32. data/lib/drip/resources/webhook.rb +9 -0
  33. data/lib/drip/resources/workflow.rb +9 -0
  34. data/lib/drip/resources/workflow_trigger.rb +9 -0
  35. data/lib/drip/response.rb +1 -1
  36. data/lib/drip/version.rb +1 -1
  37. data/test/drip/client/accounts_test.rb +17 -0
  38. data/test/drip/client/broadcasts_test.rb +47 -0
  39. data/test/drip/client/campaign_subscriptions_test.rb +31 -0
  40. data/test/drip/client/campaigns_test.rb +68 -0
  41. data/test/drip/client/conversions_test.rb +47 -0
  42. data/test/drip/client/custom_fields_test.rb +30 -0
  43. data/test/drip/client/events_test.rb +21 -5
  44. data/test/drip/client/forms_test.rb +47 -0
  45. data/test/drip/client/purchases_test.rb +0 -1
  46. data/test/drip/client/subscribers_test.rb +52 -9
  47. data/test/drip/client/webhooks_test.rb +91 -0
  48. data/test/drip/client/workflow_triggers_test.rb +85 -0
  49. data/test/drip/client/workflows_test.rb +122 -0
  50. data/test/drip/collection_test.rb +1 -1
  51. data/test/drip/collections_test.rb +8 -1
  52. data/test/drip/resources_test.rb +8 -1
  53. data/test/drip/response_test.rb +2 -2
  54. data/test/test_helper.rb +1 -1
  55. metadata +40 -2
@@ -16,6 +16,60 @@ module Drip
16
16
  def campaigns(options = {})
17
17
  get "#{account_id}/campaigns", options
18
18
  end
19
+
20
+ # Public: Fetch a campaign.
21
+ #
22
+ # id - Required. The String id of the campaign.
23
+ #
24
+ # Returns a Drip::Response.
25
+ # See https://www.getdrip.com/docs/rest-api#campaigns
26
+ def campaign(id)
27
+ get "#{account_id}/campaigns/#{id}"
28
+ end
29
+
30
+ # Public: Activate a campaign.
31
+ #
32
+ # id - Required. The String id of the campaign.
33
+ #
34
+ # Returns a Drip::Response.
35
+ # See https://www.getdrip.com/docs/rest-api#campaigns
36
+ def activate_campaign(id)
37
+ post "#{account_id}/campaigns/#{id}/activate"
38
+ end
39
+
40
+ # Public: Pause a campaign.
41
+ #
42
+ # id - Required. The String id of the campaign.
43
+ #
44
+ # Returns a Drip::Response.
45
+ # See https://www.getdrip.com/docs/rest-api#campaigns
46
+ def pause_campaign(id)
47
+ post "#{account_id}/campaigns/#{id}/pause"
48
+ end
49
+
50
+ # Public: List everyone subscribed to a campaign.
51
+ #
52
+ # id - Required. The String id of the campaign.
53
+ #
54
+ # options - A Hash of options
55
+ # - status - Optional. Filter by one of the following statuses:
56
+ # active, unsubscribed or removed. Defaults to active.
57
+ # - page - Optional. Use this parameter to paginate through
58
+ # your list of campaign subscribers. Each response contains a
59
+ # a `meta` object that includes `total_count` and
60
+ # `total_pages` attributes.
61
+ # - sort - Optional. Sort results by one of these fields:
62
+ # `id`, `created_at`. Default sorting is `created_at`
63
+ # - direction - Optional. The direction to sort the results:
64
+ # `asc`, `desc`. Defaults to `desc`
65
+ # - per_page - Optional. The number of records to be returned
66
+ # on each page. Defaults to 100. Maximum 1000
67
+ #
68
+ # Returns a Drip::Response.
69
+ # See https://www.getdrip.com/docs/rest-api#campaigns
70
+ def campaign_subscribers(id, options = {})
71
+ get "#{account_id}/campaigns/#{id}/subscribers", options
72
+ end
19
73
  end
20
74
  end
21
75
  end
@@ -0,0 +1,27 @@
1
+ module Drip
2
+ class Client
3
+ module Conversions
4
+ # Public: Fetch all conversions.
5
+ #
6
+ # options - A Hash of options.
7
+ # - status - Optional. Filter by one of the following statuses:
8
+ # active, disabled, or all. Defaults to all.
9
+ #
10
+ # Returns a Drip::Response.
11
+ # See https://www.getdrip.com/docs/rest-api#conversions
12
+ def conversions(options = {})
13
+ get "#{account_id}/goals", options
14
+ end
15
+
16
+ # Public: Fetch a conversion.
17
+ #
18
+ # id - Required. The String id of the conversion
19
+ #
20
+ # Returns a Drip::Response.
21
+ # See https://www.getdrip.com/docs/rest-api#conversions
22
+ def conversion(id)
23
+ get "#{account_id}/goals/#{id}"
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,13 @@
1
+ module Drip
2
+ class Client
3
+ module CustomFields
4
+ # Public: List all custom field identifiers.
5
+ #
6
+ # Returns a Drip::Response.
7
+ # See https://www.getdrip.com/docs/rest-api#custom_fields
8
+ def custom_fields
9
+ get "#{account_id}/custom_field_identifiers"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -32,6 +32,19 @@ module Drip
32
32
  url = "#{account_id}/events/batches"
33
33
  post url, generate_resource("batches", { "events" => events })
34
34
  end
35
+
36
+ # Public: Fetch all custom event actions.
37
+ #
38
+ # options - Optional. A Hash of options
39
+ # - page - Optional. The page number. Defaults to 1
40
+ # - per_page - Optional. The number of records to be returned
41
+ # on each page. Defaults to 100. Maximum 1000.
42
+ #
43
+ # Returns a Drip::Response.
44
+ # See https://www.getdrip.com/docs/rest-api#events
45
+ def event_actions(options = {})
46
+ get "#{account_id}/event_actions", options
47
+ end
35
48
  end
36
49
  end
37
50
  end
@@ -0,0 +1,23 @@
1
+ module Drip
2
+ class Client
3
+ module Forms
4
+ # Public: Fetch all forms.
5
+ #
6
+ # Returns a Drip::Response.
7
+ # See https://www.getdrip.com/docs/rest-api#forms
8
+ def forms
9
+ get "#{account_id}/forms"
10
+ end
11
+
12
+ # Public: Fetch a form.
13
+ #
14
+ # id - Required. The String id of the form
15
+ #
16
+ # Returns a Drip::Response.
17
+ # See https://www.getdrip.com/docs/rest-api#forms
18
+ def form(id)
19
+ get "#{account_id}/forms/#{id}"
20
+ end
21
+ end
22
+ end
23
+ end
@@ -37,7 +37,7 @@ module Drip
37
37
  # Returns a Drip::Response.
38
38
  # See https://www.getdrip.com/docs/rest-api#create_purchase
39
39
  def create_purchase(email, amount, options = {})
40
- data = options.merge(:amount => amount)
40
+ data = options.merge(amount: amount)
41
41
  post "#{account_id}/subscribers/#{CGI.escape email}/purchases", generate_resource("purchases", data)
42
42
  end
43
43
 
@@ -3,7 +3,7 @@ require "cgi"
3
3
  module Drip
4
4
  class Client
5
5
  module Subscribers
6
- # Public: Fetch a subscriber.
6
+ # Public: List all subscribers.
7
7
  #
8
8
  # options - A Hash of options.
9
9
  # - status - Optional. Filter by one of the following statuses:
@@ -37,7 +37,7 @@ module Drip
37
37
  # If provided and a subscriber with the email above
38
38
  # does not exist, this address will be used to
39
39
  # create a new subscriber.
40
- # - time_zone - Optional. The subscriber's time zone (in Olsen
40
+ # - time_zone - Optional. The subscriber's time zone (in Olson
41
41
  # format). Defaults to Etc/UTC.
42
42
  # - custom_fields - Optional. A Hash of custom field data.
43
43
  # - tags - Optional. An Array of tags.
@@ -45,7 +45,7 @@ module Drip
45
45
  # Returns a Drip::Response.
46
46
  # See https://www.getdrip.com/docs/rest-api#create_or_update_subscriber
47
47
  def create_or_update_subscriber(email, options = {})
48
- data = options.merge(:email => email)
48
+ data = options.merge(email: email)
49
49
  post "#{account_id}/subscribers", generate_resource("subscribers", data)
50
50
  end
51
51
 
@@ -57,7 +57,7 @@ module Drip
57
57
  # If provided and a subscriber with the email above
58
58
  # does not exist, this address will be used to
59
59
  # create a new subscriber.
60
- # - time_zone - Optional. The subscriber's time zone (in Olsen
60
+ # - time_zone - Optional. The subscriber's time zone (in Olson
61
61
  # format). Defaults to Etc/UTC.
62
62
  # - custom_fields - Optional. A Hash of custom field data.
63
63
  # - tags - Optional. An Array of tags.
@@ -69,6 +69,18 @@ module Drip
69
69
  post url, generate_resource("batches", { "subscribers" => subscribers })
70
70
  end
71
71
 
72
+ # Public: Unsubscribe a collection of subscribers.
73
+ #
74
+ # subscribers - Required. An Array of between 1 and 1000 Hashes of subscriber data.
75
+ # - email - Required. The String subscriber email address.
76
+ #
77
+ # Returns a Drip::Response
78
+ # See https://www.getdrip.com/docs/rest-api#subscriber_batches
79
+ def unsubscribe_subscribers(subscribers)
80
+ url = "#{account_id}/unsubscribes/batches"
81
+ post url, generate_resource("batches", { "subscribers" => subscribers })
82
+ end
83
+
72
84
  # Public: Unsubscribe a subscriber globally or from a specific campaign.
73
85
  #
74
86
  # id_or_email - Required. The String id or email address of the subscriber.
@@ -79,7 +91,7 @@ module Drip
79
91
  # Returns a Drip::Response.
80
92
  # See https://www.getdrip.com/docs/rest-api#unsubscribe
81
93
  def unsubscribe(id_or_email, options = {})
82
- url = "#{account_id}/subscribers/#{CGI.escape id_or_email}/unsubscribe"
94
+ url = "#{account_id}/subscribers/#{CGI.escape id_or_email}/remove"
83
95
  url += options[:campaign_id] ? "?campaign_id=#{options[:campaign_id]}" : ""
84
96
  post url
85
97
  end
@@ -95,7 +107,7 @@ module Drip
95
107
  # on the campaign.
96
108
  # - starting_email_index - Optional. The index (zero-based) of
97
109
  # the email to send first. Defaults to 0.
98
- # - time_zone - Optional. The subscriber's time zone (in Olsen
110
+ # - time_zone - Optional. The subscriber's time zone (in Olson
99
111
  # format). Defaults to Etc/UTC.
100
112
  # - custom_fields - Optional. A Hash of custom field data.
101
113
  # - tags - Optional. An Array of tags.
@@ -122,6 +134,16 @@ module Drip
122
134
  def delete_subscriber(id_or_email)
123
135
  delete "#{account_id}/subscribers/#{CGI.escape id_or_email}"
124
136
  end
137
+
138
+ # Public: Unsubscribe a subscriber from all mailings.
139
+ #
140
+ # id_or_email - Required. The String id or email address of the subscriber.
141
+ #
142
+ # Returns No Content.
143
+ # See https://www.getdrip.com/docs/rest-api#fdelete_subscriber
144
+ def unsubscribe_from_all(id_or_email)
145
+ post "#{account_id}/subscribers/#{CGI.escape id_or_email}/unsubscribe_all"
146
+ end
125
147
  end
126
148
  end
127
149
  end
@@ -0,0 +1,59 @@
1
+ module Drip
2
+ class Client
3
+ module Webhooks
4
+ # Public: List all webhooks.
5
+ #
6
+ # Returns a Drip::Response.
7
+ # See https://www.getdrip.com/docs/rest-api#webhooks
8
+ def webhooks
9
+ get "#{account_id}/webhooks"
10
+ end
11
+
12
+ # Public: Fetch a webhook
13
+ # id - Required. The String id of the webhook
14
+ #
15
+ # Returns a Drip::Response.
16
+ # See https://www.getdrip.com/docs/rest-api#webhooks
17
+ def webhook(id)
18
+ get "#{account_id}/webhooks/#{id}"
19
+ end
20
+
21
+ # Public: Create a webhook.
22
+ #
23
+ # post_url - Required. The String url that the webhook will post to.
24
+ # include_received_email - Optional. A Boolean specifying whether we should send a
25
+ # notification whenever a subscriber receives an email.
26
+ # Defaults to false.
27
+ # events - Optional. An Array of which events we should send
28
+ # notifications for. Eligible events can be found in the
29
+ # webhooks documentation here: https://www.getdrip.com/docs/webhooks#events.
30
+ # By default, we will send notifications for all events except
31
+ # `subscrber.received_email`.
32
+ #
33
+ # Returns a Drip::Response
34
+ # See https://www.getdrip.com/docs/rest-api#subscriber_batches
35
+ def create_webhook(post_url, include_received_email, events)
36
+ include_received_email = include_received_email ? true : false
37
+ url = "#{account_id}/webhooks"
38
+
39
+ post url, generate_resource(
40
+ "webhooks",
41
+ {
42
+ "post_url" => post_url,
43
+ "include_received_email" => include_received_email,
44
+ "events" => events
45
+ }
46
+ )
47
+ end
48
+
49
+ # Public: List all webhooks.
50
+ # id - Required. The String id of the webhook
51
+ #
52
+ # Returns a Drip::Response.
53
+ # See https://www.getdrip.com/docs/rest-api#webhooks
54
+ def delete_webhook(id)
55
+ delete "#{account_id}/webhooks/#{id}"
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,44 @@
1
+ module Drip
2
+ class Client
3
+ module WorkflowTriggers
4
+ # Public: List all workflow triggers.
5
+ # id - Required. The String id of the workflow
6
+ #
7
+ # Returns a Drip::Response.
8
+ # See https://www.getdrip.com/docs/rest-api#workflow_triggers
9
+ def workflow_triggers(id)
10
+ get "#{account_id}/workflows/#{id}/triggers"
11
+ end
12
+
13
+ # Public: Create a workflow trigger.
14
+ # id - Required. The String id of the workflow
15
+ #
16
+ # options - A Hash of options.
17
+ # - provider - Required. Required. A String indicating a provider.
18
+ # - trigger_type - Required. A String indicating the automation
19
+ # trigger type.
20
+ # - properties - Optional. An Object containing properties for the given trigger.
21
+ #
22
+ # Returns a Drip::Response.
23
+ # See https://www.getdrip.com/docs/rest-api#workflows
24
+ def create_workflow_trigger(id, options = {})
25
+ post "#{account_id}/workflows/#{id}/triggers", generate_resource("triggers", options)
26
+ end
27
+
28
+ # Public: Update a workflow trigger.
29
+ # id - Required. The String id of the workflow trigger
30
+ #
31
+ # options - A Hash of options.
32
+ # - provider - Required. Required. A String indicating a provider.
33
+ # - trigger_type - Required. A String indicating the automation
34
+ # trigger type.
35
+ # - properties - Optional. An Object containing properties for the given trigger.
36
+ #
37
+ # Returns a Drip::Response.
38
+ # See https://www.getdrip.com/docs/rest-api#workflows
39
+ def update_workflow_trigger(id, options = {})
40
+ put "#{account_id}/workflows/#{id}/triggers", generate_resource("triggers", options)
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,80 @@
1
+ require "cgi"
2
+
3
+ module Drip
4
+ class Client
5
+ module Workflows
6
+ # Public: List all workflows.
7
+ #
8
+ # options - A Hash of options
9
+ # - status - Optional. Filter by one of the following statuses:
10
+ # draft, active, or paused. Defaults to all.
11
+ #
12
+ # Returns a Drip::Response.
13
+ # See https://www.getdrip.com/docs/rest-api#workflows
14
+ def workflows(options = {})
15
+ get "#{account_id}/workflows", options
16
+ end
17
+
18
+ # Public: Fetch a workflow.
19
+ # id - Required. The String id of the workflow
20
+ #
21
+ # Returns a Drip::Response.
22
+ # See https://www.getdrip.com/docs/rest-api#workflows
23
+ def workflow(id)
24
+ get "#{account_id}/workflows/#{id}"
25
+ end
26
+
27
+ # Public: Activate a workflow.
28
+ # id - Required. The String id of the workflow
29
+ #
30
+ # Returns a Drip::Response.
31
+ # See https://www.getdrip.com/docs/rest-api#workflows
32
+ def activate_workflow(id)
33
+ post "#{account_id}/workflows/#{id}/activate"
34
+ end
35
+
36
+ # Public: Pause a workflow.
37
+ # id - Required. The String id of the workflow
38
+ #
39
+ # Returns a Drip::Response.
40
+ # See https://www.getdrip.com/docs/rest-api#workflows
41
+ def pause_workflow(id)
42
+ post "#{account_id}/workflows/#{id}/pause"
43
+ end
44
+
45
+ # Public: Start someone on a workflow.
46
+ # id - Required. The String id of the workflow
47
+ #
48
+ # options - A Hash of options.
49
+ # - email - Optional. A new email address for the subscriber.
50
+ # If provided and a subscriber with the email above
51
+ # does not exist, this address will be used to
52
+ # create a new subscriber.
53
+ # - id - Optional. The subscriber's Drip id. Either email or id must be included.
54
+ # - user_id - Optional. A unique identifier for the user in your database,
55
+ # such as a primary key.
56
+ # - time_zone - Optional. The subscriber's time zone (in Olson
57
+ # format). Defaults to Etc/UTC.
58
+ # - custom_fields - Optional. A Hash of custom field data.
59
+ # - tags - Optional. An Array of tags.
60
+ # - prospect - Optional. A Boolean specifiying whether we should attach a lead
61
+ # score to the subscriber (when lead scoring is enabled). Defaults to true
62
+ #
63
+ # Returns a Drip::Response.
64
+ # See https://www.getdrip.com/docs/rest-api#workflows
65
+ def start_subscriber_workflow(id, options = {})
66
+ post "#{account_id}/workflows/#{id}/subscribers", generate_resource("subscribers", options)
67
+ end
68
+
69
+ # Public: Remove someone from a workflow.
70
+ # id - Required. The String id of the workflow
71
+ # id_or_email - Required. The String id or email address of the subscriber.
72
+ #
73
+ # Returns a Drip::Response.
74
+ # See https://www.getdrip.com/docs/rest-api#workflows
75
+ def remove_subscriber_workflow(workflow_id, id_or_email)
76
+ delete "#{account_id}/workflows/#{workflow_id}/subscribers/#{CGI.escape id_or_email}"
77
+ end
78
+ end
79
+ end
80
+ end
@@ -1,23 +1,35 @@
1
1
  require "drip/collections/accounts"
2
- require "drip/collections/subscribers"
3
- require "drip/collections/tags"
2
+ require "drip/collections/broadcasts"
3
+ require "drip/collections/campaigns"
4
+ require "drip/collections/campaign_subscriptions"
4
5
  require "drip/collections/errors"
5
6
  require "drip/collections/purchases"
7
+ require "drip/collections/subscribers"
8
+ require "drip/collections/tags"
9
+ require "drip/collections/webhooks"
10
+ require "drip/collections/workflows"
11
+ require "drip/collections/workflow_triggers"
6
12
 
7
13
  module Drip
8
14
  module Collections
9
15
  def self.classes
10
16
  [
11
17
  Drip::Accounts,
12
- Drip::Subscribers,
18
+ Drip::Broadcasts,
19
+ Drip::Campaigns,
20
+ Drip::CampaignSubscriptions,
13
21
  Drip::Errors,
22
+ Drip::Purchases,
23
+ Drip::Subscribers,
14
24
  Drip::Tags,
15
- Drip::Purchases
25
+ Drip::Webhooks,
26
+ Drip::Workflows,
27
+ Drip::WorkflowTriggers
16
28
  ]
17
29
  end
18
30
 
19
31
  def self.find_class(name)
20
- self.classes.find { |c| c.collection_name == name } || Drip::Collection
32
+ classes.find { |c| c.collection_name == name } || Drip::Collection
21
33
  end
22
34
  end
23
35
  end