klaviyo_api 1.3.1 → 1.4.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: 730043f0dcbac75ac8f28308931684bae022bb5d412f5f137410ef7a9c6d8b09
4
- data.tar.gz: c9837c60aef92683d21db4b5868c8fb21ce309709692bf9f257ad308bafc7d6b
3
+ metadata.gz: fa973ac50c2f9d84ffea184bbe4ca030c7ff1ffc99fd1a76f0ab51f845140487
4
+ data.tar.gz: ac7b1cf169a606910eb51aa5736d92e926c60e5862b710027bdd3fa468af4bed
5
5
  SHA512:
6
- metadata.gz: afefe3883a8a4f78c1fba19cd1ecc40792a0aeb9332029f9faa44adde1d03f6a4fdb3f80ed9bfad19504cca6b6fb4057c90402eebc408d7c85c01a1bb35d7c23
7
- data.tar.gz: 558884db59de97077b7384f9d6d38a18652eb2883c99181a066585df7571550aac2719a22f06712dc2ef263d5efe374a615edeab88beda62320168546a91d896
6
+ metadata.gz: 2776400dcc29ef86aac04acb8c49a64d383e302ade62602666c6bb02d69573bde894ea785e61c045329c234c64d242f60182a043d3cc74729bf84ea35e67863c
7
+ data.tar.gz: 6b9b855da870f2de53a3090dcae65269986cb9bc87c5373873fff684fb57e4bb46f585a6ea3955f66d3b38b0b4b5d373a0dea650d8eb510fab36b40729e904a3
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## [1.4.0]
4
+
5
+ ### Added
6
+
7
+ - Support `/v1/metrics`, `/v1/metrics/timeline`
8
+ - Support `/v1/metrics/<id>/timeline`
9
+
3
10
  ## [1.3.1]
4
11
 
5
12
  ### Changed
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KlaviyoAPI::Collections
4
+ # This collection is used for item types that rely on
5
+ # 'next' markers to provide pagination.
6
+ class NextMarkerCollection < ActiveResource::Collection
7
+ attr_accessor :next, :count
8
+
9
+ def initialize(response = {})
10
+ @count = response.delete 'count'
11
+ @next = response.delete 'next'
12
+
13
+ @elements = response['data'] || []
14
+ end
15
+ end
16
+ end
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KlaviyoAPI::Collections
4
- class Profile < ActiveResource::Collection
4
+ # This collection is used for item types that rely on pagination and
5
+ # provide `page`, `page_size`, etc.
6
+ class PaginatedCollection < ActiveResource::Collection
5
7
  attr_accessor :total, :page, :page_size, :start, :end
6
8
 
7
9
  def initialize(response = {})
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KlaviyoAPI
4
+ # Klaviyo has the concept of "timelines" on Metrics.
5
+ # A single entry in that timeline is an Event.
6
+ class Event < Base
7
+ ORIGINAL_PREFIX = '/api/v1/metric/:metric_id/'
8
+ self.prefix = ORIGINAL_PREFIX
9
+
10
+ self.element_name = 'timeline'
11
+ self.collection_name = 'timeline'
12
+ self.collection_parser = KlaviyoAPI::Collections::NextMarkerCollection
13
+
14
+ class << self
15
+ def find_single(scope, options)
16
+ raise KlaviyoAPI::InvalidOperation, 'Cannot get single Event via API. Please use KlaviyoAPI::Event#all.'
17
+ end
18
+
19
+ def collection_path(prefix_options = {}, query_options = {})
20
+ # This needs to support both `metrics/timeline` and `metric/<id>/timeline,
21
+ # through `Event.all` and `Event.all params {metric_id: <id>}`. It gets a
22
+ # little messy.
23
+ if prefix_options.empty?
24
+ self.prefix = '/api/v1/metrics/'
25
+ end
26
+
27
+ check_prefix_options(prefix_options)
28
+
29
+ prefix_options, query_options = split_options(prefix_options) if query_options.nil?
30
+ query_options = query_options.deep_merge({ api_key: headers['api-key'] })
31
+
32
+ path = "#{prefix(prefix_options)}#{collection_name}#{format_extension}#{query_string(query_options)}"
33
+
34
+ self.prefix = ORIGINAL_PREFIX
35
+
36
+ path
37
+ end
38
+ end
39
+
40
+ def destroy
41
+ raise KlaviyoAPI::InvalidOperation, 'Cannot delete Events via API.'
42
+ end
43
+
44
+ def create
45
+ raise KlaviyoAPI::InvalidOperation, 'Cannot create Events via API.'
46
+ end
47
+
48
+ def update
49
+ raise KlaviyoAPI::InvalidOperation, 'Cannot update Events via API.'
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KlaviyoAPI
4
+ class Metric < Base
5
+ extend KlaviyoAPI::Support::Countable
6
+
7
+ self.prefix += 'v1/'
8
+
9
+ self.collection_parser = KlaviyoAPI::Collections::PaginatedCollection
10
+
11
+ has_many :events, class_name: 'KlaviyoAPI::Event'
12
+
13
+ class << self
14
+ def find_single(scope, options)
15
+ raise KlaviyoAPI::InvalidOperation, 'Cannot get single Metric via API. Please use KlaviyoAPI::Metric#all.'
16
+ end
17
+
18
+ def collection_path(prefix_options = {}, query_options = {})
19
+ super prefix_options, query_options.deep_merge({ api_key: headers['api-key'] })
20
+ end
21
+
22
+ # Get all Events for all Metrics
23
+ # https://www.klaviyo.com/docs/api/metrics#metrics-timeline
24
+ def events
25
+ KlaviyoAPI::Event.all
26
+ end
27
+ end
28
+
29
+ def destroy
30
+ raise KlaviyoAPI::InvalidOperation, 'Cannot delete Metrics via API.'
31
+ end
32
+
33
+ def create
34
+ raise KlaviyoAPI::InvalidOperation, 'Cannot create Metrics via API.'
35
+ end
36
+
37
+ def update
38
+ raise KlaviyoAPI::InvalidOperation, 'Cannot update Metrics via API.'
39
+ end
40
+ end
41
+ end
@@ -7,7 +7,7 @@ module KlaviyoAPI
7
7
  self.prefix += 'v1/'
8
8
 
9
9
  self.element_name = 'person'
10
- self.collection_parser = KlaviyoAPI::Collections::Profile
10
+ self.collection_parser = KlaviyoAPI::Collections::PaginatedCollection
11
11
 
12
12
  class << self
13
13
  def collection_path(prefix_options = {}, query_options = {})
@@ -20,11 +20,11 @@ module KlaviyoAPI
20
20
  end
21
21
 
22
22
  def destroy
23
- raise KlaviyoAPI::InvalidOperation.new 'Cannot delete Profiles via API.'
23
+ raise KlaviyoAPI::InvalidOperation, 'Cannot delete Profiles via API.'
24
24
  end
25
25
 
26
26
  def create
27
- raise KlaviyoAPI::InvalidOperation.new 'Cannot create Profiles via API.'
27
+ raise KlaviyoAPI::InvalidOperation, 'Cannot create Profiles via API.'
28
28
  end
29
29
 
30
30
  def update
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KlaviyoAPI
4
- VERSION = '1.3.1'
4
+ VERSION = '1.4.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: klaviyo_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - rewind.io
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-22 00:00:00.000000000 Z
11
+ date: 2019-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeresource
@@ -205,7 +205,8 @@ files:
205
205
  - lib/active_resource/connection_ext.rb
206
206
  - lib/klaviyo_api.rb
207
207
  - lib/klaviyo_api/collections.rb
208
- - lib/klaviyo_api/collections/profile.rb
208
+ - lib/klaviyo_api/collections/next_marker_collection.rb
209
+ - lib/klaviyo_api/collections/paginated_collection.rb
209
210
  - lib/klaviyo_api/configuration.rb
210
211
  - lib/klaviyo_api/connection.rb
211
212
  - lib/klaviyo_api/detailed_log_subscriber.rb
@@ -213,8 +214,10 @@ files:
213
214
  - lib/klaviyo_api/json_formatter.rb
214
215
  - lib/klaviyo_api/resources.rb
215
216
  - lib/klaviyo_api/resources/base.rb
217
+ - lib/klaviyo_api/resources/event.rb
216
218
  - lib/klaviyo_api/resources/list.rb
217
219
  - lib/klaviyo_api/resources/list_member.rb
220
+ - lib/klaviyo_api/resources/metric.rb
218
221
  - lib/klaviyo_api/resources/profile.rb
219
222
  - lib/klaviyo_api/resources/support/countable.rb
220
223
  - lib/klaviyo_api/session.rb