customerio 4.0.1 → 4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.markdown +4 -0
- data/README.md +15 -0
- data/lib/customerio/client.rb +25 -0
- data/lib/customerio/version.rb +1 -1
- data/spec/client_spec.rb +31 -0
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4effd60709e999b2530ceb0cdbd5125a163543d5f842657d13bb57b4cf10b92
|
4
|
+
data.tar.gz: 6cb74d720acb7f4ac284c760cd92aa4a774d5762dd886ee7d68d8cacc42dd677
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8004b7a1062fabdaa46378a5e9f9a14138ca6bd2c45d6cb246636e112207be11cb68b8a561ca9e507b11ff803ffd8e4f1e0765f6cbecac7dc413c36c9e58adcf
|
7
|
+
data.tar.gz: cf8908e63e075e7a6989c777de2d5bb3f538025bfe6820d6c9d58848fea3ebc3f4a3b054ee94799671f71bf3b1b19678fd0f4051373fcf666c64020eb50b239f
|
data/CHANGELOG.markdown
CHANGED
data/README.md
CHANGED
@@ -104,6 +104,21 @@ recreated.
|
|
104
104
|
$customerio.delete(5)
|
105
105
|
```
|
106
106
|
|
107
|
+
### Merge duplicate customer profiles
|
108
|
+
|
109
|
+
When you merge two people, you pick a primary person and merge a secondary, duplicate person into it. The primary person remains after the merge and the secondary is deleted. This process is permanent: you cannot recover the secondary person.
|
110
|
+
|
111
|
+
The first and third parameters represent the identifier for the primary and secondary people respectively—one of `id`, `email`, or `cio_id`. The second and fourth parameters are the identifier values for the primary and secondary people respectively.
|
112
|
+
|
113
|
+
```ruby
|
114
|
+
# $customerio.merge_customers("primaryType", "primaryIdentifier", "secondaryType", "secondaryIdentifier")
|
115
|
+
# primaryType / secondaryType are one of "id", "email", or "cio_id"
|
116
|
+
# primaryIdentifier / secondaryIdentifier are the identifier value corresponding to the type.
|
117
|
+
|
118
|
+
# merge customer "cperson@gmail.com" into "cool.person@company.com"
|
119
|
+
$customerio.merge_customers("email", "cool.person@company.com", "email", "cperson@gmail.com")
|
120
|
+
```
|
121
|
+
|
107
122
|
### Tracking a custom event
|
108
123
|
|
109
124
|
Now that you're identifying your customers with [Customer.io](http://customer.io), you can now send events like
|
data/lib/customerio/client.rb
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
require "addressable/uri"
|
2
2
|
|
3
3
|
module Customerio
|
4
|
+
class IdentifierType
|
5
|
+
ID = "id"
|
6
|
+
EMAIL = "email"
|
7
|
+
CIOID = "cio_id"
|
8
|
+
end
|
9
|
+
|
4
10
|
class Client
|
5
11
|
PUSH_OPENED = 'opened'
|
6
12
|
PUSH_CONVERTED = 'converted'
|
@@ -91,6 +97,17 @@ module Customerio
|
|
91
97
|
@client.request_and_verify_response(:post, track_push_notification_event_path, attributes.merge(event: event_name))
|
92
98
|
end
|
93
99
|
|
100
|
+
def merge_customers(primary_id_type, primary_id, secondary_id_type, secondary_id)
|
101
|
+
raise ParamError.new("invalid primary_id_type") if !is_valid_id_type?(primary_id_type)
|
102
|
+
raise ParamError.new("primary_id must be a non-empty string") if is_empty?(primary_id)
|
103
|
+
raise ParamError.new("invalid secondary_id_type") if !is_valid_id_type?(secondary_id_type)
|
104
|
+
raise ParamError.new("secondary_id must be a non-empty string") if is_empty?(secondary_id)
|
105
|
+
|
106
|
+
body = { :primary => {primary_id_type => primary_id}, :secondary => {secondary_id_type => secondary_id} }
|
107
|
+
|
108
|
+
@client.request_and_verify_response(:post, merge_customers_path, body)
|
109
|
+
end
|
110
|
+
|
94
111
|
private
|
95
112
|
|
96
113
|
def escape(val)
|
@@ -122,6 +139,10 @@ module Customerio
|
|
122
139
|
"/push/events"
|
123
140
|
end
|
124
141
|
|
142
|
+
def merge_customers_path
|
143
|
+
"/api/v1/merge_customers"
|
144
|
+
end
|
145
|
+
|
125
146
|
def create_or_update(attributes = {})
|
126
147
|
attributes = Hash[attributes.map { |(k,v)| [ k.to_sym, v ] }]
|
127
148
|
raise MissingIdAttributeError.new("Must provide a customer id") if is_empty?(attributes[:id])
|
@@ -162,5 +183,9 @@ module Customerio
|
|
162
183
|
def is_empty?(val)
|
163
184
|
val.nil? || (val.is_a?(String) && val.strip == "")
|
164
185
|
end
|
186
|
+
|
187
|
+
def is_valid_id_type?(input)
|
188
|
+
[IdentifierType::ID, IdentifierType::CIOID, IdentifierType::EMAIL].include? input
|
189
|
+
end
|
165
190
|
end
|
166
191
|
end
|
data/lib/customerio/version.rb
CHANGED
data/spec/client_spec.rb
CHANGED
@@ -592,4 +592,35 @@ describe Customerio::Client do
|
|
592
592
|
}.to raise_error(Customerio::Client::ParamError, 'timestamp must be a valid timestamp')
|
593
593
|
end
|
594
594
|
end
|
595
|
+
|
596
|
+
describe "#merge_customers" do
|
597
|
+
before(:each) do
|
598
|
+
@client = Customerio::Client.new("SITE_ID", "API_KEY", :json => true)
|
599
|
+
end
|
600
|
+
|
601
|
+
it "should raise validation errors on merge params" do
|
602
|
+
expect {
|
603
|
+
client.merge_customers("", "id1", Customerio::IdentifierType::ID, "id2")
|
604
|
+
}.to raise_error(Customerio::Client::ParamError, 'invalid primary_id_type')
|
605
|
+
|
606
|
+
expect {
|
607
|
+
client.merge_customers(Customerio::IdentifierType::EMAIL, "", Customerio::IdentifierType::ID, "id2")
|
608
|
+
}.to raise_error(Customerio::Client::ParamError, 'primary_id must be a non-empty string')
|
609
|
+
|
610
|
+
expect {
|
611
|
+
client.merge_customers(Customerio::IdentifierType::CIOID, "id1", "", "id2")
|
612
|
+
}.to raise_error(Customerio::Client::ParamError, 'invalid secondary_id_type')
|
613
|
+
|
614
|
+
expect {
|
615
|
+
client.merge_customers(Customerio::IdentifierType::ID, "id1", Customerio::IdentifierType::ID, "")
|
616
|
+
}.to raise_error(Customerio::Client::ParamError, 'secondary_id must be a non-empty string')
|
617
|
+
end
|
618
|
+
|
619
|
+
it "requires a valid customer_id when creating" do
|
620
|
+
stub_request(:post, api_uri('/api/v1/merge_customers')).
|
621
|
+
to_return(status: 200, body: "", headers: {})
|
622
|
+
|
623
|
+
client.merge_customers(Customerio::IdentifierType::ID, "ID1", Customerio::IdentifierType::EMAIL, "hello@company.com")
|
624
|
+
end
|
625
|
+
end
|
595
626
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: customerio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0
|
4
|
+
version: 4.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Allison
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-09-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|
@@ -125,7 +125,7 @@ homepage: http://customer.io
|
|
125
125
|
licenses:
|
126
126
|
- MIT
|
127
127
|
metadata: {}
|
128
|
-
post_install_message:
|
128
|
+
post_install_message:
|
129
129
|
rdoc_options: []
|
130
130
|
require_paths:
|
131
131
|
- lib
|
@@ -140,8 +140,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
140
|
- !ruby/object:Gem::Version
|
141
141
|
version: '0'
|
142
142
|
requirements: []
|
143
|
-
rubygems_version: 3.
|
144
|
-
signing_key:
|
143
|
+
rubygems_version: 3.2.22
|
144
|
+
signing_key:
|
145
145
|
specification_version: 4
|
146
146
|
summary: A ruby client for the Customer.io event API.
|
147
147
|
test_files:
|