Skip to content

Commit a677fc6

Browse files
authored
Merge pull request #51 from DripEmail/update-subscriber-using-drip-id
Update subscriber using Drip ID
2 parents 849392f + 04e8d7e commit a677fc6

5 files changed

Lines changed: 28 additions & 10 deletions

File tree

.rubocop.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,7 @@ Layout/MultilineOperationIndentation:
2828

2929
Layout/MultilineMethodCallIndentation:
3030
EnforcedStyle: 'indented'
31+
32+
Metrics/ClassLength:
33+
Exclude:
34+
- 'test/**/*'

.rubocop_todo.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ Metrics/AbcSize:
2323
Metrics/BlockLength:
2424
Max: 46
2525

26-
# Offense count: 3
27-
# Configuration parameters: CountComments.
28-
Metrics/ClassLength:
29-
Max: 173
30-
3126
# Offense count: 4
3227
# Configuration parameters: CountComments.
3328
Metrics/MethodLength:

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## [Unreleased]
88

9-
[master]: https://github.com/DripEmail/drip-ruby/compare/v3.0.0...HEAD
9+
[master]: https://github.com/DripEmail/drip-ruby/compare/v3.1.1...HEAD
1010

11+
- Allow `#create_or_update_subscriber` to work with Drip id. Fixes [#50](https://github.com/DripEmail/drip-ruby/issues/50)
1112
- Your contribution here!
1213

1314
## [3.1.1] - 2018-06-06

lib/drip/client/subscribers.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ def subscriber(id_or_email)
3131

3232
# Public: Create or update a subscriber.
3333
#
34-
# email - Required. The String subscriber email address.
34+
# email - Optional. The String subscriber email address. (Deprecated in favor of a hash argument)
3535
# options - A Hash of options.
36+
# - email - Required (or id). Lookup the subscriber by email.
37+
# - id - Required (or email). Lookup the subscriber by Drip ID.
3638
# - new_email - Optional. A new email address for the subscriber.
3739
# If provided and a subscriber with the email above
3840
# does not exist, this address will be used to
@@ -44,8 +46,11 @@ def subscriber(id_or_email)
4446
#
4547
# Returns a Drip::Response.
4648
# See https://www.getdrip.com/docs/rest-api#create_or_update_subscriber
47-
def create_or_update_subscriber(email, options = {})
48-
data = options.merge(email: email)
49+
def create_or_update_subscriber(*args)
50+
data = {}
51+
data[:email] = args[0] if args[0].is_a? String
52+
data.merge!(args.last) if args.last.is_a? Hash
53+
raise ArgumentError, 'email: or id: parameter required' if !data.key?(:email) && !data.key?(:id)
4954
post "#{account_id}/subscribers", generate_resource("subscribers", data)
5055
end
5156

test/drip/client/subscribers_test.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,22 @@ def setup
6565
to_return(status: @response_status, body: @response_body, headers: {})
6666
end
6767

68-
should "send the right request" do
68+
should "allow request with legacy email argument" do
6969
expected = Drip::Response.new(@response_status, JSON.parse(@response_body))
7070
assert_equal expected, @client.create_or_update_subscriber(@email, @data)
71+
assert_requested :post, "https://api.getdrip.com/v2/12345/subscribers", body: '{"subscribers":[{"email":"derrick@getdrip.com","time_zone":"America/Los_Angeles"}]}', times: 1
72+
end
73+
74+
should "allow request with email keyword argument" do
75+
expected = Drip::Response.new(@response_status, JSON.parse(@response_body))
76+
assert_equal expected, @client.create_or_update_subscriber(email: @email)
77+
assert_requested :post, "https://api.getdrip.com/v2/12345/subscribers", body: '{"subscribers":[{"email":"derrick@getdrip.com"}]}', times: 1
78+
end
79+
80+
should "allow request with drip id keyword argument" do
81+
expected = Drip::Response.new(@response_status, JSON.parse(@response_body))
82+
assert_equal expected, @client.create_or_update_subscriber(id: 123456)
83+
assert_requested :post, "https://api.getdrip.com/v2/12345/subscribers", body: '{"subscribers":[{"id":123456}]}', times: 1
7184
end
7285
end
7386

0 commit comments

Comments
 (0)