analytics-ruby 2.0.5 → 2.4.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 +7 -0
- data/bin/analytics +108 -0
- data/lib/analytics-ruby.rb +1 -0
- data/lib/segment/analytics/backoff_policy.rb +49 -0
- data/lib/segment/analytics/client.rb +121 -256
- data/lib/segment/analytics/defaults.rb +20 -4
- data/lib/segment/analytics/field_parser.rb +192 -0
- data/lib/segment/analytics/logging.rb +36 -11
- data/lib/segment/analytics/message_batch.rb +72 -0
- data/lib/segment/analytics/response.rb +0 -1
- data/lib/segment/analytics/test_queue.rb +56 -0
- data/lib/segment/analytics/transport.rb +138 -0
- data/lib/segment/analytics/utils.rb +20 -19
- data/lib/segment/analytics/version.rb +1 -1
- data/lib/segment/analytics/worker.rb +20 -10
- data/lib/segment/analytics.rb +15 -6
- metadata +101 -55
- data/Gemfile +0 -2
- data/Gemfile.lock +0 -60
- data/History.md +0 -124
- data/Makefile +0 -8
- data/README.md +0 -39
- data/Rakefile +0 -7
- data/analytics-ruby.gemspec +0 -23
- data/lib/segment/analytics/request.rb +0 -84
- data/spec/segment/analytics/client_spec.rb +0 -299
- data/spec/segment/analytics/worker_spec.rb +0 -96
- data/spec/segment/analytics_spec.rb +0 -103
- data/spec/spec_helper.rb +0 -81
data/lib/segment/analytics.rb
CHANGED
@@ -1,20 +1,29 @@
|
|
1
|
+
require 'segment/analytics/version'
|
1
2
|
require 'segment/analytics/defaults'
|
2
3
|
require 'segment/analytics/utils'
|
3
|
-
require 'segment/analytics/
|
4
|
+
require 'segment/analytics/field_parser'
|
4
5
|
require 'segment/analytics/client'
|
5
6
|
require 'segment/analytics/worker'
|
6
|
-
require 'segment/analytics/
|
7
|
+
require 'segment/analytics/transport'
|
7
8
|
require 'segment/analytics/response'
|
8
9
|
require 'segment/analytics/logging'
|
10
|
+
require 'segment/analytics/test_queue'
|
9
11
|
|
10
12
|
module Segment
|
11
13
|
class Analytics
|
12
|
-
|
13
|
-
|
14
|
+
# Initializes a new instance of {Segment::Analytics::Client}, to which all
|
15
|
+
# method calls are proxied.
|
16
|
+
#
|
17
|
+
# @param options includes options that are passed down to
|
18
|
+
# {Segment::Analytics::Client#initialize}
|
19
|
+
# @option options [Boolean] :stub (false) If true, requests don't hit the
|
20
|
+
# server and are stubbed to be successful.
|
21
|
+
def initialize(options = {})
|
22
|
+
Transport.stub = options[:stub] if options.has_key?(:stub)
|
14
23
|
@client = Segment::Analytics::Client.new options
|
15
24
|
end
|
16
25
|
|
17
|
-
def method_missing
|
26
|
+
def method_missing(message, *args, &block)
|
18
27
|
if @client.respond_to? message
|
19
28
|
@client.send message, *args, &block
|
20
29
|
else
|
@@ -22,7 +31,7 @@ module Segment
|
|
22
31
|
end
|
23
32
|
end
|
24
33
|
|
25
|
-
def
|
34
|
+
def respond_to_missing?(method_name, include_private = false)
|
26
35
|
@client.respond_to?(method_name) || super
|
27
36
|
end
|
28
37
|
|
metadata
CHANGED
@@ -1,125 +1,171 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: analytics-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
5
|
-
prerelease:
|
4
|
+
version: 2.4.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Segment.io
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2021-05-05 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
16
|
-
requirement:
|
17
|
-
none: false
|
14
|
+
name: commander
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- - ~>
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version: '
|
19
|
+
version: '4.4'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.4'
|
25
27
|
- !ruby/object:Gem::Dependency
|
26
|
-
name:
|
27
|
-
requirement:
|
28
|
-
none: false
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
|
-
- - ~>
|
31
|
+
- - "~>"
|
31
32
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
33
|
+
version: '10.3'
|
33
34
|
type: :development
|
34
35
|
prerelease: false
|
35
|
-
version_requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.3'
|
36
41
|
- !ruby/object:Gem::Dependency
|
37
42
|
name: rspec
|
38
|
-
requirement:
|
39
|
-
none: false
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
40
44
|
requirements:
|
41
|
-
- - ~>
|
45
|
+
- - "~>"
|
42
46
|
- !ruby/object:Gem::Version
|
43
|
-
version: '
|
47
|
+
version: '3.0'
|
44
48
|
type: :development
|
45
49
|
prerelease: false
|
46
|
-
version_requirements:
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
47
55
|
- !ruby/object:Gem::Dependency
|
48
56
|
name: tzinfo
|
49
|
-
requirement:
|
50
|
-
none: false
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
51
58
|
requirements:
|
52
|
-
- - =
|
59
|
+
- - '='
|
53
60
|
- !ruby/object:Gem::Version
|
54
61
|
version: 1.2.1
|
55
62
|
type: :development
|
56
63
|
prerelease: false
|
57
|
-
version_requirements:
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.2.1
|
58
69
|
- !ruby/object:Gem::Dependency
|
59
70
|
name: activesupport
|
60
|
-
requirement:
|
61
|
-
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 4.1.11
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
62
79
|
requirements:
|
63
|
-
- -
|
80
|
+
- - "~>"
|
64
81
|
- !ruby/object:Gem::Version
|
65
|
-
version:
|
66
|
-
|
82
|
+
version: 4.1.11
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: oj
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
67
88
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
89
|
+
version: 3.6.2
|
69
90
|
type: :development
|
70
91
|
prerelease: false
|
71
|
-
version_requirements:
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 3.6.2
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.51.0
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.51.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: codecov
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.1.4
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.1.4
|
72
125
|
description: The Segment.io ruby analytics library
|
73
126
|
email: friends@segment.io
|
74
|
-
executables:
|
127
|
+
executables:
|
128
|
+
- analytics
|
75
129
|
extensions: []
|
76
130
|
extra_rdoc_files: []
|
77
131
|
files:
|
78
|
-
- analytics
|
79
|
-
- analytics-ruby.
|
80
|
-
-
|
81
|
-
-
|
82
|
-
-
|
132
|
+
- bin/analytics
|
133
|
+
- lib/analytics-ruby.rb
|
134
|
+
- lib/segment.rb
|
135
|
+
- lib/segment/analytics.rb
|
136
|
+
- lib/segment/analytics/backoff_policy.rb
|
83
137
|
- lib/segment/analytics/client.rb
|
84
138
|
- lib/segment/analytics/defaults.rb
|
139
|
+
- lib/segment/analytics/field_parser.rb
|
85
140
|
- lib/segment/analytics/logging.rb
|
86
|
-
- lib/segment/analytics/
|
141
|
+
- lib/segment/analytics/message_batch.rb
|
87
142
|
- lib/segment/analytics/response.rb
|
143
|
+
- lib/segment/analytics/test_queue.rb
|
144
|
+
- lib/segment/analytics/transport.rb
|
88
145
|
- lib/segment/analytics/utils.rb
|
89
146
|
- lib/segment/analytics/version.rb
|
90
147
|
- lib/segment/analytics/worker.rb
|
91
|
-
- lib/segment/analytics.rb
|
92
|
-
- lib/segment.rb
|
93
|
-
- Makefile
|
94
|
-
- Rakefile
|
95
|
-
- README.md
|
96
|
-
- spec/segment/analytics/client_spec.rb
|
97
|
-
- spec/segment/analytics/worker_spec.rb
|
98
|
-
- spec/segment/analytics_spec.rb
|
99
|
-
- spec/spec_helper.rb
|
100
148
|
homepage: https://github.com/segmentio/analytics-ruby
|
101
149
|
licenses:
|
102
150
|
- MIT
|
151
|
+
metadata: {}
|
103
152
|
post_install_message:
|
104
153
|
rdoc_options: []
|
105
154
|
require_paths:
|
106
155
|
- lib
|
107
156
|
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
-
none: false
|
109
157
|
requirements:
|
110
|
-
- -
|
158
|
+
- - ">="
|
111
159
|
- !ruby/object:Gem::Version
|
112
|
-
version: '0'
|
160
|
+
version: '2.0'
|
113
161
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
-
none: false
|
115
162
|
requirements:
|
116
|
-
- -
|
163
|
+
- - ">="
|
117
164
|
- !ruby/object:Gem::Version
|
118
165
|
version: '0'
|
119
166
|
requirements: []
|
120
|
-
|
121
|
-
rubygems_version: 1.8.11
|
167
|
+
rubygems_version: 3.0.8
|
122
168
|
signing_key:
|
123
|
-
specification_version:
|
169
|
+
specification_version: 4
|
124
170
|
summary: Segment.io analytics library
|
125
171
|
test_files: []
|
data/Gemfile
DELETED
data/Gemfile.lock
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
analytics-ruby (2.0.5)
|
5
|
-
json (~> 1.7)
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: http://rubygems.org/
|
9
|
-
specs:
|
10
|
-
activesupport (3.2.18)
|
11
|
-
i18n (~> 0.6, >= 0.6.4)
|
12
|
-
multi_json (~> 1.0)
|
13
|
-
diff-lcs (1.2.5)
|
14
|
-
i18n (0.6.9)
|
15
|
-
json (1.8.1)
|
16
|
-
multi_json (1.10.1)
|
17
|
-
predicated (0.2.6)
|
18
|
-
rake (10.3.1)
|
19
|
-
rspec (2.14.1)
|
20
|
-
rspec-core (~> 2.14.0)
|
21
|
-
rspec-expectations (~> 2.14.0)
|
22
|
-
rspec-mocks (~> 2.14.0)
|
23
|
-
rspec-core (2.14.8)
|
24
|
-
rspec-expectations (2.14.5)
|
25
|
-
diff-lcs (>= 1.1.3, < 2.0)
|
26
|
-
rspec-mocks (2.14.6)
|
27
|
-
ruby2ruby (2.1.0)
|
28
|
-
ruby_parser (~> 3.1)
|
29
|
-
sexp_processor (~> 4.0)
|
30
|
-
ruby_parser (3.6.1)
|
31
|
-
sexp_processor (~> 4.1)
|
32
|
-
sexp_processor (4.4.3)
|
33
|
-
thread_safe (0.3.4)
|
34
|
-
thread_safe (0.3.4-java)
|
35
|
-
tzinfo (1.2.1)
|
36
|
-
thread_safe (~> 0.1)
|
37
|
-
wrong (0.7.1)
|
38
|
-
diff-lcs (~> 1.2.5)
|
39
|
-
predicated (~> 0.2.6)
|
40
|
-
ruby2ruby (>= 2.0.1)
|
41
|
-
ruby_parser (>= 3.0.1)
|
42
|
-
sexp_processor (>= 4.0)
|
43
|
-
wrong (0.7.1-java)
|
44
|
-
diff-lcs (~> 1.2.5)
|
45
|
-
predicated (~> 0.2.6)
|
46
|
-
ruby2ruby (>= 2.0.1)
|
47
|
-
ruby_parser (>= 3.0.1)
|
48
|
-
sexp_processor (>= 4.0)
|
49
|
-
|
50
|
-
PLATFORMS
|
51
|
-
java
|
52
|
-
ruby
|
53
|
-
|
54
|
-
DEPENDENCIES
|
55
|
-
activesupport (>= 3.0.0, < 4.0.0)
|
56
|
-
analytics-ruby!
|
57
|
-
rake (~> 10.3)
|
58
|
-
rspec (~> 2.0)
|
59
|
-
tzinfo (= 1.2.1)
|
60
|
-
wrong (~> 0.0)
|
data/History.md
DELETED
@@ -1,124 +0,0 @@
|
|
1
|
-
2.0.4 / 2014-06-11
|
2
|
-
==================
|
3
|
-
* fix: isofying trait dates in #group
|
4
|
-
|
5
|
-
2.0.3 / 2014-06-04
|
6
|
-
==================
|
7
|
-
* fix: undefined method `is_requesting?' for nil:NilClass when calling flush (#51)
|
8
|
-
|
9
|
-
2.0.2 / 2014-05-30
|
10
|
-
==================
|
11
|
-
* fix: formatting ios dates
|
12
|
-
* fix: respond_to? implementation
|
13
|
-
* add: able to stub requests by setting STUB env var
|
14
|
-
|
15
|
-
2.0.1 / 2014-05-15
|
16
|
-
==================
|
17
|
-
* add: namespace under Segment::Analytics
|
18
|
-
* add: can create multiple instances with creator method (rather than
|
19
|
-
having a singleton)
|
20
|
-
* add: logging with Logger instance or Rails.logger if available
|
21
|
-
* add: able to stub requests so they just log and don't hit the server
|
22
|
-
* fix: worker continues running across forked processes
|
23
|
-
* fix: removed usage of ActiveSupport methods since its not a dependency
|
24
|
-
* fix: sending data that matches segment's new api spec
|
25
|
-
|
26
|
-
(there is no v2.0.0)
|
27
|
-
|
28
|
-
1.1.0 / 2014-04-17
|
29
|
-
==================
|
30
|
-
* adding .initialized? by [@lumberj](https://github.com/lumberj)
|
31
|
-
|
32
|
-
1.0.0 / 2014-03-12
|
33
|
-
==================
|
34
|
-
* removing faraday dependency
|
35
|
-
|
36
|
-
0.6.0 / 2014-02-19
|
37
|
-
==================
|
38
|
-
* adding .group(), .page(), and .screen() calls
|
39
|
-
* relaxing faraday dependency, fixes #31
|
40
|
-
|
41
|
-
0.5.4 / 2013-12-31
|
42
|
-
==================
|
43
|
-
* Add `requestId` fields to all requests for tracing.
|
44
|
-
|
45
|
-
0.5.3 / 2013-12-31
|
46
|
-
==================
|
47
|
-
* Allow the consumer thread to shut down so it won't remain live in hot deploy scenarios. This fixes the jruby memory leak by [@nirvdrum](https://github.com/nirvdrum)
|
48
|
-
|
49
|
-
0.5.2 / 2013-12-02
|
50
|
-
==================
|
51
|
-
* adding `sleep` backoff between connection retries
|
52
|
-
|
53
|
-
0.5.1 / 2013-11-22
|
54
|
-
==================
|
55
|
-
* adding retries for connection hangups
|
56
|
-
|
57
|
-
0.5.0 / 2013-10-03
|
58
|
-
==================
|
59
|
-
* Removing global Analytics constant in favor of adding it to our config. NOTE: If you are upgrading from a previous version and want to continue using the `Analytics` namespace, you'll have to add `Analytics = AnalyticsRuby` to your config. Otherwise you WILL NOT be sending analytics data. See the [setup docs for more info](https://segment.io/libraries/ruby)
|
60
|
-
|
61
|
-
0.4.0 / 2013-08-30
|
62
|
-
==================
|
63
|
-
* Adding support and tests for 1.8.7
|
64
|
-
|
65
|
-
0.3.4 / 2013-08-26
|
66
|
-
==================
|
67
|
-
* Pass `Time` values as iso8601 timestamp strings
|
68
|
-
|
69
|
-
0.3.3 / 2013-08-02
|
70
|
-
==================
|
71
|
-
* Allow init/track/identify/alias to accept strings as keys. by [@shipstar](https://github.com/shipstar)
|
72
|
-
|
73
|
-
0.3.2 / 2013-05-28
|
74
|
-
==================
|
75
|
-
* Adding faraday timeout by [@yanchenyun](https://github.com/yangchenyun)
|
76
|
-
|
77
|
-
0.3.1 / 2013-04-29
|
78
|
-
==================
|
79
|
-
* Adding check for properties to be a Hash
|
80
|
-
|
81
|
-
0.3.0 / 2013-04-05
|
82
|
-
==================
|
83
|
-
* Adding alias call
|
84
|
-
|
85
|
-
0.2.0 / 2013-03-21
|
86
|
-
==================
|
87
|
-
* Adding flush method
|
88
|
-
|
89
|
-
0.1.4 / 2013-03-19
|
90
|
-
==================
|
91
|
-
* Adding ClassMethods for more extensibility by [arronmabrey](https://github.com/arronmabrey)
|
92
|
-
|
93
|
-
0.1.3 / 2013-03-19
|
94
|
-
==================
|
95
|
-
* Fixing user_id.to_s semantics, reported by [arronmabrey](https://github.com/arronmabrey)
|
96
|
-
* Reduced faraday requirements by [arronmabrey](https://github.com/arronmabrey)
|
97
|
-
|
98
|
-
0.1.2 / 2013-03-11
|
99
|
-
==================
|
100
|
-
* Fixing thrown exception on non-initialized tracks thanks to [sbellity](https://github.com/sbellity)
|
101
|
-
|
102
|
-
0.1.1 / 2013-02-11
|
103
|
-
==================
|
104
|
-
* Updating dependencies
|
105
|
-
* Adding actual support for MultiJson 1.0
|
106
|
-
|
107
|
-
0.1.0 / 2013-01-22
|
108
|
-
==================
|
109
|
-
* Updated docs to point at segment.io
|
110
|
-
|
111
|
-
0.0.5 / 2013-01-21
|
112
|
-
==================
|
113
|
-
* Renaming of all the files for proper bundling usage
|
114
|
-
|
115
|
-
0.0.4 / 2013-01-17
|
116
|
-
==================
|
117
|
-
* Updated readme and install instruction courtesy of [@zeke](https://github.com/zeke)
|
118
|
-
* Removed typhoeus and reverted to default adapter
|
119
|
-
* Removing session_id in favor of a single user_id
|
120
|
-
|
121
|
-
0.0.3 / 2013-01-16
|
122
|
-
==================
|
123
|
-
* Rakefile and renaming courtesy of [@kiennt](https://github.com/kiennt)
|
124
|
-
* Updated tests with mocks
|
data/Makefile
DELETED
data/README.md
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
analytics-ruby
|
2
|
-
==============
|
3
|
-
|
4
|
-
[](https://travis-ci.org/segmentio/analytics-ruby)
|
5
|
-
|
6
|
-
analytics-ruby is a ruby client for [Segment.io](https://segment.io)
|
7
|
-
|
8
|
-
## Documentation
|
9
|
-
|
10
|
-
Documentation is available at [segment.io/libraries/ruby](https://segment.io/libraries/ruby)
|
11
|
-
|
12
|
-
## License
|
13
|
-
|
14
|
-
```
|
15
|
-
WWWWWW||WWWWWW
|
16
|
-
W W W||W W W
|
17
|
-
||
|
18
|
-
( OO )__________
|
19
|
-
/ | \
|
20
|
-
/o o| MIT \
|
21
|
-
\___/||_||__||_|| *
|
22
|
-
|| || || ||
|
23
|
-
_||_|| _||_||
|
24
|
-
(__|__|(__|__|
|
25
|
-
```
|
26
|
-
|
27
|
-
(The MIT License)
|
28
|
-
|
29
|
-
Copyright (c) 2013 Segment.io Inc. <friends@segment.io>
|
30
|
-
|
31
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
32
|
-
|
33
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
34
|
-
|
35
|
-
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
36
|
-
|
37
|
-
|
38
|
-
[](https://bitdeli.com/free "Bitdeli Badge")
|
39
|
-
|
data/Rakefile
DELETED
data/analytics-ruby.gemspec
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
require File.expand_path('../lib/segment/analytics/version', __FILE__)
|
2
|
-
|
3
|
-
Gem::Specification.new do |spec|
|
4
|
-
spec.name = 'analytics-ruby'
|
5
|
-
spec.version = Segment::Analytics::VERSION
|
6
|
-
spec.files = Dir.glob('**/*')
|
7
|
-
spec.require_paths = ['lib']
|
8
|
-
spec.summary = 'Segment.io analytics library'
|
9
|
-
spec.description = 'The Segment.io ruby analytics library'
|
10
|
-
spec.authors = ['Segment.io']
|
11
|
-
spec.email = 'friends@segment.io'
|
12
|
-
spec.homepage = 'https://github.com/segmentio/analytics-ruby'
|
13
|
-
spec.license = 'MIT'
|
14
|
-
|
15
|
-
# Ruby 1.8 requires json
|
16
|
-
spec.add_dependency 'json', ['~> 1.7'] if RUBY_VERSION < "1.9"
|
17
|
-
|
18
|
-
spec.add_development_dependency 'rake', '~> 10.3'
|
19
|
-
spec.add_development_dependency 'wrong', '~> 0.0'
|
20
|
-
spec.add_development_dependency 'rspec', '~> 2.0'
|
21
|
-
spec.add_development_dependency 'tzinfo', '1.2.1'
|
22
|
-
spec.add_development_dependency 'activesupport', '>= 3.0.0', '<4.0.0'
|
23
|
-
end
|
@@ -1,84 +0,0 @@
|
|
1
|
-
require 'segment/analytics/defaults'
|
2
|
-
require 'segment/analytics/utils'
|
3
|
-
require 'segment/analytics/response'
|
4
|
-
require 'segment/analytics/logging'
|
5
|
-
require 'net/http'
|
6
|
-
require 'net/https'
|
7
|
-
require 'json'
|
8
|
-
|
9
|
-
module Segment
|
10
|
-
class Analytics
|
11
|
-
class Request
|
12
|
-
include Segment::Analytics::Defaults::Request
|
13
|
-
include Segment::Analytics::Utils
|
14
|
-
include Segment::Analytics::Logging
|
15
|
-
|
16
|
-
# public: Creates a new request object to send analytics batch
|
17
|
-
#
|
18
|
-
def initialize(options = {})
|
19
|
-
options[:host] ||= HOST
|
20
|
-
options[:port] ||= PORT
|
21
|
-
options[:ssl] ||= SSL
|
22
|
-
options[:headers] ||= HEADERS
|
23
|
-
@path = options[:path] || PATH
|
24
|
-
@retries = options[:retries] || RETRIES
|
25
|
-
@backoff = options[:backoff] || BACKOFF
|
26
|
-
|
27
|
-
http = Net::HTTP.new(options[:host], options[:port])
|
28
|
-
http.use_ssl = options[:ssl]
|
29
|
-
http.read_timeout = 8
|
30
|
-
http.open_timeout = 4
|
31
|
-
|
32
|
-
@http = http
|
33
|
-
end
|
34
|
-
|
35
|
-
# public: Posts the write key and batch of messages to the API.
|
36
|
-
#
|
37
|
-
# returns - Response of the status and error if it exists
|
38
|
-
def post(write_key, batch)
|
39
|
-
status, error = nil, nil
|
40
|
-
remaining_retries = @retries
|
41
|
-
backoff = @backoff
|
42
|
-
headers = { 'Content-Type' => 'application/json', 'accept' => 'application/json' }
|
43
|
-
begin
|
44
|
-
payload = JSON.generate :sentAt => datetime_in_iso8601(Time.new), :batch => batch
|
45
|
-
request = Net::HTTP::Post.new(@path, headers)
|
46
|
-
request.basic_auth write_key, nil
|
47
|
-
|
48
|
-
if self.class.stub
|
49
|
-
status = 200
|
50
|
-
error = nil
|
51
|
-
logger.debug "stubbed request to #{@path}: write key = #{write_key}, payload = #{payload}"
|
52
|
-
else
|
53
|
-
res = @http.request(request, payload)
|
54
|
-
status = res.code.to_i
|
55
|
-
body = JSON.parse(res.body)
|
56
|
-
error = body["error"]
|
57
|
-
end
|
58
|
-
|
59
|
-
rescue Exception => e
|
60
|
-
logger.error e.message
|
61
|
-
e.backtrace.each { |line| logger.error line }
|
62
|
-
status = -1
|
63
|
-
error = "Connection error: #{e}"
|
64
|
-
logger.info "retries remaining: #{remaining_retries}"
|
65
|
-
|
66
|
-
unless (remaining_retries -=1).zero?
|
67
|
-
sleep(backoff)
|
68
|
-
retry
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
Response.new status, error
|
73
|
-
end
|
74
|
-
|
75
|
-
class << self
|
76
|
-
attr_accessor :stub
|
77
|
-
|
78
|
-
def stub
|
79
|
-
@stub || ENV['STUB']
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|