klaviyo_api 1.2.0 → 1.3.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 +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/klaviyo_api.rb +1 -0
- data/lib/klaviyo_api/collections.rb +3 -0
- data/lib/klaviyo_api/collections/profile.rb +17 -0
- data/lib/klaviyo_api/resources/profile.rb +64 -0
- data/lib/klaviyo_api/resources/support/countable.rb +9 -0
- data/lib/klaviyo_api/version.rb +1 -1
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb1fb4019e0ab815eed1cc24a427e97125369040f7e08821aeab66927f941b55
|
4
|
+
data.tar.gz: bed43a2800399a3136dfe3c139882d132a50e8a56746aa912d178c5e9e58675b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 443aad88c951bc24b23b08adde05179352edca3f2fd8fdeb38b41ceb1de0374d09b5328ef28c5b606807abbd55413eee262a9bf62fc4d7d988ad4befc0d284e1
|
7
|
+
data.tar.gz: 196cf5de54d6c9d4f7fc53d20863d2e97fc3b1073f27ff4c6f1986dbd3c12b5943fdc354bdc454f5a17324cbfabccfd87a59abbe5d9be377e581ff286e7aa6b0
|
data/CHANGELOG.md
CHANGED
data/lib/klaviyo_api.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KlaviyoAPI::Collections
|
4
|
+
class Profile < ActiveResource::Collection
|
5
|
+
attr_accessor :total, :page, :page_size, :start, :end
|
6
|
+
|
7
|
+
def initialize(response = {})
|
8
|
+
@total = response.delete 'total'
|
9
|
+
@page = response.delete 'page'
|
10
|
+
@page_size = response.delete 'page_size'
|
11
|
+
@start = response.delete 'start'
|
12
|
+
@end = response.delete 'end'
|
13
|
+
|
14
|
+
@elements = response['data'] || []
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KlaviyoAPI
|
4
|
+
class Profile < Base
|
5
|
+
extend KlaviyoAPI::Support::Countable
|
6
|
+
|
7
|
+
self.prefix += 'v1/'
|
8
|
+
|
9
|
+
self.element_name = 'person'
|
10
|
+
self.collection_parser = KlaviyoAPI::Collections::Profile
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def collection_path(prefix_options = {}, query_options = {})
|
14
|
+
super prefix_options, query_options.deep_merge({ api_key: headers['api-key'] })
|
15
|
+
end
|
16
|
+
|
17
|
+
def element_path(id, prefix_options = {}, query_options = {})
|
18
|
+
super id, prefix_options, query_options.deep_merge({ api_key: headers['api-key'] })
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def destroy
|
23
|
+
raise KlaviyoAPI::InvalidOperation.new 'Cannot delete Profiles via API.'
|
24
|
+
end
|
25
|
+
|
26
|
+
def create
|
27
|
+
raise KlaviyoAPI::InvalidOperation.new 'Cannot create Profiles via API.'
|
28
|
+
end
|
29
|
+
|
30
|
+
def update
|
31
|
+
run_callbacks :update do
|
32
|
+
# This endpoint does not accept JSON bodies. Additionally, if the API key is in the URL, the rest of the attributes
|
33
|
+
# MUST be in the URL as well. The other option is to have the API key and all attributes in the body as `key=value` pairs.
|
34
|
+
#
|
35
|
+
# To reduce friction, as we already need the API key in the URL for other operations, let's just add all the attributes
|
36
|
+
# to the URL. Unfortunately we will need to include ALL the attributes, not just the changed ones, because it seems
|
37
|
+
# ActiveResource has no support for dirty models. https://github.com/rails/activeresource/issues/308
|
38
|
+
path = self.class.element_path(id, prefix_options, attributes)
|
39
|
+
|
40
|
+
connection.put(path, nil, self.class.headers).tap do |response|
|
41
|
+
load_attributes_from_response(response)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def method_missing(method_symbol, *arguments)
|
49
|
+
method_name = method_symbol.to_s
|
50
|
+
|
51
|
+
# Some fields start with a $ (e.g., '$title'). The methods `title`, `title?`
|
52
|
+
# and `title=` should act upon the attribute `$title` if present. Otherwise,
|
53
|
+
# they should act upon the attribute `title`
|
54
|
+
#
|
55
|
+
# Not a whole lot we can do if the item contains both `title` and `$title` -
|
56
|
+
# this will prioritize the version with the $.
|
57
|
+
if attributes.keys.any? { |attribute| attribute == "$#{method_name.sub(/\?|=$/, '')}" }
|
58
|
+
method_symbol = "$#{method_name}".to_sym
|
59
|
+
end
|
60
|
+
|
61
|
+
super
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/lib/klaviyo_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: klaviyo_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- rewind.io
|
@@ -204,6 +204,8 @@ files:
|
|
204
204
|
- README.md
|
205
205
|
- lib/active_resource/connection_ext.rb
|
206
206
|
- lib/klaviyo_api.rb
|
207
|
+
- lib/klaviyo_api/collections.rb
|
208
|
+
- lib/klaviyo_api/collections/profile.rb
|
207
209
|
- lib/klaviyo_api/configuration.rb
|
208
210
|
- lib/klaviyo_api/connection.rb
|
209
211
|
- lib/klaviyo_api/detailed_log_subscriber.rb
|
@@ -213,6 +215,8 @@ files:
|
|
213
215
|
- lib/klaviyo_api/resources/base.rb
|
214
216
|
- lib/klaviyo_api/resources/list.rb
|
215
217
|
- lib/klaviyo_api/resources/list_member.rb
|
218
|
+
- lib/klaviyo_api/resources/profile.rb
|
219
|
+
- lib/klaviyo_api/resources/support/countable.rb
|
216
220
|
- lib/klaviyo_api/session.rb
|
217
221
|
- lib/klaviyo_api/version.rb
|
218
222
|
homepage: https://github.com/rewindio/klaviyo_api.git
|