Skip to content

Commit

Permalink
Fix offenses in binary (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
tagliala authored Jan 17, 2025
1 parent e53d235 commit 0410d49
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 82 deletions.
72 changes: 5 additions & 67 deletions .rubocop_todo.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 17 additions & 15 deletions bin/colore-client
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'optparse'
require 'pathname'
require 'pp'

BASE = Pathname.new(__FILE__).realpath.parent.parent
$: << BASE + 'lib'
BIN_BASE = Pathname.new(__dir__)
$LOAD_PATH << BIN_BASE.join('../lib')

require 'colore-client'

Expand All @@ -23,13 +23,13 @@ output_file = nil
callback_url = nil
verbose = nil

REQUESTS = %w(
REQUESTS = %w[
ping
create_document update_document update_title
request_conversion delete_document
delete_version get_document get_document_info
convert
)
].freeze

OptionParser.new do |opts|
opts.banner = 'Usage: colore_client -r {request} [opts]'
Expand All @@ -46,21 +46,23 @@ OptionParser.new do |opts|
opts.on('-c', '--callback-url URL', 'Callback URL for conversion callbacks') { |c| callback_url = c }
opts.on('-B', '--backtrace', 'Request backtrace on errors') { backtrace = true }
opts.on('-V', '--verbose', 'Log interactions') { verbose = true }
opts.on('-h', '--help', 'This message') { puts opts; exit 0 }
opts.on('-h', '--help', 'This message') do
puts opts
exit 0
end
opts.separator "Valid requests: #{REQUESTS.join ', '}"
end.parse!

logger = Logger.new(verbose ? STDOUT : nil)
logger = Logger.new(verbose ? $stdout : nil)

client = Colore::Client.new base_uri: base_uri, app: app, backtrace: backtrace, logger: logger

begin
resp = nil
case request
when 'ping'
resp = client.ping
client.ping
when 'create_document'
resp = client.create_document(
client.create_document(
doc_id: doc_id,
title: title,
filename: (File.basename(file) if file),
Expand All @@ -69,7 +71,7 @@ begin
callback_url: callback_url
)
when 'update_document'
resp = client.update_document(
client.update_document(
doc_id: doc_id,
filename: (File.basename(file) if file),
content: (File.read(file) if file),
Expand All @@ -89,25 +91,25 @@ begin
when 'get_document'
resp = client.delete_document doc_id: doc_id, version: version, filename: filename
if output_file
File.open(output_file, "wb") { |f| f.write(resp) }
File.binwrite(output_file, resp)
resp = nil
end
when 'get_document_info'
resp = client.get_document_info doc_id: doc_id
when 'convert'
resp = client.convert content: File.read(file), action: actions[0], language: language
if output_file
File.open(output_file, "wb") { |f| f.write(resp) }
File.binwrite(output_file, resp)
resp = nil
end
else
raise "Unhandled request type: #{request}"
end

if resp.respond_to? :to_hash
resp.respond_to? :to_hash
resp.to_hash
else
STDOUT.write resp
write(resp)
end
rescue Colore::Errors::APIError => e
puts "Received error from colore: #{e.http_code}, #{e.message}"
Expand Down

0 comments on commit 0410d49

Please sign in to comment.