salestation 3.5.0 → 3.8.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 4fd4756c2f6c74060b5a8fc8d7c86c8b4e4b78ec
4
- data.tar.gz: 74aae6794e107f5d25f6bbffd92f43e7d940b469
2
+ SHA256:
3
+ metadata.gz: b5082a680af9f209df45163e85fbaf36ee19c08f752f8bba5fdcc6b33268da7f
4
+ data.tar.gz: 367153d32a664158e42d94d9b61f9e96693ee054b6d0944ad9c2ef0f299902fb
5
5
  SHA512:
6
- metadata.gz: 500d7c1894f02b898ff7b6c7cea53b3fc84699440b1d031bdca0c3f9d12dc2e463c3360d768386e53ed31d18e44e6cb7d04af73d6238173e8b7c52740c3c305c
7
- data.tar.gz: 2372c5e2e508edc5949b00476e5e4dc93ffd48d4996d686584b49b943792c83f3b5f384854f5e986896235cb76b220d6931d1c79ebe9252fee08ed794199c125
6
+ metadata.gz: c4a938998c2bc6b4480d9de13390998fccce96de4d2a65ad5814d033ef647aafce66ab7250546cf5e3f3794c4ab0341c411d91fefe4a562db2078aad2c2b91f4
7
+ data.tar.gz: 4884f0bff30fea0101d0b34bb47d0fdccea566c0c273da98ba91bc1f8798416506e8aafa922f2de642dd0b212dd34565fa0826f825374604927f77fa2041e65b
@@ -1,6 +1,4 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.4
5
- - 2.5
6
- before_install: gem install bundler -v 1.17.3
4
+ - 2.7
data/README.md CHANGED
@@ -142,14 +142,14 @@ end
142
142
 
143
143
  Salestation provides a StatsD middleware which can be used record request
144
144
  execution time. A `timing` call with elapsed seconds is made to the provided
145
- StatsD instance with `path`, `method`, `status` tags.
145
+ StatsD instance with `path`, `method`, `status` and `status_class` tags.
146
146
 
147
147
  ```ruby
148
148
  class Webapp < Sinatra::Base
149
149
  # ...
150
150
  use Salestation::Web::StatsdMiddleware,
151
151
  Statsd.new(host, port),
152
- metric: 'my-metric'
152
+ metric: 'my_service.response.time'
153
153
  end
154
154
  ```
155
155
 
@@ -157,7 +157,7 @@ You can configure per-request tags by defining `salestation.statsd.tags` in sina
157
157
 
158
158
  ```ruby
159
159
  def my_handler(env)
160
- env['salestation.statsd.tags'] = ['foo', 'bar']
160
+ env['salestation.statsd.tags'] = ['foo:bar']
161
161
  # ...
162
162
  end
163
163
  ```
@@ -7,7 +7,7 @@ require 'dry-types'
7
7
  module Salestation
8
8
  class App
9
9
  module Types
10
- include Dry::Types.module
10
+ include Dry::Types()
11
11
  end
12
12
 
13
13
  def initialize(env:, hooks: {})
@@ -5,7 +5,7 @@ module Salestation
5
5
  module Errors
6
6
  class InvalidInput < Dry::Struct
7
7
  attribute :errors, Types::Strict::Hash
8
- attribute :hints, Types::Coercible::Hash.default({})
8
+ attribute :hints, Types::Coercible::Hash.default({}.freeze)
9
9
  attribute? :debug_message, Types::Strict::String
10
10
  end
11
11
 
@@ -8,7 +8,7 @@ require 'json'
8
8
  module Salestation
9
9
  class Web < Module
10
10
  module Types
11
- include Dry::Types.module
11
+ include Dry::Types()
12
12
  end
13
13
 
14
14
  def initialize(errors: {})
@@ -32,19 +32,27 @@ module Salestation
32
32
  class Error < Response
33
33
  attribute :status, Types::Strict::Integer
34
34
  attribute :message, Types::Strict::String
35
- attribute :debug_message, Types::String.default('')
36
- attribute :context, Types::Hash.default({})
37
- attribute :headers, Types::Hash.default({})
35
+ attribute :debug_message, Types::Coercible::String.default('')
36
+ attribute :context, Types::Hash.default({}.freeze)
37
+ attribute :headers, Types::Hash.default({}.freeze)
38
38
 
39
39
  def body
40
40
  {message: message, debug_message: debug_message}
41
41
  end
42
42
  end
43
43
 
44
+ class UnprocessableEntityError < Error
45
+ attribute :form_errors, Types::Hash.default({}.freeze)
46
+
47
+ def body
48
+ super.merge(form_errors: form_errors)
49
+ end
50
+ end
51
+
44
52
  class Success < Response
45
53
  attribute :status, Types::Strict::Integer
46
54
  attribute :body, Types::Strict::Hash | Types::Strict::Array
47
- attribute :headers, Types::Hash.default({})
55
+ attribute :headers, Types::Hash.default({}.freeze)
48
56
  end
49
57
 
50
58
  class UnprocessableEntityFromSchemaErrors
@@ -52,7 +60,7 @@ module Salestation
52
60
  message = parse_errors(errors)
53
61
  debug_message = parse_hints(hints)
54
62
 
55
- UnprocessableEntity.new(message: message, debug_message: debug_message)
63
+ UnprocessableEntity.new(message: message, debug_message: debug_message, form_errors: errors)
56
64
  end
57
65
 
58
66
  def self.parse_errors(errors)
@@ -99,7 +107,7 @@ module Salestation
99
107
  Conflict = Error.with_code(409)
100
108
  RequestEntityTooLarge = Error.with_code(413)
101
109
  UnsupportedMediaType = Error.with_code(415)
102
- UnprocessableEntity = Error.with_code(422)
110
+ UnprocessableEntity = UnprocessableEntityError.with_code(422)
103
111
 
104
112
  InternalError = Error.with_code(500)
105
113
  ServiceUnavailable = Error.with_code(503)
@@ -5,7 +5,7 @@ module Salestation
5
5
  class StatsdMiddleware
6
6
  EXTRA_TAGS_ENV_KEY = 'salestation.statsd.tags'
7
7
 
8
- DURATION_PRECISION = 6
8
+ DURATION_MILLISECOND_PRECISION = 3
9
9
 
10
10
  def initialize(app, statsd, metric:)
11
11
  @app = app
@@ -27,20 +27,21 @@ module Salestation
27
27
  end
28
28
 
29
29
  tags = [
30
- "path:#{ path }",
31
- "method:#{ method }",
32
- "status:#{ status }"
30
+ "path:#{path}",
31
+ "method:#{method}",
32
+ "status:#{status}",
33
+ "status_class:#{status / 100}xx"
33
34
  ] + env.fetch(EXTRA_TAGS_ENV_KEY, [])
34
35
 
35
- @statsd.timing(@metric, duration(from: start), tags: tags)
36
+ @statsd.timing(@metric, duration_ms(from: start), tags: tags)
36
37
 
37
38
  [status, header, body]
38
39
  end
39
40
 
40
41
  private
41
42
 
42
- def duration(from:)
43
- (system_monotonic_time - from).round(DURATION_PRECISION)
43
+ def duration_ms(from:)
44
+ ((system_monotonic_time - from) * 1000).round(DURATION_MILLISECOND_PRECISION)
44
45
  end
45
46
 
46
47
  def system_monotonic_time
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "salestation"
7
- spec.version = "3.5.0"
7
+ spec.version = "3.8.1"
8
8
  spec.authors = ["Glia TechMovers"]
9
9
  spec.email = ["techmovers@glia.com"]
10
10
 
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.add_development_dependency "bundler", "~> 1.13"
22
+ spec.add_development_dependency "bundler", "~> 2.0"
23
23
  spec.add_development_dependency "rake", "~> 13.0"
24
24
  spec.add_development_dependency "rspec", "~> 3.0"
25
25
  spec.add_development_dependency "pry", "~> 0.10.4"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: salestation
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.5.0
4
+ version: 3.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Glia TechMovers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-09 00:00:00.000000000 Z
11
+ date: 2020-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.13'
19
+ version: '2.0'
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: '1.13'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -158,8 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
158
  - !ruby/object:Gem::Version
159
159
  version: '0'
160
160
  requirements: []
161
- rubyforge_project:
162
- rubygems_version: 2.6.14.4
161
+ rubygems_version: 3.0.3
163
162
  signing_key:
164
163
  specification_version: 4
165
164
  summary: ''