-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
103 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
source 'https://rubygems.org' | ||
|
||
gem 'thrift', '~> 0.19.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
thrift (0.19.0) | ||
|
||
PLATFORMS | ||
arm64-darwin-22 | ||
|
||
DEPENDENCIES | ||
thrift (~> 0.19.0) | ||
|
||
BUNDLED WITH | ||
2.4.22 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# main_client.rb | ||
|
||
$LOAD_PATH.unshift(File.expand_path('./gen_rb/')) | ||
|
||
require 'json' | ||
require_relative './gen_rb/resource_service' | ||
require_relative 'resource_invoke' | ||
|
||
def main | ||
if ARGV.length < 4 | ||
puts "Usage: ruby main_client.rb hostname port method uri" | ||
return | ||
end | ||
|
||
hostname = ARGV[0] | ||
port = ARGV[1].to_i | ||
method = ARGV[2] | ||
uri = ARGV[3] | ||
|
||
resource_invoke = ResourceInvoke.new(hostname, port) | ||
response = resource_invoke.call(method, uri) | ||
|
||
if response.is_a?(String) && response.start_with?("Error:") | ||
puts response | ||
return | ||
end | ||
|
||
puts "Response Code: #{response.code}" | ||
puts "Response Headers: #{response.headers}" | ||
puts "Raw Response JsonValue: #{response.json_value}" | ||
|
||
begin | ||
value = JSON.parse(response.json_value) | ||
puts "Response Value: #{value}" | ||
rescue JSON::ParserError => e | ||
puts "Error Unmarshaling JSON: #{e.message}" | ||
end | ||
|
||
puts "Response View: #{response.view}" | ||
end | ||
|
||
main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require 'thrift' | ||
require './gen_rb/resource_service' | ||
require './gen_rb/resource_service_types' | ||
|
||
class ResourceInvoke | ||
def initialize(host, port) | ||
@socket = Thrift::Socket.new(host, port) | ||
@transport = Thrift::BufferedTransport.new(@socket) | ||
@protocol = Thrift::BinaryProtocol.new(@transport) | ||
@client = ResourceService::ResourceService::Client.new(@protocol) | ||
end | ||
|
||
def call(method, uri) | ||
@socket.open unless @socket.open? | ||
request = ResourceService::ResourceRequest.new(method: method, uri: uri) | ||
|
||
begin | ||
response = @client.invokeRequest(request) | ||
rescue => e | ||
puts "Error: #{e.message}" | ||
puts "Backtrace: #{e.backtrace.join("\n")}" | ||
end | ||
rescue Thrift::Exception => e | ||
"Error: #{e.message}" | ||
ensure | ||
@socket.closethr if @socket.open? | ||
response | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters