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.
- checksums.yaml +5 -5
- data/.github/pull_request_template.md +39 -0
- data/.rubocop.yml +5 -1
- data/.rubocop_todo.yml +17 -9
- data/.travis.yml +2 -4
- data/CHANGELOG.md +51 -1
- data/Gemfile +12 -0
- data/README.md +6 -0
- data/Rakefile +2 -0
- data/drip-ruby.gemspec +4 -11
- data/lib/drip.rb +2 -0
- data/lib/drip/client.rb +48 -66
- data/lib/drip/client/accounts.rb +4 -2
- data/lib/drip/client/broadcasts.rb +4 -2
- data/lib/drip/client/campaign_subscriptions.rb +3 -1
- data/lib/drip/client/campaigns.rb +7 -5
- data/lib/drip/client/configuration.rb +30 -0
- data/lib/drip/client/conversions.rb +4 -2
- data/lib/drip/client/custom_fields.rb +3 -1
- data/lib/drip/client/events.rb +6 -4
- data/lib/drip/client/forms.rb +4 -2
- data/lib/drip/client/http_client.rb +66 -0
- data/lib/drip/client/orders.rb +5 -3
- data/lib/drip/client/shopper_activity.rb +80 -0
- data/lib/drip/client/subscribers.rb +30 -16
- data/lib/drip/client/tags.rb +5 -3
- data/lib/drip/client/users.rb +17 -0
- data/lib/drip/client/webhooks.rb +7 -5
- data/lib/drip/client/workflow_triggers.rb +5 -3
- data/lib/drip/client/workflows.rb +8 -6
- data/lib/drip/collection.rb +2 -0
- data/lib/drip/collections.rb +2 -0
- data/lib/drip/collections/accounts.rb +2 -0
- data/lib/drip/collections/broadcasts.rb +2 -0
- data/lib/drip/collections/campaign_subscriptions.rb +2 -0
- data/lib/drip/collections/campaigns.rb +2 -0
- data/lib/drip/collections/errors.rb +2 -0
- data/lib/drip/collections/orders.rb +2 -0
- data/lib/drip/collections/purchases.rb +2 -0
- data/lib/drip/collections/subscribers.rb +2 -0
- data/lib/drip/collections/tags.rb +2 -0
- data/lib/drip/collections/webhooks.rb +2 -0
- data/lib/drip/collections/workflow_triggers.rb +2 -0
- data/lib/drip/collections/workflows.rb +2 -0
- data/lib/drip/errors.rb +2 -0
- data/lib/drip/request.rb +33 -0
- data/lib/drip/resource.rb +2 -0
- data/lib/drip/resources.rb +2 -0
- data/lib/drip/resources/account.rb +2 -0
- data/lib/drip/resources/broadcast.rb +2 -0
- data/lib/drip/resources/campaign.rb +2 -0
- data/lib/drip/resources/campaign_subscription.rb +2 -0
- data/lib/drip/resources/error.rb +2 -0
- data/lib/drip/resources/order.rb +2 -0
- data/lib/drip/resources/purchase.rb +2 -0
- data/lib/drip/resources/subscriber.rb +2 -0
- data/lib/drip/resources/tag.rb +2 -0
- data/lib/drip/resources/webhook.rb +2 -0
- data/lib/drip/resources/workflow.rb +2 -0
- data/lib/drip/resources/workflow_trigger.rb +2 -0
- data/lib/drip/response.rb +15 -13
- data/lib/drip/version.rb +3 -1
- data/test/drip/client/accounts_test.rb +2 -0
- data/test/drip/client/broadcasts_test.rb +2 -0
- data/test/drip/client/campaign_subscriptions_test.rb +2 -0
- data/test/drip/client/campaigns_test.rb +2 -0
- data/test/drip/client/configuration_test.rb +112 -0
- data/test/drip/client/conversions_test.rb +2 -0
- data/test/drip/client/custom_fields_test.rb +2 -0
- data/test/drip/client/events_test.rb +2 -0
- data/test/drip/client/forms_test.rb +2 -0
- data/test/drip/client/http_client_test.rb +98 -0
- data/test/drip/client/orders_test.rb +2 -0
- data/test/drip/client/shopper_activity_test.rb +189 -0
- data/test/drip/client/subscribers_test.rb +8 -0
- data/test/drip/client/tags_test.rb +2 -0
- data/test/drip/client/users_test.rb +24 -0
- data/test/drip/client/webhooks_test.rb +2 -0
- data/test/drip/client/workflow_triggers_test.rb +2 -0
- data/test/drip/client/workflows_test.rb +2 -0
- data/test/drip/client_test.rb +34 -97
- data/test/drip/collection_test.rb +16 -0
- data/test/drip/collections/account_test.rb +10 -0
- data/test/drip/collections/broadcasts_test.rb +10 -0
- data/test/drip/collections/campaign_subscriptions_test.rb +10 -0
- data/test/drip/collections/campaigns_test.rb +10 -0
- data/test/drip/collections/errors_test.rb +10 -0
- data/test/drip/collections/orders_test.rb +10 -0
- data/test/drip/collections/purchases_test.rb +10 -0
- data/test/drip/collections/tags_test.rb +10 -0
- data/test/drip/collections/webhooks_test.rb +10 -0
- data/test/drip/collections/workflow_triggers_test.rb +10 -0
- data/test/drip/collections/workflows_test.rb +10 -0
- data/test/drip/collections_test.rb +2 -0
- data/test/drip/request_test.rb +60 -0
- data/test/drip/resource_test.rb +14 -0
- data/test/drip/resources/account_test.rb +2 -0
- data/test/drip/resources/order_test.rb +2 -0
- data/test/drip/resources/subscriber_test.rb +2 -0
- data/test/drip/resources/tag_test.rb +15 -0
- data/test/drip/resources_test.rb +2 -0
- data/test/drip/response_test.rb +35 -0
- data/test/test_helper.rb +5 -0
- metadata +50 -109
data/lib/drip/client/accounts.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Drip
|
|
2
4
|
class Client
|
|
3
5
|
module Accounts
|
|
@@ -6,7 +8,7 @@ module Drip
|
|
|
6
8
|
# Returns a Drip::Response.
|
|
7
9
|
# See https://www.getdrip.com/docs/rest-api#accounts
|
|
8
10
|
def accounts
|
|
9
|
-
get "accounts"
|
|
11
|
+
make_json_api_request :get, "v2/accounts"
|
|
10
12
|
end
|
|
11
13
|
|
|
12
14
|
# Public: Fetch an account.
|
|
@@ -16,7 +18,7 @@ module Drip
|
|
|
16
18
|
# Returns a Drip::Response.
|
|
17
19
|
# See https://www.getdrip.com/docs/rest-api#accounts
|
|
18
20
|
def account(id)
|
|
19
|
-
get "accounts/#{id}"
|
|
21
|
+
make_json_api_request :get, "v2/accounts/#{id}"
|
|
20
22
|
end
|
|
21
23
|
end
|
|
22
24
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Drip
|
|
2
4
|
class Client
|
|
3
5
|
module Broadcasts
|
|
@@ -12,7 +14,7 @@ module Drip
|
|
|
12
14
|
# Returns a Drip::Response
|
|
13
15
|
# See https://www.getdrip.com/docs/rest-api#broadcasts
|
|
14
16
|
def broadcasts(options = {})
|
|
15
|
-
get "
|
|
17
|
+
make_json_api_request :get, "v2/#{account_id}/broadcasts", options
|
|
16
18
|
end
|
|
17
19
|
|
|
18
20
|
# Public: Fetch a broadcast.
|
|
@@ -22,7 +24,7 @@ module Drip
|
|
|
22
24
|
# Returns a Drip::Response.
|
|
23
25
|
# See https://www.getdrip.com/docs/rest-api#broadcasts
|
|
24
26
|
def broadcast(id)
|
|
25
|
-
get "
|
|
27
|
+
make_json_api_request :get, "v2/#{account_id}/broadcasts/#{id}"
|
|
26
28
|
end
|
|
27
29
|
end
|
|
28
30
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Drip
|
|
2
4
|
class Client
|
|
3
5
|
module CampaignSubscriptions
|
|
@@ -8,7 +10,7 @@ module Drip
|
|
|
8
10
|
# Returns a Drip::Response.
|
|
9
11
|
# See https://www.getdrip.com/docs.rest-api#campaign_subscriptions
|
|
10
12
|
def campaign_subscriptions(subscriber_id)
|
|
11
|
-
get "
|
|
13
|
+
make_json_api_request :get, "v2/#{account_id}/subscribers/#{subscriber_id}/campaign_subscriptions"
|
|
12
14
|
end
|
|
13
15
|
end
|
|
14
16
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Drip
|
|
2
4
|
class Client
|
|
3
5
|
module Campaigns
|
|
@@ -14,7 +16,7 @@ module Drip
|
|
|
14
16
|
# Returns a Drip::Response.
|
|
15
17
|
# See https://www.getdrip.com/docs.rest-api#campaigns
|
|
16
18
|
def campaigns(options = {})
|
|
17
|
-
get "
|
|
19
|
+
make_json_api_request :get, "v2/#{account_id}/campaigns", options
|
|
18
20
|
end
|
|
19
21
|
|
|
20
22
|
# Public: Fetch a campaign.
|
|
@@ -24,7 +26,7 @@ module Drip
|
|
|
24
26
|
# Returns a Drip::Response.
|
|
25
27
|
# See https://www.getdrip.com/docs/rest-api#campaigns
|
|
26
28
|
def campaign(id)
|
|
27
|
-
get "
|
|
29
|
+
make_json_api_request :get, "v2/#{account_id}/campaigns/#{id}"
|
|
28
30
|
end
|
|
29
31
|
|
|
30
32
|
# Public: Activate a campaign.
|
|
@@ -34,7 +36,7 @@ module Drip
|
|
|
34
36
|
# Returns a Drip::Response.
|
|
35
37
|
# See https://www.getdrip.com/docs/rest-api#campaigns
|
|
36
38
|
def activate_campaign(id)
|
|
37
|
-
post "
|
|
39
|
+
make_json_api_request :post, "v2/#{account_id}/campaigns/#{id}/activate"
|
|
38
40
|
end
|
|
39
41
|
|
|
40
42
|
# Public: Pause a campaign.
|
|
@@ -44,7 +46,7 @@ module Drip
|
|
|
44
46
|
# Returns a Drip::Response.
|
|
45
47
|
# See https://www.getdrip.com/docs/rest-api#campaigns
|
|
46
48
|
def pause_campaign(id)
|
|
47
|
-
post "
|
|
49
|
+
make_json_api_request :post, "v2/#{account_id}/campaigns/#{id}/pause"
|
|
48
50
|
end
|
|
49
51
|
|
|
50
52
|
# Public: List everyone subscribed to a campaign.
|
|
@@ -68,7 +70,7 @@ module Drip
|
|
|
68
70
|
# Returns a Drip::Response.
|
|
69
71
|
# See https://www.getdrip.com/docs/rest-api#campaigns
|
|
70
72
|
def campaign_subscribers(id, options = {})
|
|
71
|
-
get "
|
|
73
|
+
make_json_api_request :get, "v2/#{account_id}/campaigns/#{id}/subscribers", options
|
|
72
74
|
end
|
|
73
75
|
end
|
|
74
76
|
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Drip
|
|
4
|
+
class Client
|
|
5
|
+
class Configuration
|
|
6
|
+
DEFAULT_URL_PREFIX = "https://api.getdrip.com/"
|
|
7
|
+
private_constant :DEFAULT_URL_PREFIX
|
|
8
|
+
|
|
9
|
+
CONFIGURATION_FIELDS = %i[access_token api_key account_id url_prefix http_open_timeout http_timeout].freeze
|
|
10
|
+
|
|
11
|
+
attr_accessor(*CONFIGURATION_FIELDS)
|
|
12
|
+
|
|
13
|
+
def initialize(**options)
|
|
14
|
+
remainder = options.keys - CONFIGURATION_FIELDS
|
|
15
|
+
raise ArgumentError, "unknown keyword#{'s' if remainder.size > 1}: #{remainder.join(', ')}" unless remainder.empty?
|
|
16
|
+
|
|
17
|
+
# Initialize this variable to suppress Ruby warning.
|
|
18
|
+
@url_prefix = nil
|
|
19
|
+
|
|
20
|
+
options.each do |k, v|
|
|
21
|
+
public_send("#{k}=", v)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def url_prefix
|
|
26
|
+
@url_prefix || DEFAULT_URL_PREFIX
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Drip
|
|
2
4
|
class Client
|
|
3
5
|
module Conversions
|
|
@@ -10,7 +12,7 @@ module Drip
|
|
|
10
12
|
# Returns a Drip::Response.
|
|
11
13
|
# See https://www.getdrip.com/docs/rest-api#conversions
|
|
12
14
|
def conversions(options = {})
|
|
13
|
-
get "
|
|
15
|
+
make_json_api_request :get, "v2/#{account_id}/goals", options
|
|
14
16
|
end
|
|
15
17
|
|
|
16
18
|
# Public: Fetch a conversion.
|
|
@@ -20,7 +22,7 @@ module Drip
|
|
|
20
22
|
# Returns a Drip::Response.
|
|
21
23
|
# See https://www.getdrip.com/docs/rest-api#conversions
|
|
22
24
|
def conversion(id)
|
|
23
|
-
get "
|
|
25
|
+
make_json_api_request :get, "v2/#{account_id}/goals/#{id}"
|
|
24
26
|
end
|
|
25
27
|
end
|
|
26
28
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Drip
|
|
2
4
|
class Client
|
|
3
5
|
module CustomFields
|
|
@@ -6,7 +8,7 @@ module Drip
|
|
|
6
8
|
# Returns a Drip::Response.
|
|
7
9
|
# See https://www.getdrip.com/docs/rest-api#custom_fields
|
|
8
10
|
def custom_fields
|
|
9
|
-
get "
|
|
11
|
+
make_json_api_request :get, "v2/#{account_id}/custom_field_identifiers"
|
|
10
12
|
end
|
|
11
13
|
end
|
|
12
14
|
end
|
data/lib/drip/client/events.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Drip
|
|
2
4
|
class Client
|
|
3
5
|
module Events
|
|
@@ -14,7 +16,7 @@ module Drip
|
|
|
14
16
|
# See https://www.getdrip.com/docs/rest-api#record_event
|
|
15
17
|
def track_event(email, action, properties = {}, options = {})
|
|
16
18
|
data = options.merge({ "email" => email, "action" => action, "properties" => properties })
|
|
17
|
-
post "
|
|
19
|
+
make_json_api_request :post, "v2/#{account_id}/events", private_generate_resource("events", data)
|
|
18
20
|
end
|
|
19
21
|
|
|
20
22
|
# Public: Track a collection of events all at once.
|
|
@@ -27,8 +29,8 @@ module Drip
|
|
|
27
29
|
# Returns a Drip::Response.
|
|
28
30
|
# See https://www.getdrip.com/docs/rest-api#event_batches
|
|
29
31
|
def track_events(events)
|
|
30
|
-
url = "
|
|
31
|
-
post url,
|
|
32
|
+
url = "v2/#{account_id}/events/batches"
|
|
33
|
+
make_json_api_request :post, url, private_generate_resource("batches", { "events" => events })
|
|
32
34
|
end
|
|
33
35
|
|
|
34
36
|
# Public: Fetch all custom event actions.
|
|
@@ -41,7 +43,7 @@ module Drip
|
|
|
41
43
|
# Returns a Drip::Response.
|
|
42
44
|
# See https://www.getdrip.com/docs/rest-api#events
|
|
43
45
|
def event_actions(options = {})
|
|
44
|
-
get "
|
|
46
|
+
make_json_api_request :get, "v2/#{account_id}/event_actions", options
|
|
45
47
|
end
|
|
46
48
|
end
|
|
47
49
|
end
|
data/lib/drip/client/forms.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Drip
|
|
2
4
|
class Client
|
|
3
5
|
module Forms
|
|
@@ -6,7 +8,7 @@ module Drip
|
|
|
6
8
|
# Returns a Drip::Response.
|
|
7
9
|
# See https://www.getdrip.com/docs/rest-api#forms
|
|
8
10
|
def forms
|
|
9
|
-
get "
|
|
11
|
+
make_json_api_request :get, "v2/#{account_id}/forms"
|
|
10
12
|
end
|
|
11
13
|
|
|
12
14
|
# Public: Fetch a form.
|
|
@@ -16,7 +18,7 @@ module Drip
|
|
|
16
18
|
# Returns a Drip::Response.
|
|
17
19
|
# See https://www.getdrip.com/docs/rest-api#forms
|
|
18
20
|
def form(id)
|
|
19
|
-
get "
|
|
21
|
+
make_json_api_request :get, "v2/#{account_id}/forms/#{id}"
|
|
20
22
|
end
|
|
21
23
|
end
|
|
22
24
|
end
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Drip
|
|
4
|
+
class Client
|
|
5
|
+
class HTTPClient
|
|
6
|
+
REDIRECT_LIMIT = 10
|
|
7
|
+
private_constant :REDIRECT_LIMIT
|
|
8
|
+
|
|
9
|
+
def initialize(config)
|
|
10
|
+
@config = config
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def make_request(drip_request, redirected_url: nil, step: 0)
|
|
14
|
+
raise TooManyRedirectsError, 'too many HTTP redirects' if step >= REDIRECT_LIMIT
|
|
15
|
+
|
|
16
|
+
uri = redirected_url || drip_request.url.tap do |orig_url|
|
|
17
|
+
next if drip_request.http_verb != :get
|
|
18
|
+
|
|
19
|
+
orig_url.query = URI.encode_www_form(drip_request.options)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
response = Net::HTTP.start(uri.host, uri.port, connection_options(uri.scheme)) do |http|
|
|
23
|
+
request = drip_request.verb_klass.new uri
|
|
24
|
+
request.body = drip_request.body
|
|
25
|
+
|
|
26
|
+
add_standard_headers(request)
|
|
27
|
+
request['Content-Type'] = drip_request.content_type
|
|
28
|
+
|
|
29
|
+
http.request request
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
return make_request(drip_request, redirected_url: URI(response["Location"]), step: step + 1) if response.is_a?(Net::HTTPRedirection)
|
|
33
|
+
|
|
34
|
+
response
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
private
|
|
38
|
+
|
|
39
|
+
def add_standard_headers(request)
|
|
40
|
+
request['User-Agent'] = "Drip Ruby v#{Drip::VERSION}"
|
|
41
|
+
request['Accept'] = "*/*"
|
|
42
|
+
|
|
43
|
+
if @config.access_token
|
|
44
|
+
request['Authorization'] = "Bearer #{@config.access_token}"
|
|
45
|
+
else
|
|
46
|
+
request.basic_auth @config.api_key, ""
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
request
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def connection_options(uri_scheme)
|
|
53
|
+
options = { use_ssl: uri_scheme == "https" }
|
|
54
|
+
|
|
55
|
+
if @config.http_open_timeout
|
|
56
|
+
options[:open_timeout] = @config.http_open_timeout
|
|
57
|
+
options[:ssl_timeout] = @config.http_open_timeout
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
options[:read_timeout] = @config.http_timeout if @config.http_timeout
|
|
61
|
+
|
|
62
|
+
options
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
data/lib/drip/client/orders.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Drip
|
|
2
4
|
class Client
|
|
3
5
|
module Orders
|
|
@@ -11,7 +13,7 @@ module Drip
|
|
|
11
13
|
# See https://developer.drip.com/#orders
|
|
12
14
|
def create_or_update_order(email, options = {})
|
|
13
15
|
data = options.merge(email: email)
|
|
14
|
-
post "
|
|
16
|
+
make_json_api_request :post, "v2/#{account_id}/orders", private_generate_resource("orders", data)
|
|
15
17
|
end
|
|
16
18
|
|
|
17
19
|
# Public: Create or update a batch of orders.
|
|
@@ -21,7 +23,7 @@ module Drip
|
|
|
21
23
|
# Returns a Drip::Response.
|
|
22
24
|
# See https://developer.drip.com/#create-or-update-a-batch-of-orders
|
|
23
25
|
def create_or_update_orders(orders)
|
|
24
|
-
post "
|
|
26
|
+
make_json_api_request :post, "v2/#{account_id}/orders/batches", private_generate_resource("batches", { "orders" => orders })
|
|
25
27
|
end
|
|
26
28
|
|
|
27
29
|
# Public: Create or update a refund.
|
|
@@ -38,7 +40,7 @@ module Drip
|
|
|
38
40
|
# Returns a Drip::Response.
|
|
39
41
|
# See https://developer.drip.com/#create-or-update-a-refund
|
|
40
42
|
def create_or_update_refund(options)
|
|
41
|
-
post "
|
|
43
|
+
make_json_api_request :post, "v2/#{account_id}/refunds", private_generate_resource("refunds", options)
|
|
42
44
|
end
|
|
43
45
|
end
|
|
44
46
|
end
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Drip
|
|
4
|
+
class Client
|
|
5
|
+
module ShopperActivity
|
|
6
|
+
# Public: Create a cart activity event.
|
|
7
|
+
#
|
|
8
|
+
# options - Required. A Hash of additional cart options. Refer to the
|
|
9
|
+
# Drip API docs for the required schema.
|
|
10
|
+
#
|
|
11
|
+
# Returns a Drip::Response.
|
|
12
|
+
# See https://developer.drip.com/#cart-activity
|
|
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)
|
|
15
|
+
|
|
16
|
+
%i[provider action cart_id cart_url].each do |key|
|
|
17
|
+
raise ArgumentError, "#{key}: parameter required" unless data.key?(key)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
data[:occurred_at] = Time.now.iso8601 unless data.key?(:occurred_at)
|
|
21
|
+
make_json_request :post, "v3/#{account_id}/shopper_activity/cart", data
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Public: Create an order activity event.
|
|
25
|
+
#
|
|
26
|
+
# options - Required. A Hash of additional order options. Refer to the
|
|
27
|
+
# Drip API docs for the required schema.
|
|
28
|
+
#
|
|
29
|
+
# Returns a Drip::Response.
|
|
30
|
+
# See https://developer.drip.com/#order-activity
|
|
31
|
+
def create_order_activity_event(data = {})
|
|
32
|
+
raise ArgumentError, 'email: or person_id: parameter required' if !data.key?(:email) && !data.key?(:person_id)
|
|
33
|
+
|
|
34
|
+
%i[provider action order_id].each do |key|
|
|
35
|
+
raise ArgumentError, "#{key}: parameter required" unless data.key?(key)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
data[:occurred_at] = Time.now.iso8601 unless data.key?(:occurred_at)
|
|
39
|
+
make_json_request :post, "v3/#{account_id}/shopper_activity/order", data
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Public: Create a batch of order activity events.
|
|
43
|
+
#
|
|
44
|
+
# records - Required. An array of hashes containing orders attributes.
|
|
45
|
+
# Refer to the Drip API docs for the required schema.
|
|
46
|
+
#
|
|
47
|
+
# Returns a Drip::Response.
|
|
48
|
+
# See https://developer.drip.com/#create-or-update-a-batch-of-orders
|
|
49
|
+
def create_order_activity_events(records = [])
|
|
50
|
+
records.each_with_index do |record, i|
|
|
51
|
+
raise ArgumentError, "email: or person_id: parameter required in record #{i}" if !record.key?(:email) && !record.key?(:person_id)
|
|
52
|
+
|
|
53
|
+
%i[provider action order_id].each do |key|
|
|
54
|
+
raise ArgumentError, "#{key}: parameter required in record #{i}" unless record.key?(key)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
record[:occurred_at] = Time.now.iso8601 unless record.key?(:occurred_at)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
make_json_request :post, "v3/#{account_id}/shopper_activity/order/batch", { orders: records }
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Public: Create a product activity event.
|
|
64
|
+
#
|
|
65
|
+
# options - Required. A Hash of additional product options. Refer to the
|
|
66
|
+
# Drip API docs for the required schema.
|
|
67
|
+
#
|
|
68
|
+
# Returns a Drip::Response.
|
|
69
|
+
# See https://developer.drip.com/#product-activity
|
|
70
|
+
def create_product_activity_event(data = {})
|
|
71
|
+
%i[provider action product_id name price].each do |key|
|
|
72
|
+
raise ArgumentError, "#{key}: parameter required" unless data.key?(key)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
data[:occurred_at] = Time.now.iso8601 unless data.key?(:occurred_at)
|
|
76
|
+
make_json_request :post, "v3/#{account_id}/shopper_activity/product", data
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "cgi"
|
|
2
4
|
|
|
3
5
|
module Drip
|
|
@@ -16,7 +18,7 @@ module Drip
|
|
|
16
18
|
# Returns a Drip::Response.
|
|
17
19
|
# See https://www.getdrip.com/docs/rest-api#list_subscribers
|
|
18
20
|
def subscribers(options = {})
|
|
19
|
-
get "
|
|
21
|
+
make_json_api_request :get, "v2/#{account_id}/subscribers", options
|
|
20
22
|
end
|
|
21
23
|
|
|
22
24
|
# Public: Fetch a subscriber.
|
|
@@ -26,15 +28,17 @@ module Drip
|
|
|
26
28
|
# Returns a Drip::Response.
|
|
27
29
|
# See https://www.getdrip.com/docs/rest-api#fetch_subscriber
|
|
28
30
|
def subscriber(id_or_email)
|
|
29
|
-
get "
|
|
31
|
+
make_json_api_request :get, "v2/#{account_id}/subscribers/#{CGI.escape id_or_email}"
|
|
30
32
|
end
|
|
31
33
|
|
|
32
34
|
# Public: Create or update a subscriber.
|
|
33
35
|
#
|
|
34
36
|
# email - Optional. The String subscriber email address. (Deprecated in favor of a hash argument)
|
|
35
37
|
# options - A Hash of options.
|
|
36
|
-
# - email - Required (or id
|
|
37
|
-
#
|
|
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.
|
|
38
42
|
# - new_email - Optional. A new email address for the subscriber.
|
|
39
43
|
# If provided and a subscriber with the email above
|
|
40
44
|
# does not exist, this address will be used to
|
|
@@ -43,6 +47,9 @@ module Drip
|
|
|
43
47
|
# format). Defaults to Etc/UTC.
|
|
44
48
|
# - custom_fields - Optional. A Hash of custom field data.
|
|
45
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.
|
|
46
53
|
#
|
|
47
54
|
# Returns a Drip::Response.
|
|
48
55
|
# See https://www.getdrip.com/docs/rest-api#create_or_update_subscriber
|
|
@@ -50,8 +57,8 @@ module Drip
|
|
|
50
57
|
data = {}
|
|
51
58
|
data[:email] = args[0] if args[0].is_a? String
|
|
52
59
|
data.merge!(args.last) if args.last.is_a? Hash
|
|
53
|
-
raise ArgumentError, 'email: or id: parameter required' if
|
|
54
|
-
post "
|
|
60
|
+
raise ArgumentError, 'email: or id: or bigcommerce_subscriber_id: parameter required' if missing_subscriber_identifier(data)
|
|
61
|
+
make_json_api_request :post, "v2/#{account_id}/subscribers", private_generate_resource("subscribers", data)
|
|
55
62
|
end
|
|
56
63
|
|
|
57
64
|
# Public: Create or update a collection of subscribers.
|
|
@@ -70,8 +77,8 @@ module Drip
|
|
|
70
77
|
# Returns a Drip::Response
|
|
71
78
|
# See https://www.getdrip.com/docs/rest-api#subscriber_batches
|
|
72
79
|
def create_or_update_subscribers(subscribers)
|
|
73
|
-
url = "
|
|
74
|
-
post url,
|
|
80
|
+
url = "v2/#{account_id}/subscribers/batches"
|
|
81
|
+
make_json_api_request :post, url, private_generate_resource("batches", { "subscribers" => subscribers })
|
|
75
82
|
end
|
|
76
83
|
|
|
77
84
|
# Public: Unsubscribe a collection of subscribers.
|
|
@@ -82,8 +89,8 @@ module Drip
|
|
|
82
89
|
# Returns a Drip::Response
|
|
83
90
|
# See https://www.getdrip.com/docs/rest-api#subscriber_batches
|
|
84
91
|
def unsubscribe_subscribers(subscribers)
|
|
85
|
-
url = "
|
|
86
|
-
post url,
|
|
92
|
+
url = "v2/#{account_id}/unsubscribes/batches"
|
|
93
|
+
make_json_api_request :post, url, private_generate_resource("batches", { "subscribers" => subscribers })
|
|
87
94
|
end
|
|
88
95
|
|
|
89
96
|
# Public: Unsubscribe a subscriber globally or from a specific campaign.
|
|
@@ -96,9 +103,9 @@ module Drip
|
|
|
96
103
|
# Returns a Drip::Response.
|
|
97
104
|
# See https://www.getdrip.com/docs/rest-api#unsubscribe
|
|
98
105
|
def unsubscribe(id_or_email, options = {})
|
|
99
|
-
url = "
|
|
106
|
+
url = "v2/#{account_id}/subscribers/#{CGI.escape id_or_email}/remove"
|
|
100
107
|
url += options[:campaign_id] ? "?campaign_id=#{options[:campaign_id]}" : ""
|
|
101
|
-
post url
|
|
108
|
+
make_json_api_request :post, url
|
|
102
109
|
end
|
|
103
110
|
|
|
104
111
|
# Public: Subscribe to a campaign.
|
|
@@ -126,8 +133,8 @@ module Drip
|
|
|
126
133
|
# See https://www.getdrip.com/docs/rest-api#subscribe
|
|
127
134
|
def subscribe(email, campaign_id, options = {})
|
|
128
135
|
data = options.merge("email" => email)
|
|
129
|
-
url = "
|
|
130
|
-
post url,
|
|
136
|
+
url = "v2/#{account_id}/campaigns/#{campaign_id}/subscribers"
|
|
137
|
+
make_json_api_request :post, url, private_generate_resource("subscribers", data)
|
|
131
138
|
end
|
|
132
139
|
|
|
133
140
|
# Public: Delete a subscriber.
|
|
@@ -137,7 +144,7 @@ module Drip
|
|
|
137
144
|
# Returns No Content.
|
|
138
145
|
# See https://www.getdrip.com/docs/rest-api#fdelete_subscriber
|
|
139
146
|
def delete_subscriber(id_or_email)
|
|
140
|
-
delete "
|
|
147
|
+
make_json_api_request :delete, "v2/#{account_id}/subscribers/#{CGI.escape id_or_email}"
|
|
141
148
|
end
|
|
142
149
|
|
|
143
150
|
# Public: Unsubscribe a subscriber from all mailings.
|
|
@@ -147,8 +154,15 @@ module Drip
|
|
|
147
154
|
# Returns No Content.
|
|
148
155
|
# See https://www.getdrip.com/docs/rest-api#fdelete_subscriber
|
|
149
156
|
def unsubscribe_from_all(id_or_email)
|
|
150
|
-
post "
|
|
157
|
+
make_json_api_request :post, "v2/#{account_id}/subscribers/#{CGI.escape id_or_email}/unsubscribe_all"
|
|
151
158
|
end
|
|
152
159
|
end
|
|
160
|
+
|
|
161
|
+
private
|
|
162
|
+
|
|
163
|
+
def missing_subscriber_identifier(data)
|
|
164
|
+
external_ids = data[:external_ids] || {}
|
|
165
|
+
!data.key?(:email) && !data.key?(:id) && !external_ids.key?("bigcommerce_subscriber_id")
|
|
166
|
+
end
|
|
153
167
|
end
|
|
154
168
|
end
|