grpc-rest 0.1.4 → 0.1.5

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: b9c3044d8f6813a33030d336a91e4d86b4305a781d178d85a07e5e287ab22264
4
- data.tar.gz: 659013b9ab51cd05f4e1b9570eeb71fb48f07992bd0f1eba80eb37aca1093921
3
+ metadata.gz: 3ed7db60b29738e635e7b776539fc8207a5ec264e43912cb83562b1a44efdc58
4
+ data.tar.gz: a1653a18dab17be5abad7968ae405254ccc23973f799f9c7def7cd318b485681
5
5
  SHA512:
6
- metadata.gz: 04ed1b2acf85c8ec4c069195dd1cd8711e7b68209dcf24cf62a60e832c89158364946d4da72012cc2b7bc037b6f2ac06df36a33a5a43b956e12e7dfe1b9d393b
7
- data.tar.gz: 64f846bc132c121521c4ba1c8c1189bfed3ebfc4c1ee78473fac297aba84b1254037922a08859f165569a366c23df2b6da0ea391e08ef1e50c4430db713b9f86
6
+ metadata.gz: 04b70b84065aa66b4441a4987519a351e0cafca0b58d5392a4e3a5a3b64429ca6bc4d6be877dfcf28f3c34fd77b04f7592500d89989737eab513b7c40591580f
7
+ data.tar.gz: fd35771ff21bbd7dc98550633a0eb96cb44b518f3356f792ce92dc02e9655f2683d0eab08bc1d36a1f8abf36f23fbabdd68e8bdb7f0dd4423ad311a27e7f80e6
data/CHANGELOG CHANGED
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## UNRELEASED
9
9
 
10
+ # 0.1.5 - 2024-04-04
11
+ - Parse Google Well Known Types (WKT) in request.
12
+
10
13
  # 0.1.4 - 2024-04-04
11
14
  - Remove geo-admin hardcoded requirement.
12
15
  - Use baked-in Protobuf initialization to support nested objects properly.
@@ -1,3 +1,3 @@
1
1
  module GrpcRest
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
data/lib/grpc_rest.rb CHANGED
@@ -33,6 +33,29 @@ module GrpcRest
33
33
  proto.public_send(:"#{tokens.last}=", value) if proto.respond_to?(:"#{tokens.last}=")
34
34
  end
35
35
 
36
+ def map_wkt(proto, params)
37
+ proto.to_a.each do |descriptor|
38
+ field = descriptor.name
39
+ case descriptor.subtype&.name
40
+ when 'google.protobuf.Struct'
41
+ params[field] = Google::Protobuf::Struct.from_hash(params[field])
42
+ when 'google.protobuf.Timestamp'
43
+ params[field] = Google::Protobuf::Timestamp.from_time(Time.new(params[field]))
44
+ when 'google.protobuf.Value'
45
+ params[field] = Google::Protobuf::Value.from_ruby(params[field])
46
+ when 'google.protobuf.ListValue'
47
+ params[field] = Google::Protobuf::ListValue.from_a(params[field])
48
+ else
49
+ map_wkt(descriptor.subtype, params[field]) if descriptor.subtype
50
+ end
51
+ end
52
+ end
53
+
54
+ def init_request(request_class, params)
55
+ map_wkt(request_class.descriptor, params)
56
+ request_class.new(params)
57
+ end
58
+
36
59
  def assign_params(request, param_hash, body_string, params)
37
60
  parameters = params.to_h.deep_dup
38
61
  # each instance of {variable} means that we set the corresponding param variable into the
@@ -59,7 +59,7 @@ class {{.ControllerName}}Controller < ActionController::Base
59
59
  {{range .Methods }}
60
60
  def {{.Name}}
61
61
  fields = {{.RequestType}}.descriptor.to_a.map(&:name)
62
- grpc_request = {{.RequestType}}.new(request.parameters.to_h.slice(*fields))
62
+ grpc_request = GrpcRest.init_request({{.RequestType}}, request.parameters.to_h.slice(*fields))
63
63
  GrpcRest.assign_params(grpc_request, METHOD_PARAM_MAP["{{.Name}}"], "{{.Body}}", request.parameters)
64
64
  render json: GrpcRest.send_request("{{$fullServiceName}}", "{{.Name}}", grpc_request)
65
65
  end
@@ -23,21 +23,21 @@ class MyServiceController < ActionController::Base
23
23
 
24
24
  def test
25
25
  fields = Testdata::TestRequest.descriptor.to_a.map(&:name)
26
- grpc_request = Testdata::TestRequest.new(request.parameters.to_h.slice(*fields))
26
+ grpc_request = GrpcRest.init_request(Testdata::TestRequest, request.parameters.to_h.slice(*fields))
27
27
  GrpcRest.assign_params(grpc_request, METHOD_PARAM_MAP["test"], "*", request.parameters)
28
28
  render json: GrpcRest.send_request("Testdata::MyService", "test", grpc_request)
29
29
  end
30
30
 
31
31
  def test_2
32
32
  fields = Testdata::TestRequest.descriptor.to_a.map(&:name)
33
- grpc_request = Testdata::TestRequest.new(request.parameters.to_h.slice(*fields))
33
+ grpc_request = GrpcRest.init_request(Testdata::TestRequest, request.parameters.to_h.slice(*fields))
34
34
  GrpcRest.assign_params(grpc_request, METHOD_PARAM_MAP["test_2"], "second_record", request.parameters)
35
35
  render json: GrpcRest.send_request("Testdata::MyService", "test_2", grpc_request)
36
36
  end
37
37
 
38
38
  def test_3
39
39
  fields = Testdata::TestRequest.descriptor.to_a.map(&:name)
40
- grpc_request = Testdata::TestRequest.new(request.parameters.to_h.slice(*fields))
40
+ grpc_request = GrpcRest.init_request(Testdata::TestRequest, request.parameters.to_h.slice(*fields))
41
41
  GrpcRest.assign_params(grpc_request, METHOD_PARAM_MAP["test_3"], "", request.parameters)
42
42
  render json: GrpcRest.send_request("Testdata::MyService", "test_3", grpc_request)
43
43
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grpc-rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Orner