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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 87b35ba597a897efe98627c42379ea8ad07796bda96bcc937efaf2695d690618
4
- data.tar.gz: c16c03ab3bd0038fa8b3b6d7448c1e2f3395a89fab5b0028b59076917c113c39
3
+ metadata.gz: 06e6df921036d0111ac6b57e937508d5689d30bbb702ebfc691749a9c31884ed
4
+ data.tar.gz: d160635a422395081f510059b7916aa9264c3289c3cc1d9170769c32c6d1cbb3
5
5
  SHA512:
6
- metadata.gz: 7378736285ca4afe01785e7da1df1c7ceb157880c50656f3119565d08dab9d69c89485c0b6ac28ba18d68594391b94c9a29d55cd31b86ecc91bd56b315c081c7
7
- data.tar.gz: 12296a2e2334a9bec5bb618483bf15dd01ef13af98cc6577fa79ccafe424c75f1b68899be25515a07cc451915026c19d9401e3a34445ee16cb4f7ee76d133507
6
+ metadata.gz: 41b9e773174eb1beaa88b128ebde4e75830e4c9bc9ee907bcbf24e9be7157ba0cff8a980bdc8b18a978a02d990d7933dcd3ae88fdacba81ed59f87046d36a559
7
+ data.tar.gz: 42dc377e5da9acccb960e35dea7d7d874c5a90b5965b025b0dd2a8c6443b89eae282f1f034bcee450dd8962bb06470d7016cbeaebf24871e3851853db83654ff
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
+ # v0.0.4
2
+ - bump JSI v0.2.0
3
+
1
4
  # v0.0.3
2
- - bump JSI version
5
+ - bump JSI v0.1.0
3
6
 
4
7
  # v0.0.2
5
8
 
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
- ur.request.addressable_uri = Addressable::URI.new(
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
@@ -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 = Scorpio::Ur.from_faraday_request(request_env)
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.3"
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.1.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.3
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-25 00:00:00.000000000 Z
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.1.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.1.0
26
+ version: 0.2.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: addressable
29
29
  requirement: !ruby/object:Gem::Requirement