parallel588-klaviyo 0.5.0 → 0.6.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
  SHA1:
3
- metadata.gz: 8c1590f38a286fc1aa47477ecd21dd41c0b8402f
4
- data.tar.gz: d0ccd4e0cde4dd5fabea415445f6906321ff08c1
3
+ metadata.gz: c48e98339ae3627124429dce0eccb27092ed6643
4
+ data.tar.gz: b10d9a87e4d3bf4de4bc28e952b5cb59cc8680d1
5
5
  SHA512:
6
- metadata.gz: 5faa459e25ce7f6ee3f88a7d459edad758f2941d287db0c948bb4ffd36154dc19960d41705fc705be975f2b400c7287f6103c13171edbe7dbec2bf1f13a34067
7
- data.tar.gz: 8ba7172374d3254aa53fb6dab6ec577314b52342378c694fe5f10dd68353c4369a51d37b534b75e8ffaf207152da728f9468e9133990e52ff471798b338bf40d
6
+ metadata.gz: a8f5f95e511b87f2639b33cd21b09ebb71711ff2f6554e7e08d0757fa9402d1f143f8773654faf7fd3ce40f959e8836a22fa280d61f60938d78fb33d46869047
7
+ data.tar.gz: c74da73b0beea64f332d37922e6b233722ff26e45b354f89eacd7bd8e8a672821ec46006e785175fc095c5a6131c7fcc9385b2675a734950329d9dc8b546b2e7
@@ -0,0 +1,116 @@
1
+ require_relative 'collection'
2
+ require_relative 'entry'
3
+ module Klaviyo
4
+ module Lists
5
+ # https://www.klaviyo.com/docs/api/lists
6
+ #
7
+ module ApiOperations
8
+
9
+ def all(client:, page: 0, per: 50)
10
+ Collection.new(
11
+ client.conn.get(
12
+ '/api/v1/lists',
13
+ api_key: client.api_key,
14
+ page: page, count: per
15
+ ).body)
16
+ end
17
+
18
+ def find(client:, id:)
19
+ Entry.new(
20
+ client.conn.get(
21
+ "/api/v1/list/#{id}", api_key: client.api_key
22
+ ).body)
23
+ end
24
+
25
+ def create(client:, name:, list_type: 'standart')
26
+ res = client.conn.post(
27
+ '/api/v1/lists',
28
+ api_key: client.api_key,
29
+ name: name,
30
+ list_type: list_type
31
+ )
32
+ Entry(res.body)
33
+ end
34
+
35
+ def update(client:, id:, name:)
36
+ res = client.conn.put(
37
+ "/api/v1/list/#{id}",
38
+ api_key: client.api_key,
39
+ name: name
40
+ )
41
+ Entry.new(res.body)
42
+ end
43
+
44
+ def delete(client:, id:)
45
+ res = client.conn.delete(
46
+ "/api/v1/list/#{id}",
47
+ api_key: client.api_key
48
+ )
49
+ Entry.new(res.body)
50
+ end
51
+
52
+ def include_member_in_list?(client:, id:, email:)
53
+ client.conn.get(
54
+ "/api/v1/list/#{id}/members",
55
+ api_key: client.api_key,
56
+ email: email
57
+ )
58
+ end
59
+
60
+ def include_member_in_segment?(client:, segment_id:, email:)
61
+ client.conn.get(
62
+ "/api/v1/segment/#{segment_id}/members",
63
+ api_key: client.api_key,
64
+ email: email
65
+ )
66
+ end
67
+
68
+ #
69
+ # @id - list id
70
+ #
71
+ def subscribe(client:, id:, email:, properties: {}, confirm_optin: true)
72
+ client.conn.post(
73
+ "/api/v1/list/#{id}/members",
74
+ api_key: client.api_key,
75
+ email: email,
76
+ properties: properties,
77
+ confirm_optin: confirm_optin
78
+ )
79
+ end
80
+
81
+ def unsubscribe(client:, id:, email:, ts: Time.now.to_i)
82
+ client.conn.post(
83
+ "/api/v1/list/#{id}/members/exclude",
84
+ api_key: client.api_key,
85
+ email: email,
86
+ timestamp: ts
87
+ )
88
+ end
89
+
90
+ #
91
+ # @id - list id
92
+ #
93
+ def batch_subscribe(client:, id:, batch:, confirm_optin: true)
94
+ client.conn.post(
95
+ "/api/v1/list/#{id}/members/batch",
96
+ api_key: client.api_key,
97
+ batch: batch,
98
+ confirm_optin: confirm_optin
99
+ )
100
+ end
101
+
102
+ #
103
+ # @reason - unsubscribed, bounced, invalid_email, reported_spam and manually_excluded.
104
+ # @sort - asc\desc
105
+ #
106
+ def unsubscribes(client:, id:, reason: 'unsubscribed', sort: 'asc')
107
+ client.conn.post(
108
+ "/api/v1/list/#{id}/exclusions",
109
+ api_key: client.api_key,
110
+ reason: reason,
111
+ sort: sort
112
+ )
113
+ end
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,21 @@
1
+ require_relative 'entry'
2
+ module Klaviyo
3
+ module Lists
4
+
5
+ class Collection
6
+ attr_reader :data
7
+
8
+ def initialize(data)
9
+ @data = data
10
+ end
11
+
12
+ def items
13
+ @items ||= data.fetch('data') { [] }.map { |j| Entry.new(j) }
14
+ end
15
+
16
+ def meta
17
+ @meta ||= data.except('data')
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,12 @@
1
+ module Klaviyo
2
+ module Lists
3
+
4
+ class Entry
5
+ attr_reader :data
6
+
7
+ def initialize(data)
8
+ @data = data
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,8 @@
1
+ require_relative 'lists/api_operations'
2
+ require_relative 'lists/collection'
3
+
4
+ module Klaviyo
5
+ module Lists
6
+ extend ApiOperations
7
+ end
8
+ end
@@ -17,6 +17,28 @@ module Klaviyo
17
17
  )
18
18
  Result.new(res.body)
19
19
  end
20
+
21
+ #
22
+ # @reason - unsubscribed, bounced, invalid_email, reported_spam, manually_excluded
23
+ # @sort - asc|desc
24
+ #
25
+ def exclusions(client:, reason: 'unsubscribed', sort: 'asc')
26
+ client.conn.get(
27
+ '/api/v1/people/exclusions',
28
+ api_key: client.api_key,
29
+ reason: reason,
30
+ sort: sort
31
+ )
32
+ end
33
+
34
+ def exclude(client:, email:, ts: Time.now.to_i)
35
+ client.conn.post(
36
+ '/api/v1/people/exclusions',
37
+ api_key: client.api_key,
38
+ email: email,
39
+ timestamp: ts
40
+ )
41
+ end
20
42
  end
21
43
 
22
44
  extend ApiOperations
@@ -1,3 +1,3 @@
1
1
  module Klaviyo
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
data/lib/klaviyo.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'klaviyo/version'
2
2
  require 'klaviyo/client'
3
3
  require 'klaviyo/templates'
4
+ require 'klaviyo/lists'
4
5
  require 'klaviyo/event'
5
6
  require 'klaviyo/people'
6
7
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parallel588-klaviyo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maxim Pechnikov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-06 00:00:00.000000000 Z
11
+ date: 2016-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: virtus
@@ -169,6 +169,10 @@ files:
169
169
  - lib/klaviyo.rb
170
170
  - lib/klaviyo/client.rb
171
171
  - lib/klaviyo/event.rb
172
+ - lib/klaviyo/lists.rb
173
+ - lib/klaviyo/lists/api_operations.rb
174
+ - lib/klaviyo/lists/collection.rb
175
+ - lib/klaviyo/lists/entry.rb
172
176
  - lib/klaviyo/people.rb
173
177
  - lib/klaviyo/templates.rb
174
178
  - lib/klaviyo/templates/api_operations.rb