analytics-ruby 2.2.8 → 2.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: 03a801260cc008997d94b569c3e2b2aa1892b79f544deb74d9f5687c3f593a78
4
- data.tar.gz: d66c592b1f0083a2f2823536797882aec75a6876f3dcc920ef33cc37314e2a82
3
+ metadata.gz: 783cffe105e269e46ad1a00c48deef3a8259a909ea0c5840a187cd37ec13f00d
4
+ data.tar.gz: d2255cdde8b5ea28ade9b3c4a58459d5488423ad53241d284bf0b3d883e97863
5
5
  SHA512:
6
- metadata.gz: c07bd7e741aa196de2d73babc5e9f369e5b607920e0ea48a4646d751fa584bf621f5da5caa4bffb757ecc3c80accdbeddf4d630d6c00369d00a883e8f03c26ba
7
- data.tar.gz: a931f2c5acea9ab5ff70bbe848cfa0b03a3a74ab45cd30064dd3086e8c183608dd50c6b25bf12b619584c996416546ff7a2601d911e51601dfda9d2fb12f1102
6
+ metadata.gz: f81af66cb669884d651cc24972795e72141696b13458786593d82b31f15d5c3589ebf2047e98f1a3d3ec276fc4d7e705436865bd0e349643161bfa7356618b46
7
+ data.tar.gz: 7c477ea2e3cfb3fe4c7540d649c33e2efd906690a32841d1a549820a0575818637611e389f47c3644ec0380dab3cfdf9ebf124b095a29066d7962a5322f2d003
@@ -4,7 +4,7 @@ require 'segment/analytics/utils'
4
4
  require 'segment/analytics/field_parser'
5
5
  require 'segment/analytics/client'
6
6
  require 'segment/analytics/worker'
7
- require 'segment/analytics/request'
7
+ require 'segment/analytics/transport'
8
8
  require 'segment/analytics/response'
9
9
  require 'segment/analytics/logging'
10
10
 
@@ -18,7 +18,7 @@ module Segment
18
18
  # @option options [Boolean] :stub (false) If true, requests don't hit the
19
19
  # server and are stubbed to be successful.
20
20
  def initialize(options = {})
21
- Request.stub = options[:stub] if options.has_key?(:stub)
21
+ Transport.stub = options[:stub] if options.has_key?(:stub)
22
22
  @client = Segment::Analytics::Client.new options
23
23
  end
24
24
 
@@ -9,13 +9,11 @@ require 'json'
9
9
 
10
10
  module Segment
11
11
  class Analytics
12
- class Request
12
+ class Transport
13
13
  include Segment::Analytics::Defaults::Request
14
14
  include Segment::Analytics::Utils
15
15
  include Segment::Analytics::Logging
16
16
 
17
- # public: Creates a new request object to send analytics batch
18
- #
19
17
  def initialize(options = {})
20
18
  options[:host] ||= HOST
21
19
  options[:port] ||= PORT
@@ -34,10 +32,10 @@ module Segment
34
32
  @http = http
35
33
  end
36
34
 
37
- # public: Posts the write key and batch of messages to the API.
35
+ # Sends a batch of messages to the API
38
36
  #
39
- # returns - Response of the status and error if it exists
40
- def post(write_key, batch)
37
+ # @return [Response] API response
38
+ def send(write_key, batch)
41
39
  logger.debug("Sending request for #{batch.length} items")
42
40
 
43
41
  last_response, exception = retry_with_backoff(@retries) do
@@ -59,6 +57,11 @@ module Segment
59
57
  end
60
58
  end
61
59
 
60
+ # Closes a persistent connection if it exists
61
+ def shutdown
62
+ @http.finish if @http.started?
63
+ end
64
+
62
65
  private
63
66
 
64
67
  def should_retry_request?(status_code, body)
@@ -117,6 +120,7 @@ module Segment
117
120
 
118
121
  [200, '{}']
119
122
  else
123
+ @http.start unless @http.started? # Maintain a persistent connection
120
124
  response = @http.request(request, payload)
121
125
  [response.code.to_i, response.body]
122
126
  end
@@ -64,12 +64,8 @@ module Segment
64
64
  end
65
65
  end
66
66
 
67
- def time_in_iso8601(time, fraction_digits = 3)
68
- fraction = if fraction_digits > 0
69
- ('.%06i' % time.usec)[0, fraction_digits + 1]
70
- end
71
-
72
- "#{time.strftime('%Y-%m-%dT%H:%M:%S')}#{fraction}#{formatted_offset(time, true, 'Z')}"
67
+ def time_in_iso8601(time)
68
+ "#{time.strftime('%Y-%m-%dT%H:%M:%S.%6N')}#{formatted_offset(time, true, 'Z')}"
73
69
  end
74
70
 
75
71
  def date_in_iso8601(date)
@@ -1,5 +1,5 @@
1
1
  module Segment
2
2
  class Analytics
3
- VERSION = '2.2.8'
3
+ VERSION = '2.3.0'
4
4
  end
5
5
  end
@@ -1,6 +1,6 @@
1
1
  require 'segment/analytics/defaults'
2
2
  require 'segment/analytics/message_batch'
3
- require 'segment/analytics/request'
3
+ require 'segment/analytics/transport'
4
4
  require 'segment/analytics/utils'
5
5
 
6
6
  module Segment
@@ -29,6 +29,7 @@ module Segment
29
29
  batch_size = options[:batch_size] || Defaults::MessageBatch::MAX_SIZE
30
30
  @batch = MessageBatch.new(batch_size)
31
31
  @lock = Mutex.new
32
+ @transport = Transport.new
32
33
  end
33
34
 
34
35
  # public: Continuously runs the loop to check for new events
@@ -41,11 +42,13 @@ module Segment
41
42
  consume_message_from_queue! until @batch.full? || @queue.empty?
42
43
  end
43
44
 
44
- res = Request.new.post @write_key, @batch
45
+ res = @transport.send @write_key, @batch
45
46
  @on_error.call(res.status, res.error) unless res.status == 200
46
47
 
47
48
  @lock.synchronize { @batch.clear }
48
49
  end
50
+ ensure
51
+ @transport.shutdown
49
52
  end
50
53
 
51
54
  # public: Check whether we have outstanding requests.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: analytics-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.8
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Segment.io
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-10 00:00:00.000000000 Z
11
+ date: 2021-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander
@@ -139,8 +139,8 @@ files:
139
139
  - lib/segment/analytics/field_parser.rb
140
140
  - lib/segment/analytics/logging.rb
141
141
  - lib/segment/analytics/message_batch.rb
142
- - lib/segment/analytics/request.rb
143
142
  - lib/segment/analytics/response.rb
143
+ - lib/segment/analytics/transport.rb
144
144
  - lib/segment/analytics/utils.rb
145
145
  - lib/segment/analytics/version.rb
146
146
  - lib/segment/analytics/worker.rb
@@ -163,8 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
163
163
  - !ruby/object:Gem::Version
164
164
  version: '0'
165
165
  requirements: []
166
- rubyforge_project:
167
- rubygems_version: 2.7.7
166
+ rubygems_version: 3.0.8
168
167
  signing_key:
169
168
  specification_version: 4
170
169
  summary: Segment.io analytics library