skinbaron_api_client 0.2.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3a5bc7a27a2b8ed17712e35dc276d278dac29708f10c00083a1efb67c486816c
4
- data.tar.gz: 3e0d1e16da1488cdcd09e437e456477c060fb25e2066a49b4a1c273ee8a883ff
3
+ metadata.gz: a8196ed40a109dfdcc450596dfc8a558f034766ddd02bdf99d910262fcf9281e
4
+ data.tar.gz: 8b2e857ad1ca9969810f75346875ca0bef84587dec657bfc157fa10087c3a97a
5
5
  SHA512:
6
- metadata.gz: a11aba6be419470ce1c00bb17e69f810251a5acde612e44fbb6b8fee988d57fb39d3caf9b58ac986915833e2e30981f0b01669142bbdb896d4f2048a4c7c4378
7
- data.tar.gz: f16a2ffa2d93823df50af4cacbe0c47fbbe6dae019c6d37fb823403fe94643f1db893ecb12f19393d43b32c69aa2c96c1b1870fb7c0aeee0a5567c76403dfaf0
6
+ metadata.gz: b00aac24f670697d06a4c89189d1a73e6be9a1c8f0502695168e713a9b51fa386c7715b8f1c5220106e45785da7832d614898054ae53fbcab636d7ea36db3db3
7
+ data.tar.gz: b206725aa8fc3031cd2fa0552173eab730d7c5be96f1ffd5ead2f4aebf874b8c4fc9cda9c9b89eecb687d1ffa78b94446d83d3bbc3a40b0ccd559a438205988d
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.2.1] - 2024-12-29
6
+
7
+ - Fixed typo in `minWear` and `maxWear`
8
+
5
9
  ## [0.2.0] - 2024-12-26
6
10
 
7
11
  - Added support for querying multiple items in one request
@@ -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)
@@ -75,8 +75,8 @@ module SkinbaronApiClient
75
75
  }).tap do |body|
76
76
  body["min"] = options[:min_price] if options.key?(:min_price)
77
77
  body["max"] = options[:max_price] if options.key?(:max_price)
78
- body["minwear"] = options[:min_wear] if options.key?(:min_wear)
79
- body["maxwear"] = options[:max_wear] if options.key?(:max_wear)
78
+ body["minWear"] = options[:min_wear] if options.key?(:min_wear)
79
+ body["maxWear"] = options[:max_wear] if options.key?(:max_wear)
80
80
  body["stattrak"] = options[:stattrak] if options.key?(:stattrak)
81
81
  body["souvenir"] = options[:souvenir] if options.key?(:souvenir)
82
82
  body["stackable"] = options[:stackable] if options.key?(:stackable)
@@ -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.0"
4
+ VERSION = "0.2.2"
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
  #
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.0
4
+ version: 0.2.2
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-26 00:00:00.000000000 Z
11
+ date: 2024-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http
@@ -64,12 +64,9 @@ 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
71
- - logs/errors.log
72
- - logs/requests.log
73
70
  - sig/skinbaron_api_client.rbs
74
71
  homepage: https://github.com/shazam442/skinbaron-api-client
75
72
  licenses:
@@ -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
data/logs/errors.log DELETED
@@ -1 +0,0 @@
1
- # Logfile created on 2024-12-26 17:10:31 +0100 by logger.rb/v1.6.4