skinbaron_api_client 0.2.1 → 0.2.2
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/lib/skinbaron_api_client/client.rb +0 -3
- data/lib/skinbaron_api_client/http_client.rb +2 -4
- data/lib/skinbaron_api_client/logger.rb +0 -3
- data/lib/skinbaron_api_client/version.rb +1 -1
- data/lib/skinbaron_api_client.rb +0 -1
- metadata +1 -2
- data/lib/skinbaron_api_client/error_handling.rb +0 -64
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8196ed40a109dfdcc450596dfc8a558f034766ddd02bdf99d910262fcf9281e
|
4
|
+
data.tar.gz: 8b2e857ad1ca9969810f75346875ca0bef84587dec657bfc157fa10087c3a97a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b00aac24f670697d06a4c89189d1a73e6be9a1c8f0502695168e713a9b51fa386c7715b8f1c5220106e45785da7832d614898054ae53fbcab636d7ea36db3db3
|
7
|
+
data.tar.gz: b206725aa8fc3031cd2fa0552173eab730d7c5be96f1ffd5ead2f4aebf874b8c4fc9cda9c9b89eecb687d1ffa78b94446d83d3bbc3a40b0ccd559a438205988d
|
@@ -4,14 +4,11 @@
|
|
4
4
|
|
5
5
|
require_relative "configuration"
|
6
6
|
require_relative "http_client"
|
7
|
-
require_relative "error_handling"
|
8
7
|
require_relative "logger"
|
9
8
|
require_relative "endpoints/search"
|
10
9
|
|
11
10
|
module SkinbaronApiClient
|
12
11
|
class Client
|
13
|
-
include ErrorHandling
|
14
|
-
|
15
12
|
attr_reader :config, :http_client, :search_endpoint
|
16
13
|
|
17
14
|
def initialize(**options)
|
@@ -1,13 +1,10 @@
|
|
1
1
|
require "http"
|
2
2
|
require "json"
|
3
|
-
require_relative "error_handling"
|
4
3
|
require_relative "logger"
|
5
4
|
|
6
5
|
module SkinbaronApiClient
|
7
6
|
# HTTP client for making requests to the Skinbaron API
|
8
7
|
class HttpClient
|
9
|
-
include ErrorHandling
|
10
|
-
|
11
8
|
attr_reader :base_url, :headers, :debug
|
12
9
|
|
13
10
|
def initialize(base_url:, headers: {}, debug: false)
|
@@ -16,7 +13,7 @@ module SkinbaronApiClient
|
|
16
13
|
@debug = debug
|
17
14
|
end
|
18
15
|
|
19
|
-
|
16
|
+
def post(endpoint:, body: {})
|
20
17
|
url = "#{base_url}/#{endpoint}"
|
21
18
|
debug_log "Making POST request to: #{url}"
|
22
19
|
debug_log "Request body: #{body.to_json}"
|
@@ -30,6 +27,7 @@ module SkinbaronApiClient
|
|
30
27
|
})
|
31
28
|
|
32
29
|
http_response = HTTP.headers(headers).post(url, json: body)
|
30
|
+
raise AuthenticationError, "Authentication failed" if http_response.body.to_s.include? "wrong or unauthenticated"
|
33
31
|
|
34
32
|
Logger.instance.log({
|
35
33
|
type: "RESPONSE",
|
@@ -54,9 +54,6 @@ module SkinbaronApiClient
|
|
54
54
|
@request_logger.info(JSON.pretty_generate(log_data))
|
55
55
|
@request_logger.info("#{"=" * 80}\n")
|
56
56
|
end
|
57
|
-
rescue JSON::ParserError => e
|
58
|
-
@logger.error("LOGGER: failed to parse search response", error: e.message)
|
59
|
-
@logger.error("LOGGER: Response: #{JSON.pretty_generate(log_data)}")
|
60
57
|
end
|
61
58
|
|
62
59
|
LEVELS.each do |level|
|
data/lib/skinbaron_api_client.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: skinbaron_api_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Schams
|
@@ -64,7 +64,6 @@ files:
|
|
64
64
|
- lib/skinbaron_api_client/client.rb
|
65
65
|
- lib/skinbaron_api_client/configuration.rb
|
66
66
|
- lib/skinbaron_api_client/endpoints/search.rb
|
67
|
-
- lib/skinbaron_api_client/error_handling.rb
|
68
67
|
- lib/skinbaron_api_client/http_client.rb
|
69
68
|
- lib/skinbaron_api_client/logger.rb
|
70
69
|
- lib/skinbaron_api_client/version.rb
|
@@ -1,64 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module SkinbaronApiClient
|
4
|
-
# Mixin for adding error handling capabilities to API client classes.
|
5
|
-
# Provides methods for response validation and error logging.
|
6
|
-
module ErrorHandling
|
7
|
-
def self.included(base)
|
8
|
-
base.extend(ClassMethods)
|
9
|
-
end
|
10
|
-
|
11
|
-
# Class methods for decorating instance methods with error handling.
|
12
|
-
# Provides the with_error_handling decorator for wrapping methods.
|
13
|
-
module ClassMethods
|
14
|
-
def with_error_handling(method_name)
|
15
|
-
original_method = instance_method(method_name)
|
16
|
-
|
17
|
-
define_method(method_name) do |*args, **kwargs|
|
18
|
-
response = original_method.bind(self).call(*args, **kwargs)
|
19
|
-
|
20
|
-
check_response_success(response)
|
21
|
-
check_response_authentication(response)
|
22
|
-
|
23
|
-
response
|
24
|
-
rescue HTTP::Error => e
|
25
|
-
log_error(message: "HTTP request failed", error: e)
|
26
|
-
raise RequestError, "HTTP request failed: #{e.message}"
|
27
|
-
rescue JSON::ParserError => e
|
28
|
-
log_error(message: "JSON parsing failed", error: e)
|
29
|
-
raise ResponseError, "Invalid JSON response: #{e.message}"
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
private
|
35
|
-
|
36
|
-
def logger
|
37
|
-
SkinbaronApiClient::Logger.instance
|
38
|
-
end
|
39
|
-
|
40
|
-
def log_error(message:, error:)
|
41
|
-
logger.error(
|
42
|
-
message,
|
43
|
-
{
|
44
|
-
error_class: error.class.name,
|
45
|
-
error_message: error.message,
|
46
|
-
backtrace: error.backtrace&.first(5)
|
47
|
-
}
|
48
|
-
)
|
49
|
-
end
|
50
|
-
|
51
|
-
def check_response_success(response)
|
52
|
-
return if response[:status]&.success?
|
53
|
-
|
54
|
-
raise ResponseError, "Request failed with status #{response[:status]}. Response: #{response[:body]}"
|
55
|
-
end
|
56
|
-
|
57
|
-
def check_response_authentication(response)
|
58
|
-
return unless response[:body].to_s.include? "wrong or unauthenticated request"
|
59
|
-
|
60
|
-
logger.error("Authentication failed", { body: response[:body] })
|
61
|
-
raise AuthenticationError, "Authentication failed: #{response[:body]}"
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|