simple_segment 1.1.0 → 1.4.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: 7a623a667db5890d88ca602d744725ce1a63ff6aee02ce8d6aa8439e714a8456
4
- data.tar.gz: bfcb26a192fcc815ef7dfb875280fd4b3d12840177ecd39b6af691d50dc51539
3
+ metadata.gz: 4ecb763039e2fdacb85b464ebd96a7b46b4b18a92fb1a41069aff09af3c8fa92
4
+ data.tar.gz: e8bd47c02313e50940a2b3c042533b324ce4cba322572ade72562c6c39eec119
5
5
  SHA512:
6
- metadata.gz: b47a7e817788640e8d05f88835c179aae1f6075eff460e4ad4677453f7bfe3882616caff2b06001c76bc22ded91fbf0d00eb32a2acd042647f7ae56d38bf3b42
7
- data.tar.gz: 35086c2e4b6d1c0ab332663bf5241c61e2c4b977f7757b7d5827dda428fe873d6d923163f9ad72271bd0cd57f4c07b221f0e3ff4591c9057eeccdca3bd4447c1
6
+ metadata.gz: 5f0097b62f7bcfdcd6ca0f7caa16dc29505b1fd6a896dac9178d481201d6aaabd1aa456760baef7dbb95de34f956374df643351b0769626566cb6cb2ae89e6cc
7
+ data.tar.gz: 571840b8b57c64ac39d574b92e90db37290eb48e9f756c594c109f1948b27246503ceca31f00151f0802f4e67801dfcbb138f5311c6d105852e84636bd0710b1
@@ -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: ['3.1', '3.0', '2.7']
14
+ steps:
15
+ - uses: actions/checkout@v3
16
+ - name: Set up Ruby ${{ matrix.ruby }}
17
+ uses: ruby/setup-ruby@v1
18
+ with:
19
+ ruby-version: ${{ matrix.ruby }}
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,16 +6,31 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.4.0] - 2022-08-31
10
+
11
+ ### Added
12
+ - Add host option to support regional segments https://github.com/whatthewhat/simple_segment/pull/37 by [@larsklevan](https://github.com/larsklevan)
13
+
14
+ ## [1.3.0] - 2021-11-27
15
+
16
+ ### Added
17
+ - Add support for message_id override https://github.com/whatthewhat/simple_segment/pull/34 by [@theblang](https://github.com/theblang)
18
+
19
+ ## [1.2.0] - 2020-07-29
20
+
21
+ ### Changed
22
+ - Use an empty hash if no properties were provided to `track` https://github.com/whatthewhat/simple_segment/pull/28
23
+
9
24
  ## [1.1.0] - 2020-04-11
10
25
 
11
26
  ### Added
12
- - Added supprt for http_proxy and https_proxy environment variables https://github.com/whatthewhat/simple_segment/pull/26 by @saks
27
+ - Added support for http_proxy and https_proxy environment variables https://github.com/whatthewhat/simple_segment/pull/26 by [@saks](https://github.com/saks)
13
28
  - Added Ruby 2.7 to travis.yml
14
29
 
15
30
  ## [1.0.0] - 2019-12-12
16
31
 
17
32
  ### Added
18
- - Allow passing custom Net::HTTP options (e.g. timeout) https://github.com/whatthewhat/simple_segment/pull/23 by @barodeur
33
+ - Allow passing custom Net::HTTP options (e.g. timeout) https://github.com/whatthewhat/simple_segment/pull/23 by [@barodeur](https://github.com/barodeur)
19
34
 
20
35
  ### Changed
21
36
  - The gem is no longer tested with Ruby versions below 2.4
@@ -25,7 +40,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
25
40
  ### Changed
26
41
  - 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
27
42
 
28
- [Unreleased]: https://github.com/whatthewhat/simple_segment/compare/v1.1.0...HEAD
43
+ [Unreleased]: https://github.com/whatthewhat/simple_segment/compare/v1.4.0...HEAD
44
+ [1.4.0]: https://github.com/whatthewhat/simple_segment/compare/v1.3.0...v1.4.0
45
+ [1.3.0]: https://github.com/whatthewhat/simple_segment/compare/v1.2.0...v1.3.0
46
+ [1.2.0]: https://github.com/whatthewhat/simple_segment/compare/v1.1.0...v1.2.0
29
47
  [1.1.0]: https://github.com/whatthewhat/simple_segment/compare/v1.0.0...v1.1.0
30
48
  [1.0.0]: https://github.com/whatthewhat/simple_segment/compare/v0.3.0...v1.0.0
31
49
  [0.3.0]: https://github.com/whatthewhat/simple_segment/compare/v0.2.1...v0.3.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
 
@@ -110,6 +110,17 @@ analytics = SimpleSegment::Client.new(
110
110
  )
111
111
  ```
112
112
 
113
+ ### Configurable Host
114
+
115
+ You can use [regional segments](https://segment.com/docs/guides/regional-segment/) and send data to the desired region by setting the `host` parameter.
116
+
117
+ ```ruby
118
+ analytics = SimpleSegment::Client.new(
119
+ write_key: 'YOUR_WRITE_KEY',
120
+ host: 'events.eu1.segmentapis.com'
121
+ )
122
+ ```
123
+
113
124
  ## Development
114
125
 
115
126
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -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
@@ -7,7 +7,9 @@ module SimpleSegment
7
7
  include SimpleSegment::Utils
8
8
  include SimpleSegment::Logging
9
9
 
10
- attr_reader :write_key, :on_error, :stub, :logger, :http_options
10
+ DEFAULT_HOST = 'api.segment.io'
11
+
12
+ attr_reader :write_key, :on_error, :stub, :logger, :http_options, :host
11
13
 
12
14
  def initialize(settings = {})
13
15
  symbolized_settings = symbolize_keys(settings)
@@ -17,6 +19,7 @@ module SimpleSegment
17
19
  @logger = default_logger(symbolized_settings[:logger])
18
20
  @http_options = { use_ssl: true }
19
21
  .merge(symbolized_settings[:http_options] || {})
22
+ @host = symbolized_settings[:host] || DEFAULT_HOST
20
23
  raise ArgumentError, 'Missing required option :write_key' \
21
24
  unless @write_key
22
25
  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
@@ -2,13 +2,12 @@
2
2
 
3
3
  module SimpleSegment
4
4
  class Request
5
- BASE_URL = 'https://api.segment.io'
6
5
  DEFAULT_HEADERS = {
7
6
  'Content-Type' => 'application/json',
8
7
  'accept' => 'application/json'
9
8
  }.freeze
10
9
 
11
- attr_reader :write_key, :error_handler, :stub, :logger, :http_options
10
+ attr_reader :write_key, :error_handler, :stub, :logger, :http_options, :host
12
11
 
13
12
  def initialize(client)
14
13
  @write_key = client.config.write_key
@@ -16,6 +15,7 @@ module SimpleSegment
16
15
  @stub = client.config.stub
17
16
  @logger = client.config.logger
18
17
  @http_options = client.config.http_options
18
+ @host = client.config.host
19
19
  end
20
20
 
21
21
  def post(path, payload, headers: DEFAULT_HEADERS) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
@@ -23,17 +23,17 @@ module SimpleSegment
23
23
  status_code = nil
24
24
  response_body = nil
25
25
 
26
- uri = URI(BASE_URL)
26
+ uri = URI("https://#{host}#{path}")
27
27
  payload = JSON.generate(payload)
28
28
  if stub
29
29
  logger.debug "stubbed request to \
30
- #{path}: write key = #{write_key}, \
30
+ #{uri.path}: write key = #{write_key}, \
31
31
  payload = #{payload}"
32
32
 
33
33
  { status: 200, error: nil }
34
34
  else
35
35
  Net::HTTP.start(uri.host, uri.port, :ENV, http_options) do |http|
36
- request = Net::HTTP::Post.new(path, headers)
36
+ request = Net::HTTP::Post.new(uri.path, headers)
37
37
  request.basic_auth write_key, nil
38
38
  http.request(request, payload).tap do |res|
39
39
  status_code = res.code
@@ -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.1.0'
4
+ VERSION = '1.4.0'
5
5
  end
@@ -24,7 +24,10 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency 'pry'
25
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'
28
- spec.add_development_dependency 'timecop', '~> 0.8.0'
27
+ spec.add_development_dependency 'rubocop', '1.23.0'
28
+ spec.add_development_dependency 'timecop', '~> 0.9.5'
29
29
  spec.add_development_dependency 'webmock', '~> 3.7'
30
+ spec.metadata = {
31
+ 'rubygems_mfa_required' => 'true'
32
+ }
30
33
  end
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: 1.1.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikhail Topolskiy
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-11 00:00:00.000000000 Z
11
+ date: 2022-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -72,28 +72,28 @@ 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
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 0.8.0
89
+ version: 0.9.5
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 0.8.0
96
+ version: 0.9.5
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: webmock
99
99
  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,8 +147,9 @@ files:
147
147
  homepage: https://github.com/whatthewhat/simple_segment
148
148
  licenses:
149
149
  - MIT
150
- metadata: {}
151
- post_install_message:
150
+ metadata:
151
+ rubygems_mfa_required: 'true'
152
+ post_install_message:
152
153
  rdoc_options: []
153
154
  require_paths:
154
155
  - lib
@@ -163,8 +164,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
163
164
  - !ruby/object:Gem::Version
164
165
  version: '0'
165
166
  requirements: []
166
- rubygems_version: 3.0.3
167
- signing_key:
167
+ rubygems_version: 3.1.6
168
+ signing_key:
168
169
  specification_version: 4
169
170
  summary: A simple synchronous API client for segment.io.
170
171
  test_files: []
data/.travis.yml DELETED
@@ -1,6 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.4
4
- - 2.5
5
- - 2.6
6
- - 2.7