simple_segment 1.0.0.pre → 1.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: 27c373f624b3e1192b8ebb92fbd5ead37924a4578e5179dd831c9226e4f57583
4
- data.tar.gz: b2537161f1f05a92ed3c39c47d65c62cb535217ebedc3d1201ed75a8aa928e56
3
+ metadata.gz: 17b61bb188d391c3349423f42c56444313a7ed154945149ecda2d1317d070a15
4
+ data.tar.gz: 499d33dbd054da57d6bf33bf277638a93d238dee88d7d1989626ce96f35dcbef
5
5
  SHA512:
6
- metadata.gz: b53313b90d9db6a87799b57f4cfee2fba4fb645e9b2b1aea3db19e996795266d6a558f14802c9bf86a6f13fa2655f0b9760267bab4189736746bd2684e93ed10
7
- data.tar.gz: e2b9c0b2d5bde7ff41de7e78af42b9c50621f0c095c9d8563cabfba3f0d5bf703c80e46b6fae3101cb4f686ebaa58c82ab77149792c3f87408df5b3d267c88db
6
+ metadata.gz: 209c042c0b36bbe411cbb76e57ae072c6cde1de5906dff3bdcff597dd83148f92154d052acec4225b23e1c40c64f5be3129d4a21db62aff1709520725e45edc6
7
+ data.tar.gz: 120b864ff8d2ba8a68082a6b8d4bcc68f75cd490ae083f463ef2e8bc0c02efc52f4f926642a1cf5cc0067db7ba885220ab7e7a66c578daff5a9499385fa81826
@@ -0,0 +1,22 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+
8
+ jobs:
9
+ test:
10
+ runs-on: ubuntu-latest
11
+ strategy:
12
+ matrix:
13
+ ruby-version: [2.6, 2.7, 3.0]
14
+ steps:
15
+ - uses: actions/checkout@v2
16
+ - name: Set up Ruby ${{ matrix.ruby-version }}
17
+ uses: ruby/setup-ruby@v1
18
+ with:
19
+ ruby-version: ${{ matrix.ruby-version }}
20
+ bundler-cache: true
21
+ - name: Run tests
22
+ run: bundle exec rake
data/.rubocop.yml CHANGED
@@ -1,8 +1,11 @@
1
+ AllCops:
2
+ NewCops: enable
3
+
1
4
  Metrics/BlockLength:
2
5
  Exclude:
3
6
  - '**/*_spec.rb'
4
7
 
5
- Metrics/LineLength:
8
+ Layout/LineLength:
6
9
  Max: 100
7
10
  IgnoreCopDirectives: true
8
11
  Exclude:
@@ -10,3 +13,6 @@ Metrics/LineLength:
10
13
 
11
14
  Style/Documentation:
12
15
  Enabled: false
16
+
17
+ Gemspec/RequiredRubyVersion:
18
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -6,13 +6,40 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.3.0] - 2021-11-27
10
+
11
+ ### Added
12
+ - Add support for message_id override https://github.com/whatthewhat/simple_segment/pull/34 by [@theblang][]
13
+
14
+ ## [1.2.0] - 2020-07-29
15
+
16
+ ### Changed
17
+ - Use an empty hash if no properties were provided to `track` https://github.com/whatthewhat/simple_segment/pull/28
18
+
19
+ ## [1.1.0] - 2020-04-11
20
+
21
+ ### Added
22
+ - Added support for http_proxy and https_proxy environment variables https://github.com/whatthewhat/simple_segment/pull/26 by [@saks][]
23
+ - Added Ruby 2.7 to travis.yml
24
+
25
+ ## [1.0.0] - 2019-12-12
26
+
27
+ ### Added
28
+ - Allow passing custom Net::HTTP options (e.g. timeout) https://github.com/whatthewhat/simple_segment/pull/23 by [@barodeur][]
29
+
30
+ ### Changed
31
+ - The gem is no longer tested with Ruby versions below 2.4
9
32
 
10
33
  ## [0.3.0] - 2018-03-15
11
34
 
12
35
  ### Changed
13
36
  - Date properties are now automatically converted to ISO 8601 to be consistent with the official client https://github.com/whatthewhat/simple_segment/pull/19 by @juanramoncg
14
37
 
15
- [Unreleased]: https://github.com/whatthewhat/simple_segment/compare/v0.3.0...HEAD
38
+ [Unreleased]: https://github.com/whatthewhat/simple_segment/compare/v1.3.0...HEAD
39
+ [1.3.0]: https://github.com/whatthewhat/simple_segment/compare/v1.2.0...v1.3.0
40
+ [1.2.0]: https://github.com/whatthewhat/simple_segment/compare/v1.1.0...v1.2.0
41
+ [1.1.0]: https://github.com/whatthewhat/simple_segment/compare/v1.0.0...v1.1.0
42
+ [1.0.0]: https://github.com/whatthewhat/simple_segment/compare/v0.3.0...v1.0.0
16
43
  [0.3.0]: https://github.com/whatthewhat/simple_segment/compare/v0.2.1...v0.3.0
17
44
  [0.2.1]: https://github.com/whatthewhat/simple_segment/compare/v0.2.0...v0.2.1
18
45
  [0.2.0]: https://github.com/whatthewhat/simple_segment/compare/v0.1.1...v0.2.0
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # SimpleSegment
2
2
 
3
- [![Build Status](https://travis-ci.org/whatthewhat/simple_segment.svg?branch=master)](https://travis-ci.org/whatthewhat/simple_segment)
3
+ ![Build Status](https://github.com/whatthewhat/simple_segment/actions/workflows/ci.yml/badge.svg?branch=master)
4
4
 
5
- A simple synchronous Ruby API client for [segment.io](segment.io).
5
+ A simple synchronous Ruby API client for [segment.io](https://segment.io).
6
6
 
7
7
  SimpleSegment allows for manual control of when and how the events are sent to Segment. This can be useful if you want to leverage an existing queueing system like Sidekiq or Resque for sending events or need to send events synchronously. If this is not the case you will be better off using the [official segment gem](https://github.com/segmentio/analytics-ruby) that handles queuing for you.
8
8
 
@@ -29,34 +29,32 @@ Add this line to your application's Gemfile:
29
29
  gem 'simple_segment'
30
30
  ```
31
31
 
32
- And then execute:
33
-
34
- $ bundle
35
-
36
32
  Or install it yourself as:
37
33
 
38
- $ gem install simple_segment
34
+ ```sh
35
+ $ gem install simple_segment
36
+ ```
39
37
 
40
38
  ## Usage
41
39
 
42
40
  Create a client instance:
43
41
 
44
42
  ```ruby
45
- analytics = SimpleSegment::Client.new({
43
+ analytics = SimpleSegment::Client.new(
46
44
  write_key: 'YOUR_WRITE_KEY', # required
47
45
  on_error: proc { |error_code, error_body, exception, response|
48
46
  # defaults to an empty proc
49
47
  }
50
- })
48
+ )
51
49
  ```
52
50
 
53
51
  Use it as you would use `analytics-ruby`:
54
52
 
55
53
  ```ruby
56
- analytics.track({
54
+ analytics.track(
57
55
  user_id: user.id,
58
56
  event: 'Created Account'
59
- })
57
+ )
60
58
  ```
61
59
 
62
60
  ### Batching
@@ -86,6 +84,7 @@ analytics = SimpleSegment::Client.new(
86
84
  ```
87
85
 
88
86
  ### Configurable Logger
87
+
89
88
  When used in stubbed mode all calls are logged to STDOUT, this can be changed by providing a custom logger object:
90
89
 
91
90
  ```ruby
@@ -97,7 +96,7 @@ analytics = SimpleSegment::Client.new(
97
96
 
98
97
  ### Set HTTP Options
99
98
 
100
- You can set options that are passed to `Net::HTTP.start`.
99
+ You can set [options](https://docs.ruby-lang.org/en/2.0.0/Net/HTTP.html#method-c-start) that are passed to `Net::HTTP.start`.
101
100
 
102
101
  ```ruby
103
102
  analytics = SimpleSegment::Client.new(
@@ -22,6 +22,7 @@ module SimpleSegment
22
22
  # @option :context [Hash]
23
23
  # @option :integrations [Hash]
24
24
  # @option :timestamp [#iso8601] (Time.now)
25
+ # @option :message_id
25
26
  def identify(options)
26
27
  Operations::Identify.new(self, symbolize_keys(options)).call
27
28
  end
@@ -34,6 +35,7 @@ module SimpleSegment
34
35
  # @option :context [Hash]
35
36
  # @option :integrations [Hash]
36
37
  # @option :timestamp [#iso8601] (Time.now)
38
+ # @option :message_id
37
39
  def track(options)
38
40
  Operations::Track.new(self, symbolize_keys(options)).call
39
41
  end
@@ -46,6 +48,7 @@ module SimpleSegment
46
48
  # @option :context [Hash]
47
49
  # @option :integrations [Hash]
48
50
  # @option :timestamp [#iso8601] (Time.now)
51
+ # @option :message_id
49
52
  def page(options)
50
53
  Operations::Page.new(self, symbolize_keys(options)).call
51
54
  end
@@ -58,6 +61,7 @@ module SimpleSegment
58
61
  # @option :context [Hash]
59
62
  # @option :integrations [Hash]
60
63
  # @option :timestamp [#iso8601] (Time.now)
64
+ # @option :message_id
61
65
  def group(options)
62
66
  Operations::Group.new(self, symbolize_keys(options)).call
63
67
  end
@@ -70,6 +74,7 @@ module SimpleSegment
70
74
  # @option :context [Hash]
71
75
  # @option :integrations [Hash]
72
76
  # @option :timestamp [#iso8601] (Time.now)
77
+ # @option :message_id
73
78
  def alias(options)
74
79
  Operations::Alias.new(self, symbolize_keys(options)).call
75
80
  end
@@ -8,7 +8,7 @@ module SimpleSegment
8
8
  end
9
9
 
10
10
  def default_logger(logger_option)
11
- logger_option || Logger.new(STDOUT)
11
+ logger_option || Logger.new($stdout)
12
12
  end
13
13
  end
14
14
  end
@@ -36,7 +36,8 @@ module SimpleSegment
36
36
  context: context,
37
37
  integrations: options[:integrations],
38
38
  timestamp: timestamp(options.fetch(:timestamp, current_time)),
39
- sentAt: current_time.iso8601
39
+ sentAt: current_time.iso8601,
40
+ messageId: options[:message_id]
40
41
  }
41
42
  end
42
43
 
@@ -8,14 +8,13 @@ module SimpleSegment
8
8
  end
9
9
 
10
10
  def build_payload
11
- raise ArgumentError, 'event name must be present' \
12
- unless options[:event]
11
+ raise ArgumentError, 'event name must be present' unless options[:event]
13
12
 
14
- properties = options[:properties] && isoify_dates!(options[:properties])
13
+ properties = options[:properties] || {}
15
14
 
16
15
  base_payload.merge(
17
16
  event: options[:event],
18
- properties: properties
17
+ properties: isoify_dates!(properties)
19
18
  )
20
19
  end
21
20
  end
@@ -32,7 +32,7 @@ module SimpleSegment
32
32
 
33
33
  { status: 200, error: nil }
34
34
  else
35
- Net::HTTP.start(uri.host, uri.port, http_options) do |http|
35
+ Net::HTTP.start(uri.host, uri.port, :ENV, http_options) do |http|
36
36
  request = Net::HTTP::Post.new(path, headers)
37
37
  request.basic_auth write_key, nil
38
38
  http.request(request, payload).tap do |res|
@@ -7,9 +7,7 @@ module SimpleSegment
7
7
  end
8
8
 
9
9
  def symbolize_keys(hash)
10
- hash.each_with_object({}) do |(key, value), result|
11
- result[key.to_sym] = value
12
- end
10
+ hash.transform_keys(&:to_sym)
13
11
  end
14
12
 
15
13
  # public: Converts all the date values in the into iso8601 strings in place
@@ -22,8 +20,8 @@ module SimpleSegment
22
20
  # strings
23
21
  #
24
22
  def isoify_dates(hash)
25
- hash.each_with_object({}) do |(k, v), memo|
26
- memo[k] = maybe_datetime_in_iso8601(v)
23
+ hash.transform_values do |v|
24
+ maybe_datetime_in_iso8601(v)
27
25
  end
28
26
  end
29
27
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SimpleSegment
4
- VERSION = '1.0.0.pre'
4
+ VERSION = '1.3.0'
5
5
  end
@@ -20,11 +20,14 @@ Gem::Specification.new do |spec|
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
21
  spec.require_paths = ['lib']
22
22
 
23
- spec.add_development_dependency 'bundler', '~> 1.11'
23
+ spec.add_development_dependency 'bundler', '>= 1.11'
24
24
  spec.add_development_dependency 'pry'
25
- spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rake', '>= 10.0'
26
26
  spec.add_development_dependency 'rspec', '~> 3.0'
27
- spec.add_development_dependency 'rubocop', '0.75.0'
27
+ spec.add_development_dependency 'rubocop', '1.23.0'
28
28
  spec.add_development_dependency 'timecop', '~> 0.8.0'
29
29
  spec.add_development_dependency 'webmock', '~> 3.7'
30
+ spec.metadata = {
31
+ 'rubygems_mfa_required' => 'true'
32
+ }
30
33
  end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_segment
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre
4
+ version: 1.3.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: 2019-12-12 00:00:00.000000000 Z
11
+ date: 2021-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.11'
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
26
  version: '1.11'
27
27
  - !ruby/object:Gem::Dependency
@@ -42,14 +42,14 @@ dependencies:
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '10.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
54
  version: '10.0'
55
55
  - !ruby/object:Gem::Dependency
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - '='
74
74
  - !ruby/object:Gem::Version
75
- version: 0.75.0
75
+ version: 1.23.0
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - '='
81
81
  - !ruby/object:Gem::Version
82
- version: 0.75.0
82
+ version: 1.23.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: timecop
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -116,11 +116,11 @@ executables: []
116
116
  extensions: []
117
117
  extra_rdoc_files: []
118
118
  files:
119
+ - ".github/workflows/ci.yml"
119
120
  - ".gitignore"
120
121
  - ".hound.yml"
121
122
  - ".rspec"
122
123
  - ".rubocop.yml"
123
- - ".travis.yml"
124
124
  - CHANGELOG.md
125
125
  - Gemfile
126
126
  - LICENSE.txt
@@ -147,7 +147,8 @@ files:
147
147
  homepage: https://github.com/whatthewhat/simple_segment
148
148
  licenses:
149
149
  - MIT
150
- metadata: {}
150
+ metadata:
151
+ rubygems_mfa_required: 'true'
151
152
  post_install_message:
152
153
  rdoc_options: []
153
154
  require_paths:
@@ -159,11 +160,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
159
160
  version: '0'
160
161
  required_rubygems_version: !ruby/object:Gem::Requirement
161
162
  requirements:
162
- - - ">"
163
+ - - ">="
163
164
  - !ruby/object:Gem::Version
164
- version: 1.3.1
165
+ version: '0'
165
166
  requirements: []
166
- rubygems_version: 3.0.3
167
+ rubygems_version: 3.1.6
167
168
  signing_key:
168
169
  specification_version: 4
169
170
  summary: A simple synchronous API client for segment.io.
data/.travis.yml DELETED
@@ -1,5 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.4
4
- - 2.5
5
- - 2.6