simple_segment 0.1.0.pre2 → 0.1.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/lib/simple_segment/batch.rb +22 -11
- data/lib/simple_segment/client.rb +15 -6
- data/lib/simple_segment/operations/alias.rb +1 -1
- data/lib/simple_segment/operations/group.rb +1 -1
- data/lib/simple_segment/operations/identify.rb +1 -1
- data/lib/simple_segment/operations/operation.rb +3 -3
- data/lib/simple_segment/operations/page.rb +1 -1
- data/lib/simple_segment/operations/track.rb +1 -1
- data/lib/simple_segment/request.rb +5 -6
- data/lib/simple_segment/utils.rb +4 -0
- data/lib/simple_segment/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47f4f7b0de0d4bf9985f3a4d479fdbbe9a4e1348
|
4
|
+
data.tar.gz: f826f5d41f0e0bcd4e73bf7c387abd217511b6dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 039f22d6d9008b18da395ed169ae1498e4f06d875ced8114da315f25be3389ecb876156f2548a8364073d4cab3d7ec768c8a7c143e7625a9a7d8e76e54f2c469
|
7
|
+
data.tar.gz: 7198dcfdd23555625149dd5709b6ba5c844a6d6508c5dbd00e87564d335e7029aee8dd5aac2140982f76a29374bef14cf834fb70249d1a6e54884f296dabdc9d
|
data/lib/simple_segment/batch.rb
CHANGED
@@ -2,14 +2,15 @@ module SimpleSegment
|
|
2
2
|
class Batch
|
3
3
|
include SimpleSegment::Utils
|
4
4
|
|
5
|
-
attr_reader :
|
6
|
-
attr_accessor :context, :integrations
|
5
|
+
attr_reader :client, :payload
|
7
6
|
|
8
|
-
def
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
def self.deserialize(client, payload)
|
8
|
+
new(client, symbolize_keys(payload))
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(client, payload = { batch: [] })
|
12
|
+
@client = client
|
13
|
+
@payload = payload
|
13
14
|
end
|
14
15
|
|
15
16
|
def identify(options)
|
@@ -28,20 +29,30 @@ module SimpleSegment
|
|
28
29
|
add(Operations::Group, options, __method__)
|
29
30
|
end
|
30
31
|
|
32
|
+
def context=(context)
|
33
|
+
payload[:context] = context
|
34
|
+
end
|
35
|
+
|
36
|
+
def integrations=(integrations)
|
37
|
+
payload[:integrations] = integrations
|
38
|
+
end
|
39
|
+
|
40
|
+
def serialize
|
41
|
+
payload
|
42
|
+
end
|
43
|
+
|
31
44
|
def commit
|
32
45
|
if payload[:batch].length == 0
|
33
46
|
raise ArgumentError, 'A batch must contain at least one action'
|
34
47
|
end
|
35
|
-
payload[:context] = context
|
36
|
-
payload[:integrations] = integrations
|
37
48
|
|
38
|
-
Request.new('/v1/import',
|
49
|
+
Request.new(client).post('/v1/import', payload)
|
39
50
|
end
|
40
51
|
|
41
52
|
private
|
42
53
|
|
43
54
|
def add(operation_class, options, action)
|
44
|
-
operation = operation_class.new(symbolize_keys(options)
|
55
|
+
operation = operation_class.new(client, symbolize_keys(options))
|
45
56
|
operation_payload = operation.build_payload
|
46
57
|
operation_payload[:action] = action
|
47
58
|
payload[:batch] << operation_payload
|
@@ -21,7 +21,7 @@ module SimpleSegment
|
|
21
21
|
# @option :integrations [Hash]
|
22
22
|
# @option :timestamp [#iso8601] (Time.now)
|
23
23
|
def identify(options)
|
24
|
-
Operations::Identify.new(symbolize_keys(options)
|
24
|
+
Operations::Identify.new(self, symbolize_keys(options)).call
|
25
25
|
end
|
26
26
|
|
27
27
|
# @param [Hash] options
|
@@ -33,7 +33,7 @@ module SimpleSegment
|
|
33
33
|
# @option :integrations [Hash]
|
34
34
|
# @option :timestamp [#iso8601] (Time.now)
|
35
35
|
def track(options)
|
36
|
-
Operations::Track.new(symbolize_keys(options)
|
36
|
+
Operations::Track.new(self, symbolize_keys(options)).call
|
37
37
|
end
|
38
38
|
|
39
39
|
# @param [Hash] options
|
@@ -45,7 +45,7 @@ module SimpleSegment
|
|
45
45
|
# @option :integrations [Hash]
|
46
46
|
# @option :timestamp [#iso8601] (Time.now)
|
47
47
|
def page(options)
|
48
|
-
Operations::Page.new(symbolize_keys(options)
|
48
|
+
Operations::Page.new(self, symbolize_keys(options)).call
|
49
49
|
end
|
50
50
|
|
51
51
|
# @param [Hash] options
|
@@ -57,7 +57,7 @@ module SimpleSegment
|
|
57
57
|
# @option :integrations [Hash]
|
58
58
|
# @option :timestamp [#iso8601] (Time.now)
|
59
59
|
def group(options)
|
60
|
-
Operations::Group.new(symbolize_keys(options)
|
60
|
+
Operations::Group.new(self, symbolize_keys(options)).call
|
61
61
|
end
|
62
62
|
|
63
63
|
# @param [Hash] options
|
@@ -69,11 +69,20 @@ module SimpleSegment
|
|
69
69
|
# @option :integrations [Hash]
|
70
70
|
# @option :timestamp [#iso8601] (Time.now)
|
71
71
|
def alias(options)
|
72
|
-
Operations::Alias.new(symbolize_keys(options)
|
72
|
+
Operations::Alias.new(self, symbolize_keys(options)).call
|
73
73
|
end
|
74
74
|
|
75
|
+
# @yield [batch] Yields a special batch object that can be used to group
|
76
|
+
# `identify`, `track`, `page` and `group` calls into a
|
77
|
+
# single API request.
|
78
|
+
# @example
|
79
|
+
# client.batch do |analytics|
|
80
|
+
# analytics.context = { 'foo' => 'bar' }
|
81
|
+
# analytics.identify(user_id: 'id')
|
82
|
+
# analytics.track(event: 'Delivered Package', user_id: 'id')
|
83
|
+
# end
|
75
84
|
def batch
|
76
|
-
batch = Batch.new(
|
85
|
+
batch = Batch.new(self)
|
77
86
|
yield(batch)
|
78
87
|
batch.commit
|
79
88
|
end
|
@@ -8,11 +8,11 @@ module SimpleSegment
|
|
8
8
|
}
|
9
9
|
}.freeze
|
10
10
|
|
11
|
-
attr_reader :options, :
|
11
|
+
attr_reader :options, :request
|
12
12
|
|
13
|
-
def initialize(options = {}
|
13
|
+
def initialize(client, options = {})
|
14
14
|
@options = options
|
15
|
-
@
|
15
|
+
@request = Request.new(client)
|
16
16
|
end
|
17
17
|
|
18
18
|
def call
|
@@ -6,15 +6,14 @@ module SimpleSegment
|
|
6
6
|
'accept' => 'application/json'
|
7
7
|
}.freeze
|
8
8
|
|
9
|
-
attr_reader :
|
9
|
+
attr_reader :write_key, :error_handler
|
10
10
|
|
11
|
-
def initialize(
|
12
|
-
@
|
13
|
-
@
|
14
|
-
@error_handler = config.on_error
|
11
|
+
def initialize(client)
|
12
|
+
@write_key = client.config.write_key
|
13
|
+
@error_handler = client.config.on_error
|
15
14
|
end
|
16
15
|
|
17
|
-
def post(payload, headers: DEFAULT_HEADERS)
|
16
|
+
def post(path, payload, headers: DEFAULT_HEADERS)
|
18
17
|
response, status_code, response_body = nil, nil, nil
|
19
18
|
uri = URI(BASE_URL)
|
20
19
|
payload = JSON.generate(payload)
|
data/lib/simple_segment/utils.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_segment
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mikhail Topolskiy
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -141,9 +141,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
141
141
|
version: '0'
|
142
142
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
143
|
requirements:
|
144
|
-
- - "
|
144
|
+
- - ">="
|
145
145
|
- !ruby/object:Gem::Version
|
146
|
-
version:
|
146
|
+
version: '0'
|
147
147
|
requirements: []
|
148
148
|
rubyforge_project:
|
149
149
|
rubygems_version: 2.6.2
|