salestation 1.0.2 → 2.0.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
- SHA1:
3
- metadata.gz: e2f1a0952d479679a0e165cab5e87f2d5a6d49b7
4
- data.tar.gz: 2b4a7e851aad8310f98c001fb8a0452fe757a244
2
+ SHA256:
3
+ metadata.gz: dc82a6d835313f9a3dc307f08087dde23916dabccc6805aee7d4e2c8e1f7b9b2
4
+ data.tar.gz: a0088243adf9f2dae6c119b86c836138627475cc1a11a9b07a7171ff9adcecc2
5
5
  SHA512:
6
- metadata.gz: f993f4a6ee270c184337a32098346693ccc2eaaa8a2dc7ccfa195a2a4350f958f3542986330db96e82cb069f872b764623f28d0a8d8c9536110ebdeed9e5b619
7
- data.tar.gz: ec9f62fceec3395c27d0ed8fd719ae3b5454ca0dc5e22bd6703ebbc25c7118b1d9747ad3a95acca423973f0f33aefc9f8d8bdf764a92c005a642d0ca86d784a8
6
+ metadata.gz: 82e2007245ee0fc1c1f0170f063c658d837af57df50f126bcaae10eb3b245f5c895699010f8013ccbbd3d8333f1ec187beceb6f994061d7385b488f1ac33a890
7
+ data.tar.gz: 2c4510ad5f22ab4e548197dca991b68bf238d166572a5b63eb0d579139a9c47feb31ad43638670bcf79617bd8fc3c021f9d2c48a86afa3af1b8d3a5d915768a8
data/.travis.yml CHANGED
@@ -1,5 +1,6 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.2.4
5
- before_install: gem install bundler -v 1.13.6
4
+ - 2.4
5
+ - 2.5
6
+ before_install: gem install bundler -v 1.17.3
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Salestation
2
4
  class App
3
5
  module Errors
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Salestation
2
4
  class App
3
5
  module InputVerification
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Salestation
2
4
  class App
3
5
  class Request
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'deterministic'
2
4
  require 'dry-struct'
3
5
  require 'dry-types'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Salestation
2
4
  module ResultHelper
3
5
  def observe(&block)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Salestation
2
4
  class Web < Module
3
5
  class ActiveRecordConnectionManagement
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Salestation
2
4
  class Web < Module
3
5
  class ErrorMapper
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Salestation
2
4
  class Web < Module
3
5
  module Extractors
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'securerandom'
2
4
  require 'json'
3
5
 
@@ -5,15 +7,15 @@ module Salestation
5
7
  class Web < Module
6
8
  class RequestLogger
7
9
 
8
- REMOTE_ADDR = 'REMOTE_ADDR'.freeze
9
- REQUEST_URI = 'REQUEST_URI'.freeze
10
- REQUEST_METHOD = 'REQUEST_METHOD'.freeze
11
- QUERY_STRING = 'QUERY_STRING'.freeze
12
- CONTENT_TYPE = 'CONTENT_TYPE'.freeze
13
- HTTP_USER_AGENT = 'HTTP_USER_AGENT'.freeze
14
- HTTP_ACCEPT = 'HTTP_ACCEPT'.freeze
15
- SERVER_NAME = 'SERVER_NAME'.freeze
16
- JSON_CONTENT_TYPE = 'application/json'.freeze
10
+ REMOTE_ADDR = 'REMOTE_ADDR'
11
+ REQUEST_URI = 'REQUEST_URI'
12
+ REQUEST_METHOD = 'REQUEST_METHOD'
13
+ QUERY_STRING = 'QUERY_STRING'
14
+ CONTENT_TYPE = 'CONTENT_TYPE'
15
+ HTTP_USER_AGENT = 'HTTP_USER_AGENT'
16
+ HTTP_ACCEPT = 'HTTP_ACCEPT'
17
+ SERVER_NAME = 'SERVER_NAME'
18
+ JSON_CONTENT_TYPE = 'application/json'
17
19
 
18
20
  def initialize(app, logger, log_response_body: true)
19
21
  @app = app
@@ -22,23 +24,18 @@ module Salestation
22
24
  end
23
25
 
24
26
  def call(env)
25
- request_id = SecureRandom.hex(4)
26
- request_logger = Logger.new(@logger, request_id)
27
-
28
- env['request_logger'] = request_logger
29
27
  began_at = Time.now
30
28
 
31
- request_logger.info('Received request', request_log(env))
32
29
  @app.call(env).tap do |status, headers, body|
33
30
  type = status >= 500 ? :error : :info
34
- request_logger.public_send(type, 'Processed request', response_log(env, status, headers, body, began_at))
31
+ @logger.public_send(type, 'Processed request', response_log(env, status, headers, body, began_at))
35
32
  end
36
33
  end
37
34
 
38
35
  private
39
36
 
40
- def request_log(env)
41
- {
37
+ def response_log(env, status, headers, body, began_at)
38
+ log = {
42
39
  remote_addr: env[REMOTE_ADDR],
43
40
  method: env[REQUEST_METHOD],
44
41
  path: env[REQUEST_URI],
@@ -46,50 +43,32 @@ module Salestation
46
43
  content_type: env[CONTENT_TYPE],
47
44
  http_agent: env[HTTP_USER_AGENT],
48
45
  http_accept: env[HTTP_ACCEPT],
49
- server_name: env[SERVER_NAME]
46
+ server_name: env[SERVER_NAME],
47
+ status: status,
48
+ duration: Time.now - began_at,
49
+ headers: headers
50
50
  }
51
- end
52
-
53
- def response_log(env, status, headers, body, began_at)
54
- response_payload =
55
- if status >= 400
56
- { error: parse_body(body, env) }
57
- elsif @log_response_body
58
- { body: parse_body(body, env) }
59
- else
60
- {}
61
- end
62
51
 
63
- {
64
- path: env[REQUEST_URI],
65
- method: env[REQUEST_METHOD],
66
- status: status,
67
- duration: Time.now - began_at,
68
- headers: headers
69
- }.merge(response_payload)
70
- end
71
-
72
- def parse_body(body, env)
73
- begin
74
- # Rack body is an array
75
- return {} if body.empty?
76
- JSON.parse(body.join)
77
- rescue Exception
78
- {error: 'Failed to parse response body'}
52
+ if status >= 400
53
+ log[:error] = parse_body(body)
54
+ elsif @log_response_body
55
+ log[:body] = parse_body(body)
79
56
  end
57
+
58
+ log
80
59
  end
81
60
 
82
- class Logger
83
- def initialize(logger, request_id)
84
- @logger = logger
85
- @request_id = request_id
86
- end
61
+ def parse_body(body)
62
+ # Rack body is an array
63
+ return {} if body.empty?
87
64
 
88
- [:debug, :info, :warn, :error].each do |name|
89
- define_method(name) do |msg, metadata = {}|
90
- @logger.public_send(name, msg, metadata.merge(request_id: @request_id))
91
- end
65
+ if defined?(Oj)
66
+ Oj.load(body.join)
67
+ else
68
+ JSON.parse(body.join)
92
69
  end
70
+ rescue Exception
71
+ {error: 'Failed to parse response body'}
93
72
  end
94
73
  end
95
74
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Salestation
2
4
  class Web < Module
3
5
  module Responses
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Salestation
2
4
  class Web < Module
3
5
  class StatsdMiddleware
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'deterministic'
2
4
  require 'dry-struct'
3
5
  require 'dry-types'
data/lib/salestation.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative './salestation/app'
2
4
  require_relative './salestation/web'
3
5
 
data/salestation.gemspec CHANGED
@@ -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 = "1.0.2"
7
+ spec.version = "2.0.0"
8
8
  spec.authors = ["SaleMove TechMovers"]
9
9
  spec.email = ["techmovers@salemove.com"]
10
10
 
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: 1.0.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - SaleMove TechMovers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-07 00:00:00.000000000 Z
11
+ date: 2019-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -156,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
156
  version: '0'
157
157
  requirements: []
158
158
  rubyforge_project:
159
- rubygems_version: 2.6.11
159
+ rubygems_version: 2.7.6
160
160
  signing_key:
161
161
  specification_version: 4
162
162
  summary: ''