analytics-ruby 2.0.13 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- 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 +111 -269
- 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 +18 -19
- data/lib/segment/analytics/version.rb +1 -1
- data/lib/segment/analytics/worker.rb +20 -11
- data/lib/segment/analytics.rb +15 -6
- metadata +65 -34
- data/Gemfile +0 -2
- data/Gemfile.lock +0 -53
- data/History.md +0 -160
- data/Makefile +0 -8
- data/README.md +0 -91
- data/Rakefile +0 -7
- data/analytics-ruby.gemspec +0 -23
- data/lib/segment/analytics/request.rb +0 -82
- data/spec/segment/analytics/client_spec.rb +0 -291
- data/spec/segment/analytics/worker_spec.rb +0 -96
- data/spec/segment/analytics_spec.rb +0 -95
- 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,57 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: analytics-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.4.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:
|
11
|
+
date: 2021-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: commander
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '4.4'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '4.4'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '10.3'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '10.3'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '3.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '3.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: tzinfo
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -70,49 +70,81 @@ dependencies:
|
|
70
70
|
name: activesupport
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 4.1.11
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 4.1.11
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: oj
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 3.6.2
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
74
95
|
- !ruby/object:Gem::Version
|
75
|
-
version: 3.
|
76
|
-
|
96
|
+
version: 3.6.2
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
77
102
|
- !ruby/object:Gem::Version
|
78
|
-
version:
|
103
|
+
version: 0.51.0
|
79
104
|
type: :development
|
80
105
|
prerelease: false
|
81
106
|
version_requirements: !ruby/object:Gem::Requirement
|
82
107
|
requirements:
|
83
|
-
- - "
|
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
|
+
- - "~>"
|
84
116
|
- !ruby/object:Gem::Version
|
85
|
-
version:
|
86
|
-
|
117
|
+
version: 0.1.4
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
87
123
|
- !ruby/object:Gem::Version
|
88
|
-
version:
|
124
|
+
version: 0.1.4
|
89
125
|
description: The Segment.io ruby analytics library
|
90
126
|
email: friends@segment.io
|
91
|
-
executables:
|
127
|
+
executables:
|
128
|
+
- analytics
|
92
129
|
extensions: []
|
93
130
|
extra_rdoc_files: []
|
94
131
|
files:
|
95
|
-
-
|
96
|
-
-
|
97
|
-
- History.md
|
98
|
-
- Makefile
|
99
|
-
- README.md
|
100
|
-
- Rakefile
|
101
|
-
- analytics-ruby.gemspec
|
132
|
+
- bin/analytics
|
133
|
+
- lib/analytics-ruby.rb
|
102
134
|
- lib/segment.rb
|
103
135
|
- lib/segment/analytics.rb
|
136
|
+
- lib/segment/analytics/backoff_policy.rb
|
104
137
|
- lib/segment/analytics/client.rb
|
105
138
|
- lib/segment/analytics/defaults.rb
|
139
|
+
- lib/segment/analytics/field_parser.rb
|
106
140
|
- lib/segment/analytics/logging.rb
|
107
|
-
- lib/segment/analytics/
|
141
|
+
- lib/segment/analytics/message_batch.rb
|
108
142
|
- lib/segment/analytics/response.rb
|
143
|
+
- lib/segment/analytics/test_queue.rb
|
144
|
+
- lib/segment/analytics/transport.rb
|
109
145
|
- lib/segment/analytics/utils.rb
|
110
146
|
- lib/segment/analytics/version.rb
|
111
147
|
- lib/segment/analytics/worker.rb
|
112
|
-
- spec/segment/analytics/client_spec.rb
|
113
|
-
- spec/segment/analytics/worker_spec.rb
|
114
|
-
- spec/segment/analytics_spec.rb
|
115
|
-
- spec/spec_helper.rb
|
116
148
|
homepage: https://github.com/segmentio/analytics-ruby
|
117
149
|
licenses:
|
118
150
|
- MIT
|
@@ -125,15 +157,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
125
157
|
requirements:
|
126
158
|
- - ">="
|
127
159
|
- !ruby/object:Gem::Version
|
128
|
-
version: '0'
|
160
|
+
version: '2.0'
|
129
161
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
162
|
requirements:
|
131
163
|
- - ">="
|
132
164
|
- !ruby/object:Gem::Version
|
133
165
|
version: '0'
|
134
166
|
requirements: []
|
135
|
-
|
136
|
-
rubygems_version: 2.4.5
|
167
|
+
rubygems_version: 3.0.8
|
137
168
|
signing_key:
|
138
169
|
specification_version: 4
|
139
170
|
summary: Segment.io analytics library
|
data/Gemfile
DELETED
data/Gemfile.lock
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
analytics-ruby (2.0.12)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: http://rubygems.org/
|
8
|
-
specs:
|
9
|
-
activesupport (3.2.21)
|
10
|
-
i18n (~> 0.6, >= 0.6.4)
|
11
|
-
multi_json (~> 1.0)
|
12
|
-
diff-lcs (1.2.5)
|
13
|
-
i18n (0.7.0)
|
14
|
-
multi_json (1.11.1)
|
15
|
-
predicated (0.2.6)
|
16
|
-
rake (10.4.2)
|
17
|
-
rspec (2.14.1)
|
18
|
-
rspec-core (~> 2.14.0)
|
19
|
-
rspec-expectations (~> 2.14.0)
|
20
|
-
rspec-mocks (~> 2.14.0)
|
21
|
-
rspec-core (2.14.8)
|
22
|
-
rspec-expectations (2.14.5)
|
23
|
-
diff-lcs (>= 1.1.3, < 2.0)
|
24
|
-
rspec-mocks (2.14.6)
|
25
|
-
ruby2ruby (2.1.0)
|
26
|
-
ruby_parser (~> 3.1)
|
27
|
-
sexp_processor (~> 4.0)
|
28
|
-
ruby_parser (3.6.1)
|
29
|
-
sexp_processor (~> 4.1)
|
30
|
-
sexp_processor (4.4.3)
|
31
|
-
thread_safe (0.3.4)
|
32
|
-
tzinfo (1.2.1)
|
33
|
-
thread_safe (~> 0.1)
|
34
|
-
wrong (0.7.1)
|
35
|
-
diff-lcs (~> 1.2.5)
|
36
|
-
predicated (~> 0.2.6)
|
37
|
-
ruby2ruby (>= 2.0.1)
|
38
|
-
ruby_parser (>= 3.0.1)
|
39
|
-
sexp_processor (>= 4.0)
|
40
|
-
|
41
|
-
PLATFORMS
|
42
|
-
ruby
|
43
|
-
|
44
|
-
DEPENDENCIES
|
45
|
-
activesupport (>= 3.0.0, < 4.0.0)
|
46
|
-
analytics-ruby!
|
47
|
-
rake (~> 10.3)
|
48
|
-
rspec (~> 2.0)
|
49
|
-
tzinfo (= 1.2.1)
|
50
|
-
wrong (~> 0.0)
|
51
|
-
|
52
|
-
BUNDLED WITH
|
53
|
-
1.10.6
|
data/History.md
DELETED
@@ -1,160 +0,0 @@
|
|
1
|
-
2.0.12 / 2015-01-10
|
2
|
-
==================
|
3
|
-
|
4
|
-
* Fix batch being cleared and causing duplicates
|
5
|
-
|
6
|
-
2.0.11 / 2014-09-22
|
7
|
-
==================
|
8
|
-
|
9
|
-
* fix: don't clear batch if request failed
|
10
|
-
|
11
|
-
2.0.10 / 2014-09-22
|
12
|
-
==================
|
13
|
-
|
14
|
-
* Move timeout retry above output
|
15
|
-
|
16
|
-
2.0.9 / 2014-09-22
|
17
|
-
==================
|
18
|
-
|
19
|
-
* Fix rescuing timeouts
|
20
|
-
|
21
|
-
2.0.8 / 2014-09-11
|
22
|
-
==================
|
23
|
-
* fix: add 3 ms to timestamp
|
24
|
-
|
25
|
-
2.0.7 / 2014-08-27
|
26
|
-
==================
|
27
|
-
* fix: include optional options hash in calls
|
28
|
-
|
29
|
-
2.0.6 / 2014-08-12
|
30
|
-
==================
|
31
|
-
* fix: category param on #page and #screen
|
32
|
-
|
33
|
-
2.0.5 / 2014-05-26
|
34
|
-
==================
|
35
|
-
* fix: datetime conversions
|
36
|
-
|
37
|
-
2.0.4 / 2014-06-11
|
38
|
-
==================
|
39
|
-
* fix: isofying trait dates in #group
|
40
|
-
|
41
|
-
2.0.3 / 2014-06-04
|
42
|
-
==================
|
43
|
-
* fix: undefined method `is_requesting?' for nil:NilClass when calling flush (#51)
|
44
|
-
|
45
|
-
2.0.2 / 2014-05-30
|
46
|
-
==================
|
47
|
-
* fix: formatting ios dates
|
48
|
-
* fix: respond_to? implementation
|
49
|
-
* add: able to stub requests by setting STUB env var
|
50
|
-
|
51
|
-
2.0.1 / 2014-05-15
|
52
|
-
==================
|
53
|
-
* add: namespace under Segment::Analytics
|
54
|
-
* add: can create multiple instances with creator method (rather than
|
55
|
-
having a singleton)
|
56
|
-
* add: logging with Logger instance or Rails.logger if available
|
57
|
-
* add: able to stub requests so they just log and don't hit the server
|
58
|
-
* fix: worker continues running across forked processes
|
59
|
-
* fix: removed usage of ActiveSupport methods since its not a dependency
|
60
|
-
* fix: sending data that matches segment's new api spec
|
61
|
-
|
62
|
-
(there is no v2.0.0)
|
63
|
-
|
64
|
-
1.1.0 / 2014-04-17
|
65
|
-
==================
|
66
|
-
* adding .initialized? by [@lumberj](https://github.com/lumberj)
|
67
|
-
|
68
|
-
1.0.0 / 2014-03-12
|
69
|
-
==================
|
70
|
-
* removing faraday dependency
|
71
|
-
|
72
|
-
0.6.0 / 2014-02-19
|
73
|
-
==================
|
74
|
-
* adding .group(), .page(), and .screen() calls
|
75
|
-
* relaxing faraday dependency, fixes #31
|
76
|
-
|
77
|
-
0.5.4 / 2013-12-31
|
78
|
-
==================
|
79
|
-
* Add `requestId` fields to all requests for tracing.
|
80
|
-
|
81
|
-
0.5.3 / 2013-12-31
|
82
|
-
==================
|
83
|
-
* 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)
|
84
|
-
|
85
|
-
0.5.2 / 2013-12-02
|
86
|
-
==================
|
87
|
-
* adding `sleep` backoff between connection retries
|
88
|
-
|
89
|
-
0.5.1 / 2013-11-22
|
90
|
-
==================
|
91
|
-
* adding retries for connection hangups
|
92
|
-
|
93
|
-
0.5.0 / 2013-10-03
|
94
|
-
==================
|
95
|
-
* 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)
|
96
|
-
|
97
|
-
0.4.0 / 2013-08-30
|
98
|
-
==================
|
99
|
-
* Adding support and tests for 1.8.7
|
100
|
-
|
101
|
-
0.3.4 / 2013-08-26
|
102
|
-
==================
|
103
|
-
* Pass `Time` values as iso8601 timestamp strings
|
104
|
-
|
105
|
-
0.3.3 / 2013-08-02
|
106
|
-
==================
|
107
|
-
* Allow init/track/identify/alias to accept strings as keys. by [@shipstar](https://github.com/shipstar)
|
108
|
-
|
109
|
-
0.3.2 / 2013-05-28
|
110
|
-
==================
|
111
|
-
* Adding faraday timeout by [@yanchenyun](https://github.com/yangchenyun)
|
112
|
-
|
113
|
-
0.3.1 / 2013-04-29
|
114
|
-
==================
|
115
|
-
* Adding check for properties to be a Hash
|
116
|
-
|
117
|
-
0.3.0 / 2013-04-05
|
118
|
-
==================
|
119
|
-
* Adding alias call
|
120
|
-
|
121
|
-
0.2.0 / 2013-03-21
|
122
|
-
==================
|
123
|
-
* Adding flush method
|
124
|
-
|
125
|
-
0.1.4 / 2013-03-19
|
126
|
-
==================
|
127
|
-
* Adding ClassMethods for more extensibility by [arronmabrey](https://github.com/arronmabrey)
|
128
|
-
|
129
|
-
0.1.3 / 2013-03-19
|
130
|
-
==================
|
131
|
-
* Fixing user_id.to_s semantics, reported by [arronmabrey](https://github.com/arronmabrey)
|
132
|
-
* Reduced faraday requirements by [arronmabrey](https://github.com/arronmabrey)
|
133
|
-
|
134
|
-
0.1.2 / 2013-03-11
|
135
|
-
==================
|
136
|
-
* Fixing thrown exception on non-initialized tracks thanks to [sbellity](https://github.com/sbellity)
|
137
|
-
|
138
|
-
0.1.1 / 2013-02-11
|
139
|
-
==================
|
140
|
-
* Updating dependencies
|
141
|
-
* Adding actual support for MultiJson 1.0
|
142
|
-
|
143
|
-
0.1.0 / 2013-01-22
|
144
|
-
==================
|
145
|
-
* Updated docs to point at segment.io
|
146
|
-
|
147
|
-
0.0.5 / 2013-01-21
|
148
|
-
==================
|
149
|
-
* Renaming of all the files for proper bundling usage
|
150
|
-
|
151
|
-
0.0.4 / 2013-01-17
|
152
|
-
==================
|
153
|
-
* Updated readme and install instruction courtesy of [@zeke](https://github.com/zeke)
|
154
|
-
* Removed typhoeus and reverted to default adapter
|
155
|
-
* Removing session_id in favor of a single user_id
|
156
|
-
|
157
|
-
0.0.3 / 2013-01-16
|
158
|
-
==================
|
159
|
-
* Rakefile and renaming courtesy of [@kiennt](https://github.com/kiennt)
|
160
|
-
* Updated tests with mocks
|
data/Makefile
DELETED
data/README.md
DELETED
@@ -1,91 +0,0 @@
|
|
1
|
-
analytics-ruby
|
2
|
-
==============
|
3
|
-
|
4
|
-
[![Build Status](https://travis-ci.org/segmentio/analytics-ruby.png?branch=master)](https://travis-ci.org/segmentio/analytics-ruby)
|
5
|
-
|
6
|
-
analytics-ruby is a ruby client for [Segment](https://segment.com)
|
7
|
-
|
8
|
-
## Install
|
9
|
-
|
10
|
-
Into Gemfile from rubygems.org:
|
11
|
-
```
|
12
|
-
gem 'analytics-ruby', :require => "segment"
|
13
|
-
```
|
14
|
-
|
15
|
-
Into environment gems from rubygems.org:
|
16
|
-
```
|
17
|
-
gem install 'analytics-ruby'
|
18
|
-
```
|
19
|
-
|
20
|
-
## Usage
|
21
|
-
|
22
|
-
Create an instance of the Analytics object:
|
23
|
-
```
|
24
|
-
analytics = Segment::Analytics.new({
|
25
|
-
write_key: 'YOUR_WRITE_KEY'
|
26
|
-
})
|
27
|
-
```
|
28
|
-
|
29
|
-
Sample usage:
|
30
|
-
```
|
31
|
-
user = User.last
|
32
|
-
|
33
|
-
# Identify the user for the people section
|
34
|
-
analytics.identify(
|
35
|
-
{
|
36
|
-
user_id: user.id,
|
37
|
-
traits: {
|
38
|
-
email: user.email,
|
39
|
-
first_name: user.first_name,
|
40
|
-
last_name: user.last_name
|
41
|
-
}
|
42
|
-
}
|
43
|
-
)
|
44
|
-
|
45
|
-
# Track a user event
|
46
|
-
analytics.track(
|
47
|
-
{
|
48
|
-
user_id: user.id,
|
49
|
-
event: 'Created Account'
|
50
|
-
}
|
51
|
-
)
|
52
|
-
```
|
53
|
-
|
54
|
-
Refer to the section below for documenation on individual available calls.
|
55
|
-
|
56
|
-
## Documentation
|
57
|
-
|
58
|
-
Documentation is available at [segment.com/libraries/ruby](https://segment.com/libraries/ruby)
|
59
|
-
|
60
|
-
## Testing
|
61
|
-
|
62
|
-
You can use the `stub` option to Segment::Analytics.new to cause all requests to be stubbed, making it easier to test with this library.
|
63
|
-
|
64
|
-
## License
|
65
|
-
|
66
|
-
```
|
67
|
-
WWWWWW||WWWWWW
|
68
|
-
W W W||W W W
|
69
|
-
||
|
70
|
-
( OO )__________
|
71
|
-
/ | \
|
72
|
-
/o o| MIT \
|
73
|
-
\___/||_||__||_|| *
|
74
|
-
|| || || ||
|
75
|
-
_||_|| _||_||
|
76
|
-
(__|__|(__|__|
|
77
|
-
```
|
78
|
-
|
79
|
-
(The MIT License)
|
80
|
-
|
81
|
-
Copyright (c) 2013 Segment Inc. <friends@segment.com>
|
82
|
-
|
83
|
-
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:
|
84
|
-
|
85
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
86
|
-
|
87
|
-
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.
|
88
|
-
|
89
|
-
|
90
|
-
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/segmentio/analytics-ruby/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
|
91
|
-
|
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,82 +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
|
-
rescue Exception => e
|
59
|
-
unless (remaining_retries -=1).zero?
|
60
|
-
sleep(backoff)
|
61
|
-
retry
|
62
|
-
end
|
63
|
-
|
64
|
-
logger.error e.message
|
65
|
-
e.backtrace.each { |line| logger.error line }
|
66
|
-
status = -1
|
67
|
-
error = "Connection error: #{e}"
|
68
|
-
end
|
69
|
-
|
70
|
-
Response.new status, error
|
71
|
-
end
|
72
|
-
|
73
|
-
class << self
|
74
|
-
attr_accessor :stub
|
75
|
-
|
76
|
-
def stub
|
77
|
-
@stub || ENV['STUB']
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|