ur 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -1
- data/README.md +12 -0
- data/lib/ur.rb +13 -9
- data/lib/ur/faraday/yield_ur.rb +4 -2
- data/lib/ur/version.rb +1 -1
- data/ur.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06e6df921036d0111ac6b57e937508d5689d30bbb702ebfc691749a9c31884ed
|
4
|
+
data.tar.gz: d160635a422395081f510059b7916aa9264c3289c3cc1d9170769c32c6d1cbb3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41b9e773174eb1beaa88b128ebde4e75830e4c9bc9ee907bcbf24e9be7157ba0cff8a980bdc8b18a978a02d990d7933dcd3ae88fdacba81ed59f87046d36a559
|
7
|
+
data.tar.gz: 42dc377e5da9acccb960e35dea7d7d874c5a90b5965b025b0dd2a8c6443b89eae282f1f034bcee450dd8962bb06470d7016cbeaebf24871e3851853db83654ff
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -2,6 +2,18 @@
|
|
2
2
|
|
3
3
|
Ur: Unified Request/Response Representation in Ruby
|
4
4
|
|
5
|
+
## Properties
|
6
|
+
|
7
|
+
An ur primarily consists of a request, a response, and additional processing information.
|
8
|
+
|
9
|
+
The request consists of the request method, uri, headers, and body.
|
10
|
+
|
11
|
+
The response consists of the response status, headers, and body.
|
12
|
+
|
13
|
+
The processing information consists of the time the request began, the duration of the request, or tag strings. This is optional.
|
14
|
+
|
15
|
+
Other attributes may be present, and are ignored by this library.
|
16
|
+
|
5
17
|
## Usage with middleware
|
6
18
|
|
7
19
|
Rack middleware:
|
data/lib/ur.rb
CHANGED
@@ -71,7 +71,17 @@ class Ur
|
|
71
71
|
|
72
72
|
new({'bound' => 'inbound'}).tap do |ur|
|
73
73
|
ur.processing.begin!
|
74
|
+
|
74
75
|
ur.request['method'] = rack_request.request_method
|
76
|
+
|
77
|
+
ur.request.addressable_uri = Addressable::URI.new(
|
78
|
+
:scheme => rack_request.scheme,
|
79
|
+
:host => rack_request.host,
|
80
|
+
:port => rack_request.port,
|
81
|
+
:path => rack_request.path,
|
82
|
+
:query => (rack_request.query_string unless rack_request.query_string.empty?)
|
83
|
+
)
|
84
|
+
|
75
85
|
ur.request.headers = env.map do |(key, value)|
|
76
86
|
http_match = key.match(/\AHTTP_/)
|
77
87
|
if http_match
|
@@ -84,13 +94,7 @@ class Ur
|
|
84
94
|
end
|
85
95
|
end
|
86
96
|
end.compact.inject({}, &:update)
|
87
|
-
|
88
|
-
:scheme => rack_request.scheme,
|
89
|
-
:host => rack_request.host,
|
90
|
-
:port => rack_request.port,
|
91
|
-
:path => rack_request.path,
|
92
|
-
:query => (rack_request.query_string unless rack_request.query_string.empty?)
|
93
|
-
)
|
97
|
+
|
94
98
|
env["rack.input"].rewind
|
95
99
|
ur.request.body = env["rack.input"].read
|
96
100
|
env["rack.input"].rewind
|
@@ -101,15 +105,14 @@ class Ur
|
|
101
105
|
new({'bound' => 'outbound'}).tap do |ur|
|
102
106
|
ur.processing.begin!
|
103
107
|
ur.request['method'] = request_env[:method].to_s
|
104
|
-
ur.request.headers = request_env[:request_headers]
|
105
108
|
ur.request.uri = request_env[:url].normalize.to_s
|
109
|
+
ur.request.headers = request_env[:request_headers]
|
106
110
|
ur.request.set_body_from_faraday(request_env)
|
107
111
|
end
|
108
112
|
end
|
109
113
|
end
|
110
114
|
|
111
115
|
def initialize(ur = {}, **opt, &b)
|
112
|
-
ur = JSI::JSON::Node.new_doc(ur) unless ur.is_a?(JSI::JSON::Node)
|
113
116
|
super(ur, **opt, &b)
|
114
117
|
unless instance.respond_to?(:to_hash)
|
115
118
|
raise(TypeError, "expected hash argument. got: #{ur.pretty_inspect.chomp}")
|
@@ -158,6 +161,7 @@ class Ur
|
|
158
161
|
schema['properties'].each do |property_name, property_schema|
|
159
162
|
if property_schema['type'] == 'object' && property_schema['properties']
|
160
163
|
property_schema['properties'].each_key do |property_property_name|
|
164
|
+
# ur.request_method => ur['request']['method']
|
161
165
|
define_method("#{property_name}_#{property_property_name}") do
|
162
166
|
self[property_name][property_property_name]
|
163
167
|
end
|
data/lib/ur/faraday/yield_ur.rb
CHANGED
@@ -2,14 +2,16 @@ class Ur
|
|
2
2
|
module Faraday
|
3
3
|
class YieldUr < ::Faraday::Middleware
|
4
4
|
def initialize(app, options = {}, &block)
|
5
|
+
raise(ArgumentError, "no block given to yield ur") unless block
|
6
|
+
raise(TypeError, "options must be a Hash") unless options.respond_to?(:to_hash)
|
5
7
|
@app = app
|
6
8
|
@options = options
|
7
9
|
@yield_to = block
|
8
10
|
end
|
9
11
|
|
10
12
|
def call(request_env)
|
11
|
-
ur =
|
12
|
-
ur.logger = @options[:logger]
|
13
|
+
ur = (@options[:ur_class] || Ur).from_faraday_request(request_env)
|
14
|
+
ur.logger = @options[:logger] if @options[:logger]
|
13
15
|
ur.faraday_on_complete(@app, request_env) do |response_env|
|
14
16
|
@yield_to.call(ur)
|
15
17
|
end
|
data/lib/ur/version.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
UR_VERSION = "0.0.
|
1
|
+
UR_VERSION = "0.0.4".freeze
|
data/ur.gemspec
CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
29
|
spec.require_paths = ["lib"]
|
30
30
|
|
31
|
-
spec.add_dependency "jsi", "~> 0.
|
31
|
+
spec.add_dependency "jsi", "~> 0.2.0"
|
32
32
|
spec.add_dependency "addressable", "~> 2.0"
|
33
33
|
spec.add_development_dependency "rack"
|
34
34
|
spec.add_development_dependency "rack-test"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ur
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ethan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-11-
|
11
|
+
date: 2019-11-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jsi
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.2.0
|
20
20
|
type: :runtime
|
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: 0.
|
26
|
+
version: 0.2.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: addressable
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|