diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 77ef506..904deff 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,23 +1,11 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2025-01-17 07:38:10 UTC using RuboCop version 1.70.0. +# on 2025-01-17 07:46:46 UTC using RuboCop version 1.70.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -Lint/AmbiguousOperatorPrecedence: - Exclude: - - 'bin/colore-client' - -# Offense count: 1 -# This cop supports unsafe autocorrection (--autocorrect-all). -Lint/RedundantRequireStatement: - Exclude: - - 'bin/colore-client' - # Offense count: 1 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: AutoCorrect, AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods, NotImplementedExceptions. @@ -26,12 +14,11 @@ Lint/UnusedMethodArgument: Exclude: - 'lib/colore/client.rb' -# Offense count: 6 +# Offense count: 2 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: AutoCorrect. Lint/UselessAssignment: Exclude: - - 'bin/colore-client' - 'lib/colore/client.rb' # Offense count: 1 @@ -81,31 +68,18 @@ Style/Documentation: - 'lib/colore/client.rb' - 'lib/colore/errors.rb' -# Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -Style/FileWrite: - Exclude: - - 'bin/colore-client' - -# Offense count: 6 +# Offense count: 5 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: EnforcedStyle. # SupportedStyles: always, always_true, never Style/FrozenStringLiteralComment: Exclude: - 'Rakefile' - - 'bin/colore-client' - 'lib/colore-client.rb' - 'lib/colore/client.rb' - 'lib/colore/client/version.rb' - 'lib/colore/errors.rb' -# Offense count: 2 -# This cop supports unsafe autocorrection (--autocorrect-all). -Style/GlobalStdStream: - Exclude: - - 'bin/colore-client' - # Offense count: 1 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle, EnforcedShorthandSyntax, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols. @@ -130,23 +104,15 @@ Style/MethodDefParentheses: - 'lib/colore/client.rb' - 'lib/colore/errors.rb' -# Offense count: 3 +# Offense count: 2 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: EnforcedStyle. # SupportedStyles: literals, strict Style/MutableConstant: Exclude: - - 'bin/colore-client' - 'lib/colore/client.rb' - 'lib/colore/client/version.rb' -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: PreferredDelimiters. -Style/PercentLiteralDelimiters: - Exclude: - - 'bin/colore-client' - # Offense count: 1 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: AllowedCompactTypes. @@ -154,46 +120,18 @@ Style/PercentLiteralDelimiters: Style/RaiseArgs: EnforcedStyle: compact -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -Style/RedundantCondition: - Exclude: - - 'bin/colore-client' - # Offense count: 2 # This cop supports safe autocorrection (--autocorrect). Style/RedundantPercentQ: Exclude: - 'colore-client.gemspec' -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowAsExpressionSeparator. -Style/Semicolon: - Exclude: - - 'bin/colore-client' - -# Offense count: 1 -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: RequireEnglish. -# SupportedStyles: use_perl_names, use_english_names, use_builtin_english_names -Style/SpecialGlobalVars: - EnforcedStyle: use_perl_names - -# Offense count: 1 -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: Mode. -Style/StringConcatenation: - Exclude: - - 'bin/colore-client' - -# Offense count: 4 +# Offense count: 2 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline. # SupportedStyles: single_quotes, double_quotes Style/StringLiterals: Exclude: - - 'bin/colore-client' - 'lib/colore/client.rb' - 'lib/colore/errors.rb' diff --git a/bin/colore-client b/bin/colore-client index c40543e..70912e1 100755 --- a/bin/colore-client +++ b/bin/colore-client @@ -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' @@ -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]' @@ -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), @@ -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), @@ -89,7 +91,7 @@ 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' @@ -97,7 +99,7 @@ begin 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 @@ -105,9 +107,9 @@ begin 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}"