parallel588-klaviyo 0.6.0 → 0.7.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: c48e98339ae3627124429dce0eccb27092ed6643
4
- data.tar.gz: b10d9a87e4d3bf4de4bc28e952b5cb59cc8680d1
3
+ metadata.gz: ca42f71d0ad66aa987267caa2a80c6211277bd24
4
+ data.tar.gz: 3d3334697ff2b0130f90252f7996506cfc601037
5
5
  SHA512:
6
- metadata.gz: a8f5f95e511b87f2639b33cd21b09ebb71711ff2f6554e7e08d0757fa9402d1f143f8773654faf7fd3ce40f959e8836a22fa280d61f60938d78fb33d46869047
7
- data.tar.gz: c74da73b0beea64f332d37922e6b233722ff26e45b354f89eacd7bd8e8a672821ec46006e785175fc095c5a6131c7fcc9385b2675a734950329d9dc8b546b2e7
6
+ metadata.gz: e8a4f80d8ad00dc698732e2eae1558cbcb017c93cd43f2eeae88798d4a61090a8ecbdbd34232683f4de73ec1681bce4722ee3e22ff8ea05b42ee06d7a4df7c59
7
+ data.tar.gz: 2db5c4d013e7d6b183820ac04bcca622d282d70ff1118113346456646177329d8675e215c0c1bdd45c56c1ed0a91939a6f7aae697ac7a11ce72b594da61c52db
@@ -0,0 +1,102 @@
1
+ module Klaviyo
2
+ module People
3
+ # https://www.klaviyo.com/docs/api/people
4
+ #
5
+ module ApiOperations
6
+ Result = Struct.new(:response) do
7
+ def success?
8
+ response.to_s == '1'
9
+ end
10
+ end
11
+ ErrorResult = Struct.new(:response) do
12
+ def success?; false; end
13
+ def status; response['status']; end
14
+ def message; response['message']; end
15
+ end
16
+
17
+ Person = Struct.new(:attrs) do
18
+ def method_missing(method_name, *arguments, &block)
19
+ if attrs.key?(method_name.to_s)
20
+ attrs[method_name.to_s]
21
+ elsif attrs.key?("$#{method_name}")
22
+ attrs["$#{method_name}"]
23
+ else
24
+ super
25
+ end
26
+ end
27
+ end
28
+
29
+ # https://www.klaviyo.com/docs/http-api#people
30
+ # invoke(:people, :identify, properties: { '$email': 'useremail@ua.com' })
31
+ #
32
+ def identify(client:, properties: {})
33
+ res = client.conn.get(
34
+ '/api/identify',
35
+ client.build_params(properties: properties)
36
+ )
37
+ Result.new(res.body)
38
+ end
39
+
40
+ #
41
+ # @reason - unsubscribed, bounced, invalid_email, reported_spam, manually_excluded
42
+ # @sort - asc|desc
43
+ #
44
+ def exclusions(client:, reason: 'unsubscribed', sort: 'asc')
45
+ client.conn.get(
46
+ '/api/v1/people/exclusions',
47
+ api_key: client.api_key,
48
+ reason: reason,
49
+ sort: sort
50
+ )
51
+ end
52
+
53
+ def exclude(client:, email:, ts: Time.now.to_i)
54
+ client.conn.post(
55
+ '/api/v1/people/exclusions',
56
+ api_key: client.api_key,
57
+ email: email,
58
+ timestamp: ts
59
+ )
60
+ end
61
+
62
+ def find(client:, id:)
63
+ res = client.conn.get("/api/v1/person/#{id}", api_key: client.api_key)
64
+ if res.success?
65
+ Person.new(res.body)
66
+ else
67
+ ErrorResult.new(res.body)
68
+ end
69
+ end
70
+
71
+ def update(client:, id:, attrs: {})
72
+ client.conn.put(
73
+ "/api/v1/person/#{id}",
74
+ { api_key: client.api_key }.merge(attrs)
75
+ )
76
+ end
77
+
78
+ def events(client:, id:, sort: 'desc', per: 100, since: Time.now.to_i)
79
+ client.conn.get(
80
+ "/api/v1/person/#{id}/metrics/timeline",
81
+ api_key: client.api_key,
82
+ sort: sort,
83
+ count: per,
84
+ since: since
85
+ )
86
+ end
87
+
88
+ def metric_events(client:, id:, metric_id:,
89
+ sort: 'desc', per: 100,
90
+ since: Time.now.to_i)
91
+ client.conn.get(
92
+ "/api/v1/person/#{id}/metric/#{metric_id}/timeline",
93
+ api_key: client.api_key,
94
+ sort: sort,
95
+ count: per,
96
+ since: since
97
+ )
98
+ end
99
+
100
+ end
101
+ end
102
+ end
@@ -1,46 +1,6 @@
1
+ require_relative 'people/api_operations'
1
2
  module Klaviyo
2
3
  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
-
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
42
- end
43
-
44
4
  extend ApiOperations
45
5
  end
46
6
  end
@@ -1,3 +1,3 @@
1
1
  module Klaviyo
2
- VERSION = "0.6.0"
2
+ VERSION = "0.7.0"
3
3
  end
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.6.0
4
+ version: 0.7.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-07 00:00:00.000000000 Z
11
+ date: 2016-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: virtus
@@ -174,6 +174,7 @@ files:
174
174
  - lib/klaviyo/lists/collection.rb
175
175
  - lib/klaviyo/lists/entry.rb
176
176
  - lib/klaviyo/people.rb
177
+ - lib/klaviyo/people/api_operations.rb
177
178
  - lib/klaviyo/templates.rb
178
179
  - lib/klaviyo/templates/api_operations.rb
179
180
  - lib/klaviyo/version.rb