customerio_api 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +4 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE.txt +21 -0
- data/README.md +142 -0
- data/Rakefile +8 -0
- data/lib/customerio_api/errors.rb +20 -0
- data/lib/customerio_api/object.rb +22 -0
- data/lib/customerio_api/objects/customer.rb +4 -0
- data/lib/customerio_api/objects/customerio_object.rb +4 -0
- data/lib/customerio_api/objects/object_relationship.rb +4 -0
- data/lib/customerio_api/resource.rb +44 -0
- data/lib/customerio_api/resources/customer_resource.rb +14 -0
- data/lib/customerio_api/resources/customerio_object_resource.rb +30 -0
- data/lib/customerio_api/resources/object_relationship_resource.rb +16 -0
- data/lib/customerio_api/resources/track_resource.rb +26 -0
- data/lib/customerio_api/v1_client.rb +37 -0
- data/lib/customerio_api/v2_client.rb +30 -0
- data/lib/customerio_api/version.rb +5 -0
- data/lib/customerio_api.rb +19 -0
- data/rubocop.yml +20 -0
- data/sig/customerio_api.rbs +4 -0
- metadata +167 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6091d1158347650e87f732c7e733f0db28b0832e80d28df0b4b645648bddcd06
|
4
|
+
data.tar.gz: 00a16c715091dbdef658965c64244b18cde75248ed766b7e878825788633cb7a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a12e7858737966bd0b05245b323b661e2959b19e358e1da381ae5942f70ccac9dc298219dabe4c62b7a7480c980cfc4182a063ba019f9b3b50d97869172ff07e
|
7
|
+
data.tar.gz: 8339cfd265bba418b73a8f186543a68351f58047745ce415970142d8f1b32fe51a32c99c44aaf2e846ae4031e17131cfb4e7c2193fef16652f993ded52479f35
|
data/.rspec
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
10
|
+
identity and orientation.
|
11
|
+
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
13
|
+
diverse, inclusive, and healthy community.
|
14
|
+
|
15
|
+
## Our Standards
|
16
|
+
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
18
|
+
community include:
|
19
|
+
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
24
|
+
and learning from the experience
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the overall
|
26
|
+
community
|
27
|
+
|
28
|
+
Examples of unacceptable behavior include:
|
29
|
+
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or advances of
|
31
|
+
any kind
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
33
|
+
* Public or private harassment
|
34
|
+
* Publishing others' private information, such as a physical or email address,
|
35
|
+
without their explicit permission
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
37
|
+
professional setting
|
38
|
+
|
39
|
+
## Enforcement Responsibilities
|
40
|
+
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
44
|
+
or harmful.
|
45
|
+
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
49
|
+
decisions when appropriate.
|
50
|
+
|
51
|
+
## Scope
|
52
|
+
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
54
|
+
an individual is officially representing the community in public spaces.
|
55
|
+
Examples of representing our community include using an official email address,
|
56
|
+
posting via an official social media account, or acting as an appointed
|
57
|
+
representative at an online or offline event.
|
58
|
+
|
59
|
+
## Enforcement
|
60
|
+
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
62
|
+
reported to the community leaders responsible for enforcement at
|
63
|
+
[INSERT CONTACT METHOD].
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
65
|
+
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
67
|
+
reporter of any incident.
|
68
|
+
|
69
|
+
## Enforcement Guidelines
|
70
|
+
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
73
|
+
|
74
|
+
### 1. Correction
|
75
|
+
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
77
|
+
unprofessional or unwelcome in the community.
|
78
|
+
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
82
|
+
|
83
|
+
### 2. Warning
|
84
|
+
|
85
|
+
**Community Impact**: A violation through a single incident or series of
|
86
|
+
actions.
|
87
|
+
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
92
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
93
|
+
ban.
|
94
|
+
|
95
|
+
### 3. Temporary Ban
|
96
|
+
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
98
|
+
sustained inappropriate behavior.
|
99
|
+
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
101
|
+
communication with the community for a specified period of time. No public or
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
104
|
+
Violating these terms may lead to a permanent ban.
|
105
|
+
|
106
|
+
### 4. Permanent Ban
|
107
|
+
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
111
|
+
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
113
|
+
community.
|
114
|
+
|
115
|
+
## Attribution
|
116
|
+
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
118
|
+
version 2.1, available at
|
119
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
120
|
+
|
121
|
+
Community Impact Guidelines were inspired by
|
122
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
123
|
+
|
124
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
125
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
126
|
+
[https://www.contributor-covenant.org/translations][translations].
|
127
|
+
|
128
|
+
[homepage]: https://www.contributor-covenant.org
|
129
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
130
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
131
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
132
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 Linh
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
# CustomerioAPI
|
2
|
+
|
3
|
+
This is an API wrapper gem for Customer.io API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Install the gem and add to the application's Gemfile by executing:
|
8
|
+
|
9
|
+
$ bundle add customerio_api
|
10
|
+
|
11
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
12
|
+
|
13
|
+
$ gem install customerio_api
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
### Client
|
18
|
+
|
19
|
+
#### V1Client
|
20
|
+
|
21
|
+
V1Client is used to retreive data for the following resources:
|
22
|
+
|
23
|
+
- Customer
|
24
|
+
- CustomerioObject
|
25
|
+
- ObjectRelationship
|
26
|
+
|
27
|
+
V1Client is initialized with an API key which is used for bearer token authentication.
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
v1_client = CustomerioAPI::V1Client.new(api_key: ENV['CUSTOMERIO_API_KEY'])
|
31
|
+
```
|
32
|
+
|
33
|
+
#### V2Client
|
34
|
+
|
35
|
+
V2Client is used to perform various operations based on the type (person, object or delivery) and action (identify, add_relationships, delete, etc) that you set in the request.
|
36
|
+
|
37
|
+
V2Client is initialized with a site_id and track_api_key which is used for basic authentication.
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
v2_client = CustomerioAPI::V2Client.new(site_id: ENV['SITE_ID'], track_api_key: ENV['TRACK_API_KEY'])
|
41
|
+
```
|
42
|
+
|
43
|
+
### Customer
|
44
|
+
|
45
|
+
#### 1. Get a list of customers by email
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
customers = v1_client.customer.where(email: 'test@example.com')
|
49
|
+
|
50
|
+
# => returns a list of CustomerioAPI::Customer
|
51
|
+
```
|
52
|
+
|
53
|
+
### CustomerioObject
|
54
|
+
|
55
|
+
#### 1. Use a set of filter conditions to find object
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
attributes =
|
59
|
+
{
|
60
|
+
"object_type_id": '1',
|
61
|
+
"filter": {
|
62
|
+
"and":
|
63
|
+
[
|
64
|
+
{
|
65
|
+
"object_attribute": {
|
66
|
+
"field": 'name',
|
67
|
+
"operator": 'eq',
|
68
|
+
"type_id": '1',
|
69
|
+
"value": 'PostCo'
|
70
|
+
}
|
71
|
+
}
|
72
|
+
]
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
76
|
+
# start and limit params are optional
|
77
|
+
start = "0"
|
78
|
+
limit = 10
|
79
|
+
|
80
|
+
v1_client.object.where(attributes: attributes, start: start, limit: limit)
|
81
|
+
|
82
|
+
# => returns a CustomerioAPI::CustomerioObject
|
83
|
+
```
|
84
|
+
|
85
|
+
### ObjectRelationship
|
86
|
+
|
87
|
+
#### 1. Get a list of people related to an object.
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
# query_params is optional
|
91
|
+
query_params = {start: string, limit: integer, id_type: "object_id" | "cio_object_id"}
|
92
|
+
v1_client.object_relationship.where(object_type_id: 1, object_id: 'PostCo', query_params: query_params)
|
93
|
+
|
94
|
+
# => returns a CustomerioAPI::ObjectRelationship
|
95
|
+
```
|
96
|
+
|
97
|
+
### Track
|
98
|
+
|
99
|
+
#### 1. Single request
|
100
|
+
|
101
|
+
This endpoint lets create, update, or delete a single person or object—including managing relationships between objects and people.
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
# Create a person
|
105
|
+
attributes = { type: 'object', action: 'identify', identifiers: { object_type_id: '1', object_id: 'test'}, attributes: {name: "test"} }
|
106
|
+
v2_client.track.entity(attributes)
|
107
|
+
|
108
|
+
# => returns {}
|
109
|
+
```
|
110
|
+
|
111
|
+
#### 2. Multiple request
|
112
|
+
|
113
|
+
This endpoint lets you batch requests for different people and objects in a single request.
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
# Update multiple objects
|
117
|
+
attributes = [
|
118
|
+
{ type: 'object', action: 'identify', identifiers: { object_type_id: '1', object_id: 'shop-1' }, attributes: { name: 'Shop 1 updated' } },
|
119
|
+
{ type: 'object', action: 'identify', identifiers: { object_type_id: '1', object_id: 'shop-2' }, attributes: { name: 'Shop 2 updated' } }
|
120
|
+
]
|
121
|
+
v2_client.track.batch(attributes)
|
122
|
+
|
123
|
+
# => returns {}
|
124
|
+
```
|
125
|
+
|
126
|
+
## Development
|
127
|
+
|
128
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
129
|
+
|
130
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
131
|
+
|
132
|
+
## Contributing
|
133
|
+
|
134
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/customerio_api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/customerio_api/blob/master/CODE_OF_CONDUCT.md).
|
135
|
+
|
136
|
+
## License
|
137
|
+
|
138
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
139
|
+
|
140
|
+
## Code of Conduct
|
141
|
+
|
142
|
+
Everyone interacting in the CustomerioAPI project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/customerio_api/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CustomerioAPI
|
4
|
+
class Error < StandardError; end
|
5
|
+
|
6
|
+
class NotFoundError < Error
|
7
|
+
end
|
8
|
+
|
9
|
+
class WhiteListError < Error
|
10
|
+
end
|
11
|
+
|
12
|
+
class AuthenticationError < Error
|
13
|
+
end
|
14
|
+
|
15
|
+
class ServerError < Error
|
16
|
+
end
|
17
|
+
|
18
|
+
class RateLimitError < Error
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/core_ext/string'
|
4
|
+
require 'ostruct'
|
5
|
+
|
6
|
+
module CustomerioAPI
|
7
|
+
class Object < OpenStruct
|
8
|
+
def initialize(attributes)
|
9
|
+
super to_ostruct(attributes)
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_ostruct(obj)
|
13
|
+
if obj.is_a?(Hash)
|
14
|
+
OpenStruct.new(obj.map { |key, val| [key.underscore, to_ostruct(val)] }.to_h)
|
15
|
+
elsif obj.is_a?(Array)
|
16
|
+
obj.map { |o| to_ostruct(o) }
|
17
|
+
else # Assumed to be a primitive value
|
18
|
+
obj
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CustomerioAPI
|
4
|
+
class Resource
|
5
|
+
attr_reader :client
|
6
|
+
|
7
|
+
def initialize(client)
|
8
|
+
@client = client
|
9
|
+
end
|
10
|
+
|
11
|
+
def get_request(url, params: {}, headers: {})
|
12
|
+
handle_response client.connection.get(url, params, headers)
|
13
|
+
end
|
14
|
+
|
15
|
+
def post_request(url, body:, headers: {})
|
16
|
+
handle_response client.connection.post(url, body, headers)
|
17
|
+
end
|
18
|
+
|
19
|
+
def put_request(url, body:, headers: {})
|
20
|
+
handle_response client.connection.put(url, body, headers)
|
21
|
+
end
|
22
|
+
|
23
|
+
def handle_response(response)
|
24
|
+
error_message = response.body
|
25
|
+
|
26
|
+
case response.status
|
27
|
+
when 400
|
28
|
+
raise Error, "A bad request or a validation exception has occurred. #{error_message}"
|
29
|
+
when 401
|
30
|
+
raise AuthenticationError, "Invalid authorization credentials. #{error_message}"
|
31
|
+
when 403
|
32
|
+
raise WhiteListError, "IP address is not white listed. #{error_message}"
|
33
|
+
when 404
|
34
|
+
raise NotFoundError, "The resource you have specified cannot be found. #{error_message}"
|
35
|
+
when 429
|
36
|
+
raise RateLimitError, "The API rate limit for your application has been exceeded. #{error_message}"
|
37
|
+
when 500
|
38
|
+
raise ServerError, "An unhandled error with the Customer.io API. #{error_message}"
|
39
|
+
end
|
40
|
+
|
41
|
+
response
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CustomerioAPI
|
4
|
+
class CustomerResource < Resource
|
5
|
+
# client.customer.where(email: "andy@postco.io")
|
6
|
+
# Response:
|
7
|
+
# [#<CustomerioAPI::Customer email="andy@postco.io", id="test1", cio_id="d7a90a000102">]
|
8
|
+
|
9
|
+
def where(email:)
|
10
|
+
response_body = get_request('customers', params: { email: email }).body
|
11
|
+
response_body['results'].map { |customers| Customer.new(customers) }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CustomerioAPI
|
4
|
+
class CustomerioObjectResource < Resource
|
5
|
+
# attributes = {
|
6
|
+
# "object_type_id": '1',
|
7
|
+
# "filter": {
|
8
|
+
# "and": [
|
9
|
+
# {
|
10
|
+
# "object_attribute": {
|
11
|
+
# "field": 'name',
|
12
|
+
# "operator": 'eq',
|
13
|
+
# "type_id": '1',
|
14
|
+
# "value": 'PostCo'
|
15
|
+
# }
|
16
|
+
# }
|
17
|
+
# ]
|
18
|
+
# }
|
19
|
+
# }
|
20
|
+
# client.object.where(attributes: attributes)
|
21
|
+
|
22
|
+
# Response:
|
23
|
+
# #<CustomerioAPI::CustomerioObject identifiers=[#<OpenStruct cio_object_id="obd7a90a0102", object_id="PostCo">], ids=["PostCo"], next="">
|
24
|
+
|
25
|
+
def where(attributes:, start: nil, limit: nil)
|
26
|
+
response_body = post_request("objects?start=#{start}&limit=#{limit}", body: attributes).body
|
27
|
+
CustomerioObject.new(response_body)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CustomerioAPI
|
4
|
+
class ObjectRelationshipResource < Resource
|
5
|
+
# query_params = {start: string, limit: integer, id_type: "object_id" | "cio_object_id"}
|
6
|
+
# client.object_relationship.where(object_type_id: 1, object_id: 'PostCo', query_params: query_params)
|
7
|
+
|
8
|
+
# Response:
|
9
|
+
# #<CustomerioAPI::ObjectRelationship cio_relationships=[#<OpenStruct object_type_id="0", identifiers=#<OpenStruct cio_id="d7a90a000102", email="andy@postco.io", id="test1">, attributes=#<OpenStruct>, timestamps=#<OpenStruct>>], next="">
|
10
|
+
|
11
|
+
def where(object_type_id:, object_id:, query_params: {})
|
12
|
+
response_body = get_request("objects/#{object_type_id}/#{object_id}/relationships", params: query_params).body
|
13
|
+
ObjectRelationship.new(response_body)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module CustomerioAPI
|
2
|
+
class TrackResource < Resource
|
3
|
+
# Example: Create/Update a Shop object
|
4
|
+
# attributes = { type: 'object', action: 'identify', identifiers: { object_type_id: '2', object_id: 'linh-us'}, attributes: {name: "linh-us"} }
|
5
|
+
# v2_client.track.entity(attributes)
|
6
|
+
# Response: {}
|
7
|
+
|
8
|
+
def entity(attributes)
|
9
|
+
post_request('entity', body: attributes).body
|
10
|
+
end
|
11
|
+
|
12
|
+
# Example: Create/Update multiple objects
|
13
|
+
# attributes: an array of people or objects
|
14
|
+
# attributes = [
|
15
|
+
# { type: 'object', action: 'identify', identifiers: { object_type_id: '1', object_id: 'linh-us' }, attributes: { name: 'linh-us' } },
|
16
|
+
# { type: 'object', action: 'identify', identifiers: { object_type_id: '1', object_id: 'PostCo' }, attributes: { name: 'PostCo' } }
|
17
|
+
# ]
|
18
|
+
|
19
|
+
# v2_client.track.batch(attributes)
|
20
|
+
# Response: {}
|
21
|
+
|
22
|
+
def batch(attributes)
|
23
|
+
post_request('batch', body: { batch: attributes }).body
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'faraday'
|
4
|
+
|
5
|
+
module CustomerioAPI
|
6
|
+
class V1Client
|
7
|
+
BASE_URL = 'https://api.customer.io/v1/'
|
8
|
+
attr_reader :api_key, :adapter
|
9
|
+
|
10
|
+
def initialize(api_key:, adapter: Faraday.default_adapter)
|
11
|
+
@api_key = api_key
|
12
|
+
@adapter = adapter
|
13
|
+
end
|
14
|
+
|
15
|
+
def customer
|
16
|
+
CustomerResource.new(self)
|
17
|
+
end
|
18
|
+
|
19
|
+
def object
|
20
|
+
CustomerioObjectResource.new(self)
|
21
|
+
end
|
22
|
+
|
23
|
+
def object_relationship
|
24
|
+
ObjectRelationshipResource.new(self)
|
25
|
+
end
|
26
|
+
|
27
|
+
def connection
|
28
|
+
@connection ||= Faraday.new do |conn|
|
29
|
+
conn.url_prefix = BASE_URL
|
30
|
+
conn.request :json
|
31
|
+
conn.response :json, content_type: 'application/json'
|
32
|
+
conn.adapter adapter
|
33
|
+
conn.headers['Authorization'] = "Bearer #{api_key}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'faraday'
|
4
|
+
|
5
|
+
module CustomerioAPI
|
6
|
+
class V2Client
|
7
|
+
BASE_URL = 'https://track.customer.io/api/v2/'
|
8
|
+
attr_reader :site_id, :track_api_key, :adapter
|
9
|
+
|
10
|
+
def initialize(site_id:, track_api_key:, adapter: Faraday.default_adapter)
|
11
|
+
@track_api_key = track_api_key
|
12
|
+
@site_id = site_id
|
13
|
+
@adapter = adapter
|
14
|
+
end
|
15
|
+
|
16
|
+
def track
|
17
|
+
TrackResource.new(self)
|
18
|
+
end
|
19
|
+
|
20
|
+
def connection
|
21
|
+
@connection ||= Faraday.new do |conn|
|
22
|
+
conn.url_prefix = BASE_URL
|
23
|
+
conn.request :json
|
24
|
+
conn.response :json, content_type: 'application/json'
|
25
|
+
conn.adapter adapter
|
26
|
+
conn.request :authorization, :basic, site_id, track_api_key
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'customerio_api/version'
|
4
|
+
require 'zeitwerk'
|
5
|
+
|
6
|
+
loader = Zeitwerk::Loader.for_gem
|
7
|
+
loader.inflector.inflect('customerio_api' => 'CustomerioAPI')
|
8
|
+
loader.collapse("#{__dir__}/customerio_api/objects")
|
9
|
+
loader.collapse("#{__dir__}/customerio_api/resources")
|
10
|
+
# Zeitwerk doesn't support multiple classes in a single file
|
11
|
+
# https://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#one-file-one-constant-at-the-same-top-level
|
12
|
+
loader.ignore("#{__dir__}/customerio_api/errors.rb")
|
13
|
+
loader.setup
|
14
|
+
|
15
|
+
require 'customerio_api/errors'
|
16
|
+
|
17
|
+
module CustomerioAPI
|
18
|
+
end
|
19
|
+
|
data/rubocop.yml
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.6
|
3
|
+
|
4
|
+
Style/StringLiterals:
|
5
|
+
Enabled: true
|
6
|
+
EnforcedStyle: double_quotes
|
7
|
+
|
8
|
+
Style/StringLiteralsInInterpolation:
|
9
|
+
Enabled: true
|
10
|
+
EnforcedStyle: double_quotes
|
11
|
+
|
12
|
+
Layout/LineLength:
|
13
|
+
Max: 120
|
14
|
+
|
15
|
+
Metrics/MethodLength:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
Metrics/BlockLength:
|
19
|
+
Enabled: false
|
20
|
+
|
metadata
ADDED
@@ -0,0 +1,167 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: customerio_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- linhho0702
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-09-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.7.11
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.7.11
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: zeitwerk
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.6'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.23.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.23.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: dotenv
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
- hplinh0702@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".rspec"
|
119
|
+
- CHANGELOG.md
|
120
|
+
- CODE_OF_CONDUCT.md
|
121
|
+
- LICENSE.txt
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- lib/customerio_api.rb
|
125
|
+
- lib/customerio_api/errors.rb
|
126
|
+
- lib/customerio_api/object.rb
|
127
|
+
- lib/customerio_api/objects/customer.rb
|
128
|
+
- lib/customerio_api/objects/customerio_object.rb
|
129
|
+
- lib/customerio_api/objects/object_relationship.rb
|
130
|
+
- lib/customerio_api/resource.rb
|
131
|
+
- lib/customerio_api/resources/customer_resource.rb
|
132
|
+
- lib/customerio_api/resources/customerio_object_resource.rb
|
133
|
+
- lib/customerio_api/resources/object_relationship_resource.rb
|
134
|
+
- lib/customerio_api/resources/track_resource.rb
|
135
|
+
- lib/customerio_api/v1_client.rb
|
136
|
+
- lib/customerio_api/v2_client.rb
|
137
|
+
- lib/customerio_api/version.rb
|
138
|
+
- rubocop.yml
|
139
|
+
- sig/customerio_api.rbs
|
140
|
+
homepage: https://github.com/PostCo/customerio_api
|
141
|
+
licenses:
|
142
|
+
- MIT
|
143
|
+
metadata:
|
144
|
+
allowed_push_host: https://rubygems.org/
|
145
|
+
homepage_uri: https://github.com/PostCo/customerio_api
|
146
|
+
source_code_uri: https://github.com/PostCo/customerio_api
|
147
|
+
changelog_uri: https://github.com/PostCo/customerio_api/releases
|
148
|
+
post_install_message:
|
149
|
+
rdoc_options: []
|
150
|
+
require_paths:
|
151
|
+
- lib
|
152
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
153
|
+
requirements:
|
154
|
+
- - ">="
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: 3.0.0
|
157
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
158
|
+
requirements:
|
159
|
+
- - ">="
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
version: '0'
|
162
|
+
requirements: []
|
163
|
+
rubygems_version: 3.5.11
|
164
|
+
signing_key:
|
165
|
+
specification_version: 4
|
166
|
+
summary: Customer.io API Wrapper
|
167
|
+
test_files: []
|