simple_segment 1.3.0 → 1.5.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: 17b61bb188d391c3349423f42c56444313a7ed154945149ecda2d1317d070a15
4
- data.tar.gz: 499d33dbd054da57d6bf33bf277638a93d238dee88d7d1989626ce96f35dcbef
3
+ metadata.gz: 6e5090db1c874309f4cd0c4fef0cef16fc261eb9f41cc25e05bc653195199b1b
4
+ data.tar.gz: a36a26d72fd87df85236fb5b306e6c66dd9e64f1b65acb1f4b25ced8d7b655fd
5
5
  SHA512:
6
- metadata.gz: 209c042c0b36bbe411cbb76e57ae072c6cde1de5906dff3bdcff597dd83148f92154d052acec4225b23e1c40c64f5be3129d4a21db62aff1709520725e45edc6
7
- data.tar.gz: 120b864ff8d2ba8a68082a6b8d4bcc68f75cd490ae083f463ef2e8bc0c02efc52f4f926642a1cf5cc0067db7ba885220ab7e7a66c578daff5a9499385fa81826
6
+ metadata.gz: 4d9930d8f661b02fbdba7c513c0a5f424eeea901597059a8570518d1f719cc026cc24f1bd6c3a88508526198557929f8f7f3185f9f9408683c1b571cfc58e195
7
+ data.tar.gz: 1b34511c0bdd1960627e797c4a41802863cbaa15f67f53b8a3e583c3b3f95dd75b4b63d137e0e967c04cabee65853d5d96f6612f2a9a30c517af88cec782a499
@@ -10,13 +10,13 @@ jobs:
10
10
  runs-on: ubuntu-latest
11
11
  strategy:
12
12
  matrix:
13
- ruby-version: [2.6, 2.7, 3.0]
13
+ ruby: ['3.1', '3.0', '2.7']
14
14
  steps:
15
- - uses: actions/checkout@v2
16
- - name: Set up Ruby ${{ matrix.ruby-version }}
15
+ - uses: actions/checkout@v3
16
+ - name: Set up Ruby ${{ matrix.ruby }}
17
17
  uses: ruby/setup-ruby@v1
18
18
  with:
19
- ruby-version: ${{ matrix.ruby-version }}
19
+ ruby-version: ${{ matrix.ruby }}
20
20
  bundler-cache: true
21
21
  - name: Run tests
22
22
  run: bundle exec rake
data/CHANGELOG.md CHANGED
@@ -6,10 +6,20 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.5.0] - 2022-12-06
10
+
11
+ ### Changed
12
+ - Use the /v1/batch endpoint for batching events (this should be backward compatible according to Segment) https://github.com/whatthewhat/simple_segment/pull/40 by [@sgallag-insta](https://github.com/sgallag-insta)
13
+
14
+ ## [1.4.0] - 2022-08-31
15
+
16
+ ### Added
17
+ - Add host option to support regional segments https://github.com/whatthewhat/simple_segment/pull/37 by [@larsklevan](https://github.com/larsklevan)
18
+
9
19
  ## [1.3.0] - 2021-11-27
10
20
 
11
21
  ### Added
12
- - Add support for message_id override https://github.com/whatthewhat/simple_segment/pull/34 by [@theblang][]
22
+ - Add support for message_id override https://github.com/whatthewhat/simple_segment/pull/34 by [@theblang](https://github.com/theblang)
13
23
 
14
24
  ## [1.2.0] - 2020-07-29
15
25
 
@@ -19,13 +29,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
19
29
  ## [1.1.0] - 2020-04-11
20
30
 
21
31
  ### Added
22
- - Added support for http_proxy and https_proxy environment variables https://github.com/whatthewhat/simple_segment/pull/26 by [@saks][]
32
+ - Added support for http_proxy and https_proxy environment variables https://github.com/whatthewhat/simple_segment/pull/26 by [@saks](https://github.com/saks)
23
33
  - Added Ruby 2.7 to travis.yml
24
34
 
25
35
  ## [1.0.0] - 2019-12-12
26
36
 
27
37
  ### Added
28
- - Allow passing custom Net::HTTP options (e.g. timeout) https://github.com/whatthewhat/simple_segment/pull/23 by [@barodeur][]
38
+ - Allow passing custom Net::HTTP options (e.g. timeout) https://github.com/whatthewhat/simple_segment/pull/23 by [@barodeur](https://github.com/barodeur)
29
39
 
30
40
  ### Changed
31
41
  - The gem is no longer tested with Ruby versions below 2.4
@@ -35,7 +45,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
35
45
  ### Changed
36
46
  - 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
37
47
 
38
- [Unreleased]: https://github.com/whatthewhat/simple_segment/compare/v1.3.0...HEAD
48
+ [Unreleased]: https://github.com/whatthewhat/simple_segment/compare/v1.5.0...HEAD
49
+ [1.5.0]: https://github.com/whatthewhat/simple_segment/compare/v1.4.0...v1.5.0
50
+ [1.4.0]: https://github.com/whatthewhat/simple_segment/compare/v1.3.0...v1.4.0
39
51
  [1.3.0]: https://github.com/whatthewhat/simple_segment/compare/v1.2.0...v1.3.0
40
52
  [1.2.0]: https://github.com/whatthewhat/simple_segment/compare/v1.1.0...v1.2.0
41
53
  [1.1.0]: https://github.com/whatthewhat/simple_segment/compare/v1.0.0...v1.1.0
data/README.md CHANGED
@@ -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.
@@ -48,7 +48,7 @@ module SimpleSegment
48
48
  raise ArgumentError, 'A batch must contain at least one action'
49
49
  end
50
50
 
51
- Request.new(client).post('/v1/import', payload)
51
+ Request.new(client).post('/v1/batch', payload)
52
52
  end
53
53
 
54
54
  private
@@ -56,7 +56,7 @@ module SimpleSegment
56
56
  def add(operation_class, options, action)
57
57
  operation = operation_class.new(client, symbolize_keys(options))
58
58
  operation_payload = operation.build_payload
59
- operation_payload[:action] = action
59
+ operation_payload[:type] = action
60
60
  payload[:batch] << operation_payload
61
61
  end
62
62
  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
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SimpleSegment
4
- VERSION = '1.3.0'
4
+ VERSION = '1.5.0'
5
5
  end
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency 'rake', '>= 10.0'
26
26
  spec.add_development_dependency 'rspec', '~> 3.0'
27
27
  spec.add_development_dependency 'rubocop', '1.23.0'
28
- spec.add_development_dependency 'timecop', '~> 0.8.0'
28
+ spec.add_development_dependency 'timecop', '~> 0.9.5'
29
29
  spec.add_development_dependency 'webmock', '~> 3.7'
30
30
  spec.metadata = {
31
31
  'rubygems_mfa_required' => 'true'
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.3.0
4
+ version: 1.5.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: 2021-11-26 00:00:00.000000000 Z
11
+ date: 2022-12-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -86,14 +86,14 @@ dependencies:
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
@@ -149,7 +149,7 @@ licenses:
149
149
  - MIT
150
150
  metadata:
151
151
  rubygems_mfa_required: 'true'
152
- post_install_message:
152
+ post_install_message:
153
153
  rdoc_options: []
154
154
  require_paths:
155
155
  - lib
@@ -165,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
165
  version: '0'
166
166
  requirements: []
167
167
  rubygems_version: 3.1.6
168
- signing_key:
168
+ signing_key:
169
169
  specification_version: 4
170
170
  summary: A simple synchronous API client for segment.io.
171
171
  test_files: []