customerio 3.0.0 → 3.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bd807525a01387116c22f29d0ac98e9b783fe669fd092da9d97cac74a660316d
4
- data.tar.gz: 0ff5f3b518f07d5e3432a69e4a5738fd5bdeabc359593960bf9ac8f46081a7fc
3
+ metadata.gz: 48f0d7c8bb61994c6bee0e1b846772f7ab304913182a1d1ac87f52a6e4e9beff
4
+ data.tar.gz: e8df14b0db35439d08687a2ff61161d5d6bfc3a9f8ae6df71ba9c1cd7d4c91e9
5
5
  SHA512:
6
- metadata.gz: 07a1b0e3472abe674a69413e81e6cf2b87c5002a3b074a26053efc0b8da2e7d91d380055c54409922d35ff2d876aeb22c956ce1ea246842ec1ce08ad3079f35b
7
- data.tar.gz: eb291aab81e6e802a204d7c0b2d36890fa2ce26cf82c3af773a8cfddcacdc9b0d4fca7c684aee03a884bafdda4ac088c234294d197fe28041bae2573b186a1da
6
+ metadata.gz: 7fff0a46a46e90a65f39694abf8713abe1a5e9edd0f388d26fea80d305332ed8425998397822899a9b66f27e77fb98e1051cd332842c73cd20da0a7ad7380a9d
7
+ data.tar.gz: 1eab0fb3fe94024954b04f77c34029aa2b9a9b6a089d5d6aa86f9070101e0bf13e7019725e8031fcdd7af0ddf76532e4b2b85b6dfe7e482ecb5f407b339df381
@@ -0,0 +1,30 @@
1
+ name: ruby_ci
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ build:
7
+ strategy:
8
+ matrix:
9
+ ruby: ['2.5', '2.6', '2.7']
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v2
13
+ - name: set up ruby
14
+ uses: actions/setup-ruby@v1
15
+ with:
16
+ ruby-version: ${{ matrix.ruby }}
17
+ - name: install bundle
18
+ run: |
19
+ sudo apt-get -yqq install libpq-dev
20
+ gem install bundler
21
+ - name: Cache dependencies
22
+ uses: actions/cache@v2
23
+ with:
24
+ path: vendor/bundle
25
+ key: customerio-${{ matrix.ruby }}-${{ hashFiles('customerio.gemspec') }}
26
+ restore-keys: |
27
+ customerio-${{ matrix.ruby }}-
28
+ - name: Install dependencies
29
+ run: bundle install --path vendor/bundle
30
+ - run: bundle exec rspec
data/CHANGELOG.markdown CHANGED
@@ -1,3 +1,27 @@
1
+
2
+ ## Customerio 3.1.0 - March 25, 2021
3
+ ### Added
4
+ - Support for EU region
5
+
6
+ ### Removed
7
+ ### Changed
8
+ - `Customerio::Client` and `CustomerIO::APIClient` have a new parameter `region` that can be set to either `Customerio::Regions::EU` or `Customerio::Regions::US` (defaults to `Customerio::Regions::US`)
9
+
10
+ ## Customerio 3.0.0 - Dec 2, 2020
11
+
12
+ ### Added
13
+ - Support for the Transactional API
14
+
15
+ ### Removed
16
+ - `add_to_segment` and `remove_from_segment` methods
17
+ - Support for non-JSON data
18
+
19
+ ### Changed
20
+ - IDs in the URLs are now escaped.
21
+ - Improved validations for data that's passed in.
22
+ - Earlier, if you passed in an event name without a customer ID to the `track` method, we would create an anonymous event. That is now removed. To create an anonymous event, use the `anonymous_track` method.
23
+
24
+
1
25
  ## Customerio 3.0.0 - Dec 2, 2020
2
26
 
3
27
  ### Added
data/README.md CHANGED
@@ -42,15 +42,16 @@ You'll be able to integrate **fully** with [Customer.io](http://customer.io) wit
42
42
 
43
43
  ### Setup
44
44
 
45
- Create an instance of the client with your [customer.io](http://customer.io) credentials
46
- which can be found on the [customer.io integration screen](https://fly.customer.io/account/customerio_integration).
45
+ Create an instance of the client with your [Customer.io credentials](https://fly.customer.io/settings/api_credentials).
47
46
 
48
47
  If you're using Rails, create an initializer `config/initializers/customerio.rb`:
49
48
 
50
49
  ```ruby
51
- $customerio = Customerio::Client.new("YOUR SITE ID", "YOUR API SECRET KEY")
50
+ $customerio = Customerio::Client.new("YOUR SITE ID", "YOUR API SECRET KEY", region: Customerio::Regions::US)
52
51
  ```
53
52
 
53
+ `region` is optional and takes one of two values—`US` or `EU`. If you do not specify your region, we assume that your account is based in the US (`US`). If your account is based in the EU and you do not provide the correct region (`EU`), we'll route requests to our EU data centers accordingly, however this may cause data to be logged in the US.
54
+
54
55
  ### Identify logged in customers
55
56
 
56
57
  Tracking data of logged in customers is a key part of [Customer.io](http://customer.io). In order to
@@ -121,7 +122,7 @@ encourage your customers to perform an action.
121
122
  $customerio.track(5, "purchase", :type => "socks", :price => "13.99")
122
123
  ```
123
124
 
124
- **Note:** If you'd like to track events which occurred in the past, you can include a `timestamp` attribute
125
+ **Note:** If you want to track events which occurred in the past, you can include a `timestamp` attribute
125
126
  (in seconds since the epoch), and we'll use that as the date the event occurred.
126
127
 
127
128
  ```ruby
@@ -195,7 +196,7 @@ Use `send_email` referencing your request to send a transactional message. [Lear
195
196
  ```ruby
196
197
  require "customerio"
197
198
 
198
- client = Customerio::APIClient.new("your API key")
199
+ client = Customerio::APIClient.new("your API key", region: Customerio::Regions::US)
199
200
 
200
201
  request = Customerio::SendEmailRequest.new(
201
202
  to: "person@example.com",
data/lib/customerio.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "customerio/version"
2
2
 
3
3
  module Customerio
4
+ require "customerio/regions"
4
5
  require "customerio/base_client"
5
6
  require "customerio/client"
6
7
  require "customerio/requests/send_email_request"
@@ -3,10 +3,11 @@ require 'multi_json'
3
3
 
4
4
  module Customerio
5
5
  class APIClient
6
- DEFAULT_API_URL = 'https://api.customer.io'
7
-
8
6
  def initialize(app_key, options = {})
9
- options[:url] = DEFAULT_API_URL if options[:url].nil? || options[:url].empty?
7
+ options[:region] = Customerio::Regions::US if options[:region].nil?
8
+ raise "region must be an instance of Customerio::Regions::Region" unless options[:region].is_a?(Customerio::Regions::Region)
9
+
10
+ options[:url] = options[:region].api_url if options[:url].nil? || options[:url].empty?
10
11
  @client = Customerio::BaseClient.new({ app_key: app_key }, options)
11
12
  end
12
13
 
@@ -2,13 +2,14 @@ require "addressable/uri"
2
2
 
3
3
  module Customerio
4
4
  class Client
5
- DEFAULT_TRACK_URL = 'https://track.customer.io'
6
-
7
5
  class MissingIdAttributeError < RuntimeError; end
8
6
  class ParamError < RuntimeError; end
9
7
 
10
8
  def initialize(site_id, api_key, options = {})
11
- options[:url] = DEFAULT_TRACK_URL if options[:url].nil? || options[:url].empty?
9
+ options[:region] = Customerio::Regions::US if options[:region].nil?
10
+ raise "region must be an instance of Customerio::Regions::Region" unless options[:region].is_a?(Customerio::Regions::Region)
11
+
12
+ options[:url] = options[:region].track_url if options[:url].nil? || options[:url].empty?
12
13
  @client = Customerio::BaseClient.new({ site_id: site_id, api_key: api_key }, options)
13
14
  end
14
15
 
@@ -0,0 +1,11 @@
1
+ require 'net/http'
2
+ require 'multi_json'
3
+
4
+ module Customerio
5
+ module Regions
6
+ Region = Struct.new(:track_url, :api_url)
7
+
8
+ US = Customerio::Regions::Region.new('https://track.customer.io', 'https://api.customer.io').freeze
9
+ EU = Customerio::Regions::Region.new('https://track-eu.customer.io', 'https://api-eu.customer.io').freeze
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module Customerio
2
- VERSION = "3.0.0"
2
+ VERSION = "3.1.0"
3
3
  end
@@ -21,6 +21,48 @@ describe Customerio::APIClient do
21
21
  MultiJson.dump(data)
22
22
  end
23
23
 
24
+ it "the base client is initialised with the correct values when no region is passed in" do
25
+ app_key = "appkey"
26
+
27
+ expect(Customerio::BaseClient).to(
28
+ receive(:new)
29
+ .with(
30
+ { app_key: app_key },
31
+ {
32
+ region: Customerio::Regions::US,
33
+ url: Customerio::Regions::US.api_url
34
+ }
35
+ )
36
+ )
37
+
38
+ client = Customerio::APIClient.new(app_key)
39
+ end
40
+
41
+ it "raises an error when an incorrect region is passed in" do
42
+ expect {
43
+ Customerio::APIClient.new("appkey", region: :au)
44
+ }.to raise_error /region must be an instance of Customerio::Regions::Region/
45
+ end
46
+
47
+ [Customerio::Regions::US, Customerio::Regions::EU].each do |region|
48
+ it "the base client is initialised with the correct values when the region \"#{region}\" is passed in" do
49
+ app_key = "appkey"
50
+
51
+ expect(Customerio::BaseClient).to(
52
+ receive(:new)
53
+ .with(
54
+ { app_key: app_key },
55
+ {
56
+ region: region,
57
+ url: region.api_url
58
+ }
59
+ )
60
+ )
61
+
62
+ client = Customerio::APIClient.new(app_key, { region: region })
63
+ end
64
+ end
65
+
24
66
  describe "#send_email" do
25
67
  it "sends a POST request to the /api/send/email path" do
26
68
  req = Customerio::SendEmailRequest.new(
data/spec/client_spec.rb CHANGED
@@ -22,6 +22,50 @@ describe Customerio::Client do
22
22
  MultiJson.dump(data)
23
23
  end
24
24
 
25
+ it "the base client is initialised with the correct values when no region is passed in" do
26
+ site_id = "SITE_ID"
27
+ api_key = "API_KEY"
28
+
29
+ expect(Customerio::BaseClient).to(
30
+ receive(:new)
31
+ .with(
32
+ { site_id: site_id, api_key: api_key },
33
+ {
34
+ region: Customerio::Regions::US,
35
+ url: Customerio::Regions::US.track_url
36
+ }
37
+ )
38
+ )
39
+
40
+ client = Customerio::Client.new(site_id, api_key)
41
+ end
42
+
43
+ it "raises an error when an incorrect region is passed in" do
44
+ expect {
45
+ Customerio::Client.new("siteid", "apikey", region: :au)
46
+ }.to raise_error /region must be an instance of Customerio::Regions::Region/
47
+ end
48
+
49
+ [Customerio::Regions::US, Customerio::Regions::EU].each do |region|
50
+ it "the base client is initialised with the correct values when the region \"#{region}\" is passed in" do
51
+ site_id = "SITE_ID"
52
+ api_key = "API_KEY"
53
+
54
+ expect(Customerio::BaseClient).to(
55
+ receive(:new)
56
+ .with(
57
+ { site_id: site_id, api_key: api_key },
58
+ {
59
+ region: region,
60
+ url: region.track_url
61
+ }
62
+ )
63
+ )
64
+
65
+ client = Customerio::Client.new(site_id, api_key, { region: region })
66
+ end
67
+ end
68
+
25
69
  it "uses json by default" do
26
70
  body = { id: 5, name: "Bob" }
27
71
  client = Customerio::Client.new("SITE_ID", "API_KEY")
data/spec/spec_helper.rb CHANGED
@@ -10,6 +10,6 @@ require 'rspec'
10
10
  require 'webmock/rspec'
11
11
 
12
12
  RSpec.configure do |config|
13
- config.expect_with(:rspec) { |c| c.syntax = :should }
14
- config.mock_with(:rspec) { |c| c.syntax = :should }
13
+ config.expect_with(:rspec) { |c| c.syntax = [:should, :expect] }
14
+ config.mock_with(:rspec) { |c| c.syntax = [:should, :expect] }
15
15
  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: 3.0.0
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Allison
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-03 00:00:00.000000000 Z
11
+ date: 2021-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -102,6 +102,7 @@ extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
104
  - ".circleci/config.yml"
105
+ - ".github/workflows/main.yml"
105
106
  - ".gitignore"
106
107
  - CHANGELOG.markdown
107
108
  - Gemfile
@@ -114,6 +115,7 @@ files:
114
115
  - lib/customerio/base_client.rb
115
116
  - lib/customerio/client.rb
116
117
  - lib/customerio/param_encoder.rb
118
+ - lib/customerio/regions.rb
117
119
  - lib/customerio/requests/send_email_request.rb
118
120
  - lib/customerio/version.rb
119
121
  - spec/api_client_spec.rb
@@ -139,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
141
  - !ruby/object:Gem::Version
140
142
  version: '0'
141
143
  requirements: []
142
- rubygems_version: 3.1.2
144
+ rubygems_version: 3.2.3
143
145
  signing_key:
144
146
  specification_version: 4
145
147
  summary: A ruby client for the Customer.io event API.