Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ GEM
crack (1.0.0)
bigdecimal
rexml
csv (3.3.0)
csv (3.3.2)
diff-lcs (1.6.0)
hashdiff (1.1.2)
httparty (0.22.0)
Expand Down
1 change: 0 additions & 1 deletion committer.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@ Gem::Specification.new do |spec|
spec.executables = %w[committer]
spec.require_paths = ['lib']

spec.add_dependency 'httparty', '~> 0.20'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the httparty dependency here but still using it in the code will cause runtime errors. Make sure to update all usage of httparty or keep the dependency.

spec.metadata['rubygems_mfa_required'] = 'true'
end
30 changes: 17 additions & 13 deletions lib/clients/claude_client.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# frozen_string_literal: true

require 'json'
require 'httparty'
require 'net/http'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switching from HTTParty to standard library Net::HTTP is good for reducing dependencies, but ensure you're handling all error cases properly with the new implementation.

require 'uri'
require_relative '../committer/config/accessor'

module Clients
Expand All @@ -11,6 +12,8 @@ class OverloadError < StandardError; end
class UnknownError < StandardError; end
class ConfigError < StandardError; end

API_ENDPOINT = 'https://api.anthropic.com/v1/messages'

def initialize
@config = Committer::Config::Accessor.instance

Expand Down Expand Up @@ -38,19 +41,20 @@ def post(message)
private

def send_request(body)
options = build_request_options(body)
HTTParty.post('https://api.anthropic.com/v1/messages', options)
end
uri = URI.parse(API_ENDPOINT)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true

def build_request_options(body)
{
headers: {
'anthropic-version': '2023-06-01',
'content-type': 'application/json',
'x-api-key': @config['api_key']
},
body: body.to_json
}
request = Net::HTTP::Post.new(uri.request_uri)
request['anthropic-version'] = '2023-06-01'
request['content-type'] = 'application/json'
request['x-api-key'] = @config['api_key']
request.body = body.to_json

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return value has changed. The previous HTTParty.post returned a Response object with various methods, but now you're returning a parsed JSON hash. Ensure all callers of this method can handle the new return type.

response = http.request(request)
JSON.parse(response.body)
rescue JSON::ParserError
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding more specific error handling for different HTTP status codes (like 401, 403, 429, 500) to provide better error messages.

{ 'type' => 'error', 'error' => { 'type' => 'unknown_error' } }
end

def handle_error_response(response)
Expand Down
Loading