salestation 0.11.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +12 -20
- data/lib/salestation/app/errors.rb +0 -16
- data/lib/salestation/web.rb +6 -1
- data/lib/salestation/web/responses.rb +6 -12
- data/salestation.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 46cd68d7bab2619bbe24c7c01e668b7e6d5279db7e116a024b4860c43cbe1f8c
|
4
|
+
data.tar.gz: 4e6ce42687e5ff792d425d6d2c1ed80b230fa9c1ca57d16b107c976c961d749c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0c6b7c774c875f6b24c195dbf9300bdca6a70ea288c6ebd80d0612f801b5a058b726dd936ecedb1e1818c4d50bb1b7e4f11de0188613a6fc7f07b8735be94f5
|
7
|
+
data.tar.gz: 4af44c26fa86b7d2f3b3bd3305feb035723934419becdb5e113e5efe4630ea488638a401b5e199bfc30dc27c2fa875353577e9b0fcf738349096432a4365eee0
|
data/README.md
CHANGED
@@ -86,8 +86,15 @@ Multiple extractors can be merged together. If two or more extractors use the sa
|
|
86
86
|
Define a route
|
87
87
|
|
88
88
|
```ruby
|
89
|
+
include Salestation::Web.new
|
89
90
|
include Salestation::Web::Extractors
|
90
91
|
|
92
|
+
APP = Salestation::App.new(env: {})
|
93
|
+
|
94
|
+
def create_app_request
|
95
|
+
-> (input) { App.create_request(input) }
|
96
|
+
end
|
97
|
+
|
91
98
|
post '/hello/:name' do |name|
|
92
99
|
coercions = {age: ->(age) { age.to_s }}
|
93
100
|
|
@@ -95,27 +102,12 @@ post '/hello/:name' do |name|
|
|
95
102
|
.merge(ConstantInput[name: name])
|
96
103
|
.merge(HeadersExtractor[{'authorization' => :auth}])
|
97
104
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
end
|
105
|
+
response = extractor.call(request)
|
106
|
+
.map(create_app_request)
|
107
|
+
.map(HelloUser)
|
108
|
+
.map(Responses.to_ok)
|
103
109
|
|
104
|
-
|
105
|
-
|
106
|
-
def process(extract_input, &process_request)
|
107
|
-
response = extract_input.call(request).match do
|
108
|
-
Success() do |value|
|
109
|
-
create_request(value)
|
110
|
-
.map(process_request)
|
111
|
-
.map_err(&ERROR_MAPPER.map)
|
112
|
-
end
|
113
|
-
Failure() do |value|
|
114
|
-
Result::Success(value)
|
115
|
-
end
|
116
|
-
end
|
117
|
-
rescue Salestation::Web::ErrorMapper::UndefinedErrorClass => exception
|
118
|
-
raise exception
|
110
|
+
process(response)
|
119
111
|
end
|
120
112
|
```
|
121
113
|
|
@@ -2,54 +2,38 @@ module Salestation
|
|
2
2
|
class App
|
3
3
|
module Errors
|
4
4
|
class InvalidInput < Dry::Struct
|
5
|
-
constructor_type :strict_with_defaults
|
6
|
-
|
7
5
|
attribute :errors, Types::Strict::Hash
|
8
6
|
attribute :hints, Types::Coercible::Hash.default({})
|
9
7
|
end
|
10
8
|
|
11
9
|
class DependencyCurrentlyUnavailable < Dry::Struct
|
12
|
-
constructor_type :strict
|
13
|
-
|
14
10
|
attribute :message, Types::Strict::String
|
15
11
|
end
|
16
12
|
|
17
13
|
class RequestedResourceNotFound < Dry::Struct
|
18
|
-
constructor_type :strict
|
19
|
-
|
20
14
|
attribute :message, Types::Strict::String
|
21
15
|
end
|
22
16
|
|
23
17
|
class Forbidden < Dry::Struct
|
24
|
-
constructor_type :strict
|
25
|
-
|
26
18
|
attribute :message, Types::Strict::String
|
27
19
|
end
|
28
20
|
|
29
21
|
class Conflict < Dry::Struct
|
30
|
-
constructor_type :strict
|
31
|
-
|
32
22
|
attribute :message, Types::Strict::String
|
33
23
|
attribute :debug_message, Types::Strict::String
|
34
24
|
end
|
35
25
|
|
36
26
|
class NotAcceptable < Dry::Struct
|
37
|
-
constructor_type :strict
|
38
|
-
|
39
27
|
attribute :message, Types::Strict::String
|
40
28
|
attribute :debug_message, Types::Strict::String
|
41
29
|
end
|
42
30
|
|
43
31
|
class UnsupportedMediaType < Dry::Struct
|
44
|
-
constructor_type :strict
|
45
|
-
|
46
32
|
attribute :message, Types::Strict::String
|
47
33
|
attribute :debug_message, Types::Strict::String
|
48
34
|
end
|
49
35
|
|
50
36
|
class RequestEntityTooLarge < Dry::Struct
|
51
|
-
constructor_type :strict
|
52
|
-
|
53
37
|
attribute :message, Types::Strict::String
|
54
38
|
end
|
55
39
|
end
|
data/lib/salestation/web.rb
CHANGED
@@ -20,7 +20,12 @@ module Salestation
|
|
20
20
|
const_set :Responses, Salestation::Web::Responses
|
21
21
|
|
22
22
|
define_method(:process) do |response|
|
23
|
-
result =
|
23
|
+
result =
|
24
|
+
if response.value.is_a?(Salestation::Web::Responses::Response)
|
25
|
+
response.value
|
26
|
+
else
|
27
|
+
response.map_err(error_mapper.map).value
|
28
|
+
end
|
24
29
|
|
25
30
|
status result.status
|
26
31
|
json result.body
|
@@ -17,8 +17,8 @@ module Salestation
|
|
17
17
|
-> (*) { Deterministic::Result::Success(Responses::NoContent.new(body: {})) }
|
18
18
|
end
|
19
19
|
|
20
|
-
|
21
|
-
def with_code(code)
|
20
|
+
class Response < Dry::Struct
|
21
|
+
def self.with_code(code)
|
22
22
|
Class.new(self) do
|
23
23
|
define_singleton_method :new do |attrs|
|
24
24
|
super(attrs.merge(status: code))
|
@@ -27,11 +27,8 @@ module Salestation
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
class Error <
|
31
|
-
|
32
|
-
constructor_type :strict_with_defaults
|
33
|
-
|
34
|
-
attribute :status, Types::Strict::Int
|
30
|
+
class Error < Response
|
31
|
+
attribute :status, Types::Strict::Integer
|
35
32
|
attribute :message, Types::Strict::String
|
36
33
|
attribute :debug_message, Types::String.default('')
|
37
34
|
attribute :context, Types::Hash.default({})
|
@@ -41,11 +38,8 @@ module Salestation
|
|
41
38
|
end
|
42
39
|
end
|
43
40
|
|
44
|
-
class Success <
|
45
|
-
|
46
|
-
constructor_type :strict
|
47
|
-
|
48
|
-
attribute :status, Types::Strict::Int
|
41
|
+
class Success < Response
|
42
|
+
attribute :status, Types::Strict::Integer
|
49
43
|
attribute :body, Types::Strict::Hash | Types::Strict::Array
|
50
44
|
end
|
51
45
|
|
data/salestation.gemspec
CHANGED
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: 0.
|
4
|
+
version: 0.12.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:
|
11
|
+
date: 2018-08-08 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
|
159
|
+
rubygems_version: 2.7.6
|
160
160
|
signing_key:
|
161
161
|
specification_version: 4
|
162
162
|
summary: ''
|