klaviyo_api 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 74537aa6edf57066528bfcefcf4fcb883ed5e85f68ed3bf562892dad33913d7d
4
- data.tar.gz: a885389e5301c6377a244a8a78af4c25b70981859f789cd4e53e2d72f69b8fe7
3
+ metadata.gz: bb1fb4019e0ab815eed1cc24a427e97125369040f7e08821aeab66927f941b55
4
+ data.tar.gz: bed43a2800399a3136dfe3c139882d132a50e8a56746aa912d178c5e9e58675b
5
5
  SHA512:
6
- metadata.gz: cd11a8738de6446e4d3619a1b703528021dbcd07328ceb3d01d3f335fff14bc3a21409995423b2f15f3356adb9a2a3a6702cf9db89549f2f59b59cbfefa91466
7
- data.tar.gz: 6a4c7bf744142bed009aa223e297b19f15d5073a57faaa123def8304b75d9e415ad85fd86e7e10eb59027148c750adbdc6cc452944dc89eba8c95432aac9fafc
6
+ metadata.gz: 443aad88c951bc24b23b08adde05179352edca3f2fd8fdeb38b41ceb1de0374d09b5328ef28c5b606807abbd55413eee262a9bf62fc4d7d988ad4befc0d284e1
7
+ data.tar.gz: 196cf5de54d6c9d4f7fc53d20863d2e97fc3b1073f27ff4c6f1986dbd3c12b5943fdc354bdc454f5a17324cbfabccfd87a59abbe5d9be377e581ff286e7aa6b0
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## [1.3.0]
4
+
5
+ ### Added
6
+
7
+ - Support `/v1/person/<id>`
8
+ - Support `/v1/people`
9
+ - Support `.count` on Profile
10
+
3
11
  ## [1.2.0]
4
12
 
5
13
  ### Added
data/lib/klaviyo_api.rb CHANGED
@@ -21,4 +21,5 @@ require 'klaviyo_api/detailed_log_subscriber'
21
21
  require 'klaviyo_api/exceptions'
22
22
  require 'klaviyo_api/session'
23
23
 
24
+ require 'klaviyo_api/collections'
24
25
  require 'klaviyo_api/resources'
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ Dir.glob("#{File.dirname(__FILE__)}/collections/*").each { |file| require file if file.end_with? '.rb' }
@@ -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
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KlaviyoAPI::Support
4
+ module Countable
5
+ def count(params = {})
6
+ all(params).total
7
+ end
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KlaviyoAPI
4
- VERSION = '1.2.0'
4
+ VERSION = '1.3.0'
5
5
  end
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.2.0
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