skinbaron_api_client 0.2.1 → 0.2.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bac140e69332695d80e8a5f324a8becc9fb88052e80fddd0774d849bba2d1ee5
4
- data.tar.gz: cb4c3b9386949e5cd4ca9b05136a02a7015ca722e48b5fec0d71c44da3c3de8b
3
+ metadata.gz: 0b973d5e86049bfa020fae424126e8957b00fa91c613c5d4e145628123bb7289
4
+ data.tar.gz: 0f16584da1097db5facf8544e78882c73c343391d09842c2d17e06c296ab79b7
5
5
  SHA512:
6
- metadata.gz: f79f5e0ffcfd24a8ffec58da35ffa995e12da53e2e57abfb01e5f51aef6b44d3fb61419a45ecb12bba292da22ee062b0806db911af84e45e2c4f2339b8b5403c
7
- data.tar.gz: 50b1432feb1bb58928a27fd68fb59e22351b3dcb2db8e492e4baf694876ab24abe7152c10b0844bc206a1e0f1d9546cb3577604f76d7c806ac5b007fe40ce738
6
+ metadata.gz: c79cb0d5c9f0860977f9f494168124cb7f347645bd1c79c85e7be8980d4a086f2013f05f16addba7f764839dbaf92f55637da36f4b57dfad433db1e0a645cd16
7
+ data.tar.gz: dc6fe1a9d00e216fcb622b2279bcba13a59b4886d3e71fc7cf96680c67e8a62e5c45a1b7b8f72481860bf765e5a6e2b2dbb50ef2679280533f18664b1eda0366
@@ -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)
@@ -27,10 +27,11 @@ module SkinbaronApiClient
27
27
  enforce_request_delay(delay_seconds: options[:request_delay] || DEFAULT_REQUEST_DELAY)
28
28
  body["after_saleid"] = last_saleid if last_saleid
29
29
 
30
- puts "REQUEST IS BEING MADE" if @config.debug
31
30
  response = @skinbaron_client.http_client.post(endpoint: "Search", body: body)
32
31
  @last_request_time = Time.now
33
32
 
33
+ raise TooManyRequestsError, "Too many requests" if response[:status] == 429
34
+
34
35
  response_body = JSON.parse(response[:body])
35
36
  current_page_listings = response_body["sales"]
36
37
 
@@ -0,0 +1,11 @@
1
+ module SkinbaronApiClient
2
+ class Error < StandardError; end
3
+
4
+ class AuthenticationError < Error; end
5
+
6
+ class RequestError < Error; end
7
+
8
+ class ResponseError < Error; end
9
+
10
+ class TooManyRequestsError < Error; end
11
+ end
@@ -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
- with_error_handling def post(endpoint:, body: {})
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|
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SkinbaronApiClient
4
- VERSION = "0.2.1"
4
+ VERSION = "0.2.3"
5
5
  end
@@ -7,7 +7,6 @@ require "json"
7
7
  require_relative "skinbaron_api_client/version"
8
8
  require_relative "skinbaron_api_client/client"
9
9
  require_relative "skinbaron_api_client/logger"
10
- require_relative "skinbaron_api_client/error_handling"
11
10
 
12
11
  # Example usage:
13
12
  #
@@ -17,11 +16,4 @@ require_relative "skinbaron_api_client/error_handling"
17
16
  # response = skinbaron.search(item: "AK-47 | Asiimov")
18
17
  #
19
18
  module SkinbaronApiClient
20
- class Error < StandardError; end
21
-
22
- class AuthenticationError < Error; end
23
-
24
- class RequestError < Error; end
25
-
26
- class ResponseError < Error; end
27
19
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skinbaron_api_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Schams
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-12-29 00:00:00.000000000 Z
11
+ date: 2025-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http
@@ -64,7 +64,7 @@ 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
67
+ - lib/skinbaron_api_client/exceptions/exceptions.rb
68
68
  - lib/skinbaron_api_client/http_client.rb
69
69
  - lib/skinbaron_api_client/logger.rb
70
70
  - 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