parallel588-klaviyo 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.rubocop.yml +152 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/README.md +36 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/klaviyo.gemspec +30 -0
- data/lib/data/ca-certificates.crt +3893 -0
- data/lib/klaviyo/client.rb +45 -0
- data/lib/klaviyo/event.rb +48 -0
- data/lib/klaviyo/people.rb +24 -0
- data/lib/klaviyo/templates/api_operations.rb +69 -0
- data/lib/klaviyo/templates.rb +8 -0
- data/lib/klaviyo/version.rb +3 -0
- data/lib/klaviyo.rb +17 -0
- metadata +200 -0
@@ -0,0 +1,45 @@
|
|
1
|
+
module Klaviyo
|
2
|
+
API_ENDPOINT = 'https://a.klaviyo.com'
|
3
|
+
|
4
|
+
class Client
|
5
|
+
attr_reader :api_key, :conn, :token
|
6
|
+
def initialize(api_key, token)
|
7
|
+
@api_key = api_key
|
8
|
+
@token = token
|
9
|
+
@conn = Faraday.new(
|
10
|
+
url: API_ENDPOINT,
|
11
|
+
ssl: { ca_path: Klaviyo::DEFAULT_CA_BUNDLE_PATH }
|
12
|
+
) do |b|
|
13
|
+
b.headers['Accept'] = 'application/json'
|
14
|
+
b.request :url_encoded
|
15
|
+
b.response :logger
|
16
|
+
b.response :json, content_type: 'application/json'
|
17
|
+
b.adapter Faraday.default_adapter
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def build_params(params = {})
|
22
|
+
options = params.merge(
|
23
|
+
api_key: api_key,
|
24
|
+
token: token
|
25
|
+
)
|
26
|
+
|
27
|
+
{
|
28
|
+
data: Base64.encode64(JSON.generate(options)).delete("\n")
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
def invoke(resource, method, options = {})
|
33
|
+
constantize("klaviyo/#{resource}").send(
|
34
|
+
method,
|
35
|
+
options.merge(client: self)
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def constantize(class_name)
|
42
|
+
Object.module_eval(class_name.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase })
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Klaviyo
|
2
|
+
module Event
|
3
|
+
module ApiOperations
|
4
|
+
Result = Struct.new(:response) do
|
5
|
+
def success?
|
6
|
+
response.to_s == '1'
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def track(client:, event_name:,
|
11
|
+
customer_properties:,
|
12
|
+
properties: {},
|
13
|
+
time: nil)
|
14
|
+
|
15
|
+
|
16
|
+
res = client.conn.get(
|
17
|
+
'/api/track',
|
18
|
+
client.build_params(
|
19
|
+
event: event_name,
|
20
|
+
customer_properties: customer_properties,
|
21
|
+
properties: properties,
|
22
|
+
time: time
|
23
|
+
)
|
24
|
+
)
|
25
|
+
Result.new(res.body)
|
26
|
+
end
|
27
|
+
|
28
|
+
def track_once(client:, event_name:,
|
29
|
+
customer_properties:,
|
30
|
+
properties: {},
|
31
|
+
time: nil)
|
32
|
+
res = client.conn.get(
|
33
|
+
'/api/track-once',
|
34
|
+
client.build_params(
|
35
|
+
event: event_name,
|
36
|
+
customer_properties: customer_properties,
|
37
|
+
properties: properties,
|
38
|
+
time: time
|
39
|
+
)
|
40
|
+
)
|
41
|
+
Result.new(res.body)
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
extend ApiOperations
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Klaviyo
|
2
|
+
module People
|
3
|
+
module ApiOperations
|
4
|
+
Result = Struct.new(:response) do
|
5
|
+
def success?
|
6
|
+
response.to_s == '1'
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
# https://www.klaviyo.com/docs/http-api#people
|
11
|
+
# invoke(:people, :identify, properties: { '$email': 'useremail@ua.com' })
|
12
|
+
#
|
13
|
+
def identify(client:, properties: {})
|
14
|
+
res = client.conn.get(
|
15
|
+
'/api/identify',
|
16
|
+
client.build_params(properties: properties)
|
17
|
+
)
|
18
|
+
Result.new(res.body)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
extend ApiOperations
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Klaviyo
|
2
|
+
module Templates
|
3
|
+
# https://www.klaviyo.com/docs/api/email-templates
|
4
|
+
#
|
5
|
+
module ApiOperations
|
6
|
+
|
7
|
+
def all(client:)
|
8
|
+
client.conn.get('/api/v1/email-templates', api_key: client.api_key)
|
9
|
+
end
|
10
|
+
|
11
|
+
def create(client:, name:, html:)
|
12
|
+
client.conn.post(
|
13
|
+
'/api/v1/email-templates',
|
14
|
+
api_key: client.api_key,
|
15
|
+
name: name,
|
16
|
+
html: html
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
def update(client:, id:, name:, html:)
|
21
|
+
client.conn.put(
|
22
|
+
"/api/v1/email-template/#{id}",
|
23
|
+
api_key: client.api_key,
|
24
|
+
name: name,
|
25
|
+
html: html
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
def delete(client:, id:)
|
30
|
+
client.conn.delete(
|
31
|
+
"/api/v1/email-template/#{id}",
|
32
|
+
api_key: client.api_key
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
36
|
+
def clone(client:, id:, name:)
|
37
|
+
client.conn.post(
|
38
|
+
"/api/v1/email-template/#{id}/clone",
|
39
|
+
api_key: client.api_key,
|
40
|
+
name: name
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
def render(client:, id:, context:)
|
45
|
+
client.conn.post(
|
46
|
+
"/api/v1/email-template/#{id}/render",
|
47
|
+
api_key: client.api_key,
|
48
|
+
context: context
|
49
|
+
)
|
50
|
+
end
|
51
|
+
|
52
|
+
def render_and_send(
|
53
|
+
client:, id:, context:,
|
54
|
+
service:, from_email:, from_name:, subject:, to:
|
55
|
+
)
|
56
|
+
client.conn.post(
|
57
|
+
"/api/v1/email-template/#{id}/send",
|
58
|
+
api_key: client.api_key,
|
59
|
+
context: context,
|
60
|
+
service: service,
|
61
|
+
from_email: from_email,
|
62
|
+
from_name: from_name,
|
63
|
+
subject: subject,
|
64
|
+
to: to
|
65
|
+
)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/lib/klaviyo.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'klaviyo/version'
|
2
|
+
require 'klaviyo/client'
|
3
|
+
require 'klaviyo/templates'
|
4
|
+
require 'klaviyo/event'
|
5
|
+
require 'klaviyo/people'
|
6
|
+
|
7
|
+
require 'active_support'
|
8
|
+
require 'active_support/core_ext'
|
9
|
+
require 'faraday'
|
10
|
+
require 'faraday_middleware'
|
11
|
+
require 'json'
|
12
|
+
require 'virtus'
|
13
|
+
|
14
|
+
|
15
|
+
module Klaviyo
|
16
|
+
DEFAULT_CA_BUNDLE_PATH = File.dirname(__FILE__) + '/data'
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,200 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: parallel588-klaviyo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Maxim Pechnikov
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: virtus
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.0.5
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.0'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.0.5
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: json
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.8'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.8'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: faraday
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.9.2
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 0.9.2
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: faraday_middleware
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0.10'
|
68
|
+
type: :runtime
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0.10'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: activesupport
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '3.1'
|
82
|
+
- - "<"
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '6.0'
|
85
|
+
type: :runtime
|
86
|
+
prerelease: false
|
87
|
+
version_requirements: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '3.1'
|
92
|
+
- - "<"
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '6.0'
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: bundler
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - "~>"
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '1.11'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - "~>"
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '1.11'
|
109
|
+
- !ruby/object:Gem::Dependency
|
110
|
+
name: rake
|
111
|
+
requirement: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - "~>"
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '10.0'
|
116
|
+
type: :development
|
117
|
+
prerelease: false
|
118
|
+
version_requirements: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - "~>"
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '10.0'
|
123
|
+
- !ruby/object:Gem::Dependency
|
124
|
+
name: rspec
|
125
|
+
requirement: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - "~>"
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '3.0'
|
130
|
+
type: :development
|
131
|
+
prerelease: false
|
132
|
+
version_requirements: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - "~>"
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '3.0'
|
137
|
+
- !ruby/object:Gem::Dependency
|
138
|
+
name: pry
|
139
|
+
requirement: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - "~>"
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: 0.10.3
|
144
|
+
type: :development
|
145
|
+
prerelease: false
|
146
|
+
version_requirements: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - "~>"
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: 0.10.3
|
151
|
+
description: Ruby wrapper for the Klaviyo API
|
152
|
+
email:
|
153
|
+
- parallel588@gmail.com
|
154
|
+
executables: []
|
155
|
+
extensions: []
|
156
|
+
extra_rdoc_files: []
|
157
|
+
files:
|
158
|
+
- ".gitignore"
|
159
|
+
- ".rspec"
|
160
|
+
- ".rubocop.yml"
|
161
|
+
- ".travis.yml"
|
162
|
+
- Gemfile
|
163
|
+
- README.md
|
164
|
+
- Rakefile
|
165
|
+
- bin/console
|
166
|
+
- bin/setup
|
167
|
+
- klaviyo.gemspec
|
168
|
+
- lib/data/ca-certificates.crt
|
169
|
+
- lib/klaviyo.rb
|
170
|
+
- lib/klaviyo/client.rb
|
171
|
+
- lib/klaviyo/event.rb
|
172
|
+
- lib/klaviyo/people.rb
|
173
|
+
- lib/klaviyo/templates.rb
|
174
|
+
- lib/klaviyo/templates/api_operations.rb
|
175
|
+
- lib/klaviyo/version.rb
|
176
|
+
homepage: https://www.klaviyo.com/
|
177
|
+
licenses: []
|
178
|
+
metadata: {}
|
179
|
+
post_install_message:
|
180
|
+
rdoc_options: []
|
181
|
+
require_paths:
|
182
|
+
- lib
|
183
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
189
|
+
requirements:
|
190
|
+
- - ">="
|
191
|
+
- !ruby/object:Gem::Version
|
192
|
+
version: '0'
|
193
|
+
requirements: []
|
194
|
+
rubyforge_project:
|
195
|
+
rubygems_version: 2.5.1
|
196
|
+
signing_key:
|
197
|
+
specification_version: 4
|
198
|
+
summary: You heard us, a Ruby wrapper for the Klaviyo API
|
199
|
+
test_files: []
|
200
|
+
has_rdoc:
|