twirp 1.9.0 → 1.10.0

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
2
  SHA256:
3
- metadata.gz: 2564512dae1e9dcb9345119a0e09ffa0a65bba37c3800a9c6ac6c77c900701cf
4
- data.tar.gz: da232ae6c1526bb650fbc32b106191c533e8aa6c11b682d6d28044d612f0def8
3
+ metadata.gz: 2bd8003fe6ecc7f8636213eaf73a6c8b8455fd4e58adb8fb0a7400fdd5f19492
4
+ data.tar.gz: ec29ec78920b6451469fa05edcc69f4eec4162d79bbebfdf3d4ef2027a39df33
5
5
  SHA512:
6
- metadata.gz: 41cbdba9e68278362f8674d6b28336c97a13da955535abbbc5b148f006cee1e1413f76df3daa9e93fb1c80297fcfa7d6c1828591a44680bcd4025ca340f0aacc
7
- data.tar.gz: b381e1be9c43e0836bf47f60b98e14dc14cdf5ceb444597abd8cc7587e8162b4f7c8feff4f821e50cafa9a68e5db060359c474d8c2d30a5903a16d6e5db24454
6
+ metadata.gz: 58571087c354beb83cf23204abae8f64cb6ea4f3f9d75c8cb68fdaf7e9d282d05b09a37dc2458b60c946e3d930dfa64fef10f9391f0233ed5f71d75aa9ba4bf9
7
+ data.tar.gz: 55f7b4b75c4381a9144127b899c146f9b3841b49009438f123ac66d95db60aa6decf290e1dd30222eb339e062c92291d4008deb580a8798b738c6af27eb1af60
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Twirp-Ruby
2
2
 
3
- [Twirp is a protocol](https://twitchtv.github.io/twirp/docs/spec_v5.html) for routing and serialization of services defined in a [.proto file](https://developers.google.com/protocol-buffers/docs/proto3), allowing easy implementation of RPC services with auto-generated clients in different languages.
3
+ [![Run Tests](https://github.com/github/twirp-ruby/actions/workflows/tests.yml/badge.svg)](https://github.com/github/twirp-ruby/actions/workflows/tests.yml)
4
+
5
+ [Twirp is a protocol](https://github.github.io/twirp/docs/spec_v5.html) for routing and serialization of services defined in a [.proto file](https://developers.google.com/protocol-buffers/docs/proto3), allowing easy implementation of RPC services with auto-generated clients in different languages.
4
6
 
5
7
  The [canonical implementation](https://github.com/twitchtv/twirp) is in Golang. The Twirp-Ruby project is the official implementation in Ruby for both server and clients.
6
8
 
@@ -9,14 +11,18 @@ The [canonical implementation](https://github.com/twitchtv/twirp) is in Golang.
9
11
 
10
12
  Add `gem "twirp"` to your Gemfile, or install with `gem install twirp`.
11
13
 
12
- To auto-generate Ruby code from a proto file, use the `protoc` plugin and the `--ruby_out` option ([see Wiki page](https://github.com/twitchtv/twirp-ruby/wiki/Code-Generation)).
14
+ To auto-generate Ruby code from a proto file, use the `protoc` plugin and the `--ruby_out` option ([see Wiki page](https://github.com/github/twirp-ruby/wiki/Code-Generation)).
13
15
 
14
16
 
15
17
  ## Documentation
16
18
 
17
- [On the wiki](https://github.com/twitchtv/twirp-ruby/wiki).
19
+ [On the wiki](https://github.com/github/twirp-ruby/wiki).
18
20
 
19
21
 
20
22
  ## Contributing
21
23
 
22
24
  [On the CONTRIBUTING file](CONTRIBUTING.md).
25
+
26
+ ## Releases and changes
27
+
28
+ See the [releases](https://github.com/github/twirp-ruby/releases) page for latest information about released versions.
data/lib/twirp/client.rb CHANGED
@@ -151,7 +151,7 @@ module Twirp
151
151
  def rpc(rpc_method, input, req_opts=nil)
152
152
  rpcdef = self.class.rpcs[rpc_method.to_s]
153
153
  if !rpcdef
154
- return ClientResp.new(nil, Twirp::Error.bad_route("rpc not defined on this client"))
154
+ return ClientResp.new(error: Twirp::Error.bad_route("rpc not defined on this client"))
155
155
  end
156
156
 
157
157
  content_type = (req_opts && req_opts[:headers] && req_opts[:headers]['Content-Type']) || @content_type
@@ -186,15 +186,15 @@ module Twirp
186
186
 
187
187
  def rpc_response_to_clientresp(resp, content_type, rpcdef)
188
188
  if resp.status != 200
189
- return ClientResp.new(nil, self.class.error_from_response(resp))
189
+ return ClientResp.new(error: self.class.error_from_response(resp))
190
190
  end
191
191
 
192
192
  if resp.headers['Content-Type'] != content_type
193
- return ClientResp.new(nil, Twirp::Error.internal("Expected response Content-Type #{content_type.inspect} but found #{resp.headers['Content-Type'].inspect}"))
193
+ return ClientResp.new(error: Twirp::Error.internal("Expected response Content-Type #{content_type.inspect} but found #{resp.headers['Content-Type'].inspect}"))
194
194
  end
195
195
 
196
196
  data = Encoding.decode(resp.body, rpcdef[:output_class], content_type)
197
- return ClientResp.new(data, nil)
197
+ return ClientResp.new(data: data, body: resp.body)
198
198
  end
199
199
 
200
200
  end
@@ -46,11 +46,11 @@ module Twirp
46
46
 
47
47
  def rpc_response_to_clientresp(resp)
48
48
  if resp.status != 200
49
- return ClientResp.new(nil, self.class.error_from_response(resp))
49
+ return ClientResp.new(error: self.class.error_from_response(resp))
50
50
  end
51
51
 
52
52
  data = Encoding.decode_json(resp.body)
53
- return ClientResp.new(data, nil)
53
+ return ClientResp.new(data: data, body: resp.body)
54
54
  end
55
55
 
56
56
  end
@@ -14,11 +14,13 @@
14
14
  module Twirp
15
15
  class ClientResp
16
16
  attr_accessor :data
17
+ attr_accessor :body
17
18
  attr_accessor :error
18
19
 
19
- def initialize(data, error)
20
+ def initialize(data: nil, body: nil, error: nil)
20
21
  @data = data
21
22
  @error = error
23
+ @body = body
22
24
  end
23
25
  end
24
26
  end
data/lib/twirp/service.rb CHANGED
@@ -14,6 +14,7 @@
14
14
  require_relative 'encoding'
15
15
  require_relative 'error'
16
16
  require_relative 'service_dsl'
17
+ require 'rack/request'
17
18
 
18
19
  module Twirp
19
20
 
@@ -122,7 +123,7 @@ module Twirp
122
123
  end
123
124
  env[:content_type] = content_type
124
125
 
125
- path_parts = rack_request.fullpath.split("/")
126
+ path_parts = rack_request.path.split("/")
126
127
  if path_parts.size < 3 || path_parts[-2] != self.full_name
127
128
  return route_err(:bad_route, "Invalid route. Expected format: POST {BaseURL}/#{self.full_name}/{Method}", rack_request)
128
129
  end
@@ -137,7 +138,7 @@ module Twirp
137
138
  input = nil
138
139
  begin
139
140
  body_str = rack_request.body.read
140
- rack_request.body.rewind # allow other middleware to read again (https://github.com/twitchtv/twirp-ruby/issues/50)
141
+ rack_request.body.rewind # allow other middleware to read again (https://github.com/github/twirp-ruby/issues/50)
141
142
  input = Encoding.decode(body_str, env[:input_class], content_type)
142
143
  rescue => e
143
144
  error_msg = "Invalid request body for rpc method #{method_name.inspect} with Content-Type=#{content_type}"
@@ -153,7 +154,7 @@ module Twirp
153
154
  end
154
155
 
155
156
  def route_err(code, msg, req)
156
- Twirp::Error.new code, msg, twirp_invalid_route: "#{req.request_method} #{req.fullpath}"
157
+ Twirp::Error.new code, msg, twirp_invalid_route: "#{req.request_method} #{req.path}"
157
158
  end
158
159
 
159
160
 
data/lib/twirp/version.rb CHANGED
@@ -12,5 +12,5 @@
12
12
  # permissions and limitations under the License.
13
13
 
14
14
  module Twirp
15
- VERSION = "1.9.0"
15
+ VERSION = "1.10.0"
16
16
  end
data/test/service_test.rb CHANGED
@@ -188,6 +188,15 @@ class ServiceTest < Minitest::Test
188
188
  }, JSON.parse(body[0]))
189
189
  end
190
190
 
191
+ def test_route_with_query_string
192
+ rack_env = json_req "/example.Haberdasher/MakeHat?extra=1", inches: 10
193
+ status, headers, body = haberdasher_service.call(rack_env)
194
+
195
+ assert_equal 200, status
196
+ assert_equal 'application/json', headers['Content-Type']
197
+ assert_equal({"inches" => 10, "color" => "white"}, JSON.parse(body[0]))
198
+ end
199
+
191
200
  def test_json_request_ignores_unknown_fields
192
201
  rack_env = json_req "/example.Haberdasher/MakeHat", inches: 10, fake: 3
193
202
  status, headers, body = haberdasher_service.call(rack_env)
data/twirp.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.email = ["forbescyrus@gmail.com", "tothemario@gmail.com"]
12
12
  spec.summary = %q{Twirp services in Ruby.}
13
13
  spec.description = %q{Twirp is a simple RPC framework with protobuf service definitions. The Twirp gem provides native support for Ruby.}
14
- spec.homepage = "https://github.com/twitchtv/twirp-ruby"
14
+ spec.homepage = "https://github.com/github/twirp-ruby"
15
15
  spec.license = "MIT"
16
16
 
17
17
  spec.files = Dir['lib/**/*'] + %w(Gemfile LICENSE README.md twirp.gemspec)
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.required_ruby_version = '>= 1.9'
22
22
  spec.add_runtime_dependency 'google-protobuf', '~> 3.0', '>= 3.7.0'
23
- spec.add_runtime_dependency 'faraday', '< 2' # for clients
23
+ spec.add_runtime_dependency 'faraday', '< 3' # for clients
24
24
 
25
25
  spec.add_development_dependency 'bundler', '~> 2'
26
26
  spec.add_development_dependency 'minitest', '>= 5'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twirp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.0
4
+ version: 1.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cyrus A. Forbes
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-10-19 00:00:00.000000000 Z
12
+ date: 2023-01-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: google-protobuf
@@ -37,14 +37,14 @@ dependencies:
37
37
  requirements:
38
38
  - - "<"
39
39
  - !ruby/object:Gem::Version
40
- version: '2'
40
+ version: '3'
41
41
  type: :runtime
42
42
  prerelease: false
43
43
  version_requirements: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "<"
46
46
  - !ruby/object:Gem::Version
47
- version: '2'
47
+ version: '3'
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: bundler
50
50
  requirement: !ruby/object:Gem::Requirement
@@ -129,7 +129,7 @@ files:
129
129
  - test/license_header_test.rb
130
130
  - test/service_test.rb
131
131
  - twirp.gemspec
132
- homepage: https://github.com/twitchtv/twirp-ruby
132
+ homepage: https://github.com/github/twirp-ruby
133
133
  licenses:
134
134
  - MIT
135
135
  metadata: {}
@@ -148,14 +148,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
148
  - !ruby/object:Gem::Version
149
149
  version: '0'
150
150
  requirements: []
151
- rubygems_version: 3.0.3
151
+ rubygems_version: 3.3.3
152
152
  signing_key:
153
153
  specification_version: 4
154
154
  summary: Twirp services in Ruby.
155
155
  test_files:
156
+ - test/client_json_test.rb
156
157
  - test/client_test.rb
157
158
  - test/error_test.rb
158
- - test/license_header_test.rb
159
159
  - test/fake_services.rb
160
+ - test/license_header_test.rb
160
161
  - test/service_test.rb
161
- - test/client_json_test.rb