route_guide 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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +29 -16
- data/examples/Gemfile.example +6 -0
- data/examples/README.md +9 -0
- data/examples/client.rb +3 -0
- data/examples/server.rb +15 -1
- data/lib/route_guide/route_guide_services_pb.rb +1 -1
- data/lib/route_guide/version.rb +1 -1
- metadata +3 -2
- data/examples/directions_service.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 306b79419a33139769d321a1a4221408f633eac26d9d2ebcbae7d53efdfde67a
|
4
|
+
data.tar.gz: 21d43d8d4317bcc007711a883ed8d8ba7f94b7a0583455dfa40db4b4e5573ec1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6fe81484e7005e9ffb9d6351a7e07a7474478d8ef06c2d3c66ef1ff1db72bf18d87116eea778377f1acb1b550d5f7a6235b2d3b42eed81b14b7d3bcb4ae8d3c4
|
7
|
+
data.tar.gz: 54914673ae41f39bc028359ef28723224b5f63b7a9520ef1d347671142378c63b56e87c9e51fd7fbe8d0d3ab96f3b8ef12cd25db6a205d63b5b413553389710b
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -15,36 +15,40 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
15
15
|
## Usage
|
16
16
|
|
17
17
|
You need to implement a server and a client. Then you can use this gem to connect between
|
18
|
-
the two.
|
18
|
+
the two. Check the `examples` folder for a working example.
|
19
19
|
|
20
20
|
### Server side service implementation
|
21
21
|
|
22
|
-
1. Create
|
22
|
+
1. Create a `Gemfile` below then run `bundle` install:
|
23
23
|
|
24
24
|
```ruby
|
25
|
+
# frozen_string_literal: true
|
26
|
+
|
27
|
+
source "https://rubygems.org"
|
28
|
+
|
29
|
+
gem "grpc"
|
30
|
+
gem "route_guide"
|
31
|
+
```
|
32
|
+
|
33
|
+
2. Setup the gRPC server in `server.rb`:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
#!/usr/bin/env ruby
|
37
|
+
|
25
38
|
require 'grpc'
|
26
39
|
require 'route_guide'
|
27
40
|
|
28
41
|
class DirectionsService < RouteGuide::DirectionsService::Service
|
29
42
|
def direct_it(direction_req, _unused_call)
|
30
43
|
puts "Received direction request for #{direction_req}"
|
44
|
+
# build response from object
|
31
45
|
RouteGuide::DirectionsResponse.new(
|
32
|
-
directions: response
|
33
|
-
approximate_time_of_travel_in_hrs:
|
34
|
-
approximate_distance_in_kms:
|
46
|
+
directions: 'response',
|
47
|
+
approximate_time_of_travel_in_hrs: 4,
|
48
|
+
approximate_distance_in_kms: 30
|
35
49
|
)
|
36
50
|
end
|
37
51
|
end
|
38
|
-
```
|
39
|
-
|
40
|
-
2. Setup the gRPC server in `server.rb`:
|
41
|
-
|
42
|
-
```ruby
|
43
|
-
#!/usr/bin/env ruby
|
44
|
-
|
45
|
-
require 'rubygems'
|
46
|
-
require 'route_guide'
|
47
|
-
require_relative 'directions_service'
|
48
52
|
|
49
53
|
class RouteGuideServer
|
50
54
|
class << self
|
@@ -55,8 +59,10 @@ class RouteGuideServer
|
|
55
59
|
private
|
56
60
|
|
57
61
|
def start_grpc_server
|
62
|
+
# create server
|
58
63
|
@server = GRPC::RpcServer.new
|
59
64
|
@server.add_http2_port("0.0.0.0:50052", :this_port_is_insecure)
|
65
|
+
# assign server to a grpc handler
|
60
66
|
@server.handle(DirectionsService)
|
61
67
|
@server.run_till_terminated
|
62
68
|
end
|
@@ -83,12 +89,15 @@ require 'grpc'
|
|
83
89
|
require 'route_guide'
|
84
90
|
|
85
91
|
def test_single_call
|
92
|
+
# 1. connect to server service
|
86
93
|
stub = RouteGuide::DirectionsService::Stub.new('0.0.0.0:50052', :this_channel_is_insecure)
|
94
|
+
# 2. build request object
|
87
95
|
req = RouteGuide::DirectionsRequest.new(
|
88
96
|
current_location: 'current_location',
|
89
97
|
target_location: 'travel_location',
|
90
98
|
means_of_travel: 'means_of_travel'
|
91
99
|
)
|
100
|
+
# 3. call the remote method with request object as parameter
|
92
101
|
resp_obj = stub.direct_it(req)
|
93
102
|
puts "Response: #{resp_obj}"
|
94
103
|
end
|
@@ -96,7 +105,11 @@ end
|
|
96
105
|
test_single_call
|
97
106
|
```
|
98
107
|
|
99
|
-
Then run the client in a separate terminal.
|
108
|
+
2. Then run the client in a separate terminal. Run client with;
|
109
|
+
|
110
|
+
```sh
|
111
|
+
bundle exec client.rb
|
112
|
+
```
|
100
113
|
|
101
114
|
## Development
|
102
115
|
|
data/examples/README.md
ADDED
data/examples/client.rb
CHANGED
@@ -4,12 +4,15 @@ require 'grpc'
|
|
4
4
|
require 'route_guide'
|
5
5
|
|
6
6
|
def test_single_call
|
7
|
+
# 1. connect to server service
|
7
8
|
stub = RouteGuide::DirectionsService::Stub.new('0.0.0.0:50052', :this_channel_is_insecure)
|
9
|
+
# 2. build request object
|
8
10
|
req = RouteGuide::DirectionsRequest.new(
|
9
11
|
current_location: 'current_location',
|
10
12
|
target_location: 'travel_location',
|
11
13
|
means_of_travel: 'means_of_travel'
|
12
14
|
)
|
15
|
+
# 3. call remote method with request object as parameter
|
13
16
|
resp_obj = stub.direct_it(req)
|
14
17
|
puts "Response: #{resp_obj}"
|
15
18
|
end
|
data/examples/server.rb
CHANGED
@@ -1,8 +1,20 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
+
require 'grpc'
|
3
4
|
require 'rubygems'
|
4
5
|
require 'route_guide'
|
5
|
-
|
6
|
+
|
7
|
+
class DirectionsService < RouteGuide::DirectionsService::Service
|
8
|
+
def direct_it(direction_req, _unused_call)
|
9
|
+
puts "Received direction request for #{direction_req}"
|
10
|
+
# build response from object
|
11
|
+
RouteGuide::DirectionsResponse.new(
|
12
|
+
directions: 'response',
|
13
|
+
approximate_time_of_travel_in_hrs: 4,
|
14
|
+
approximate_distance_in_kms: 30
|
15
|
+
)
|
16
|
+
end
|
17
|
+
end
|
6
18
|
|
7
19
|
class RouteGuideServer
|
8
20
|
class << self
|
@@ -13,8 +25,10 @@ class RouteGuideServer
|
|
13
25
|
private
|
14
26
|
|
15
27
|
def start_grpc_server
|
28
|
+
# create server
|
16
29
|
@server = GRPC::RpcServer.new
|
17
30
|
@server.add_http2_port("0.0.0.0:50052", :this_port_is_insecure)
|
31
|
+
# assign server to a grpc handler
|
18
32
|
@server.handle(DirectionsService)
|
19
33
|
@server.run_till_terminated
|
20
34
|
end
|
data/lib/route_guide/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: route_guide
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sylvance_theone
|
@@ -30,8 +30,9 @@ files:
|
|
30
30
|
- Makefile
|
31
31
|
- README.md
|
32
32
|
- Rakefile
|
33
|
+
- examples/Gemfile.example
|
34
|
+
- examples/README.md
|
33
35
|
- examples/client.rb
|
34
|
-
- examples/directions_service.rb
|
35
36
|
- examples/server.rb
|
36
37
|
- lib/route_guide.rb
|
37
38
|
- lib/route_guide/route_guide_pb.rb
|
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'grpc'
|
2
|
-
require 'route_guide'
|
3
|
-
|
4
|
-
class DirectionsService < RouteGuide::DirectionsService::Service
|
5
|
-
def direct_it(direction_req, _unused_call)
|
6
|
-
puts "Received direction request for #{direction_req}"
|
7
|
-
RouteGuide::DirectionsResponse.new(
|
8
|
-
directions: response.direction,
|
9
|
-
approximate_time_of_travel_in_hrs: response.approximate_time_of_travel_in_hrs,
|
10
|
-
approximate_distance_in_kms: response.approximate_distance_in_kms
|
11
|
-
)
|
12
|
-
end
|
13
|
-
end
|