generatorlabs 2.0.0 → 2.1.0

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.
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # This file is part of the Generator Labs Ruby SDK package.
5
+ #
6
+ # (c) Generator Labs <support@generatorlabs.com>
7
+ #
8
+ # For the full copyright and license information, please view the LICENSE
9
+ # file that was distributed with this source code.
10
+ #
11
+
12
+ # Generator Labs API client: the request options, and the limit on a Retry-After wait.
13
+ module GeneratorLabs
14
+ # The longest Retry-After (in seconds) that is waited out before a retry. A longer wait
15
+ # is not slept: the response is raised as the error instead.
16
+ MAX_RETRY_AFTER = 60
17
+
18
+ # Options any request accepts, passed as the last argument of a resource method.
19
+ #
20
+ # - idempotency_key: the Idempotency-Key of a request that creates something or starts a
21
+ # check; a repeat with the same key returns the first answer (generated when left out)
22
+ # - request_id: the X-Request-Id to send (the API generates one otherwise)
23
+ # - if_none_match: the ETag of an earlier response; the answer is not_modified when
24
+ # nothing changed
25
+ # - fields: the keys to keep in each object of the response data (GET requests), as a
26
+ # comma-separated String or an Array
27
+ #
28
+ # @example
29
+ # options = GeneratorLabs::RequestOptions.new(fields: %w[id host])
30
+ # client.rbl.hosts.get('HT1a2b3c4d5e6f7890abcdef1234567890', options)
31
+ RequestOptions = Struct.new(:idempotency_key, :request_id, :if_none_match, :fields, keyword_init: true)
32
+
33
+ # Sort the arguments of a resource's get into the arguments of RequestHandler#get: an ID
34
+ # or a Hash of query parameters, followed by RequestOptions.
35
+ #
36
+ # @param path [String] API endpoint path of the resource
37
+ # @param args [Array] Arguments the resource's get received
38
+ # @return [Array] The path, the parameters and the request options
39
+ def self.get_args(path, args)
40
+ options = args.grep(RequestOptions).first
41
+ args = args.grep_v(RequestOptions)
42
+ raise ArgumentError, 'only one ID can be requested at a time' if args.length > 1
43
+
44
+ id = args.first
45
+ params = id if id.is_a?(Hash)
46
+ path = "#{path}/#{id}" if id && params.nil?
47
+ request = [path, params, options]
48
+ request.pop while request.length > 1 && request.last.nil?
49
+ request
50
+ end
51
+ end
@@ -18,11 +18,32 @@ module GeneratorLabs
18
18
  # @return [RateLimitInfo, nil] Rate limit information from response headers
19
19
  attr_reader :rate_limit_info
20
20
 
21
+ # @return [String, nil] The X-Request-Id of the response; quote it when contacting support
22
+ attr_reader :request_id
23
+
24
+ # @return [String, nil] The ETag of a GET response, to send back as if_none_match
25
+ attr_reader :etag
26
+
27
+ # @return [Boolean] true when the API answered with the result of an earlier request
28
+ # that carried the same Idempotency-Key
29
+ attr_reader :replayed
30
+
31
+ # @return [Boolean] true for a 304 Not Modified answer to if_none_match (no data)
32
+ attr_reader :not_modified
33
+
21
34
  # @param data [Hash] Parsed JSON response body
22
35
  # @param rate_limit_info [RateLimitInfo, nil] Rate limit information
23
- def initialize(data, rate_limit_info = nil)
36
+ # @param request_id [String, nil] X-Request-Id of the response
37
+ # @param etag [String, nil] ETag of the response
38
+ # @param replayed [Boolean] Whether the answer is a replay of an earlier request
39
+ # @param not_modified [Boolean] Whether the answer is 304 Not Modified
40
+ def initialize(data, rate_limit_info = nil, request_id: nil, etag: nil, replayed: false, not_modified: false) # rubocop:disable Metrics/ParameterLists
24
41
  @data = data
25
42
  @rate_limit_info = rate_limit_info
43
+ @request_id = request_id
44
+ @etag = etag
45
+ @replayed = replayed
46
+ @not_modified = not_modified
26
47
  end
27
48
 
28
49
  # Access response data by key (Hash-like access).
@@ -11,5 +11,5 @@
11
11
 
12
12
  module GeneratorLabs
13
13
  # Current version of the SDK
14
- VERSION = '2.0.0'
14
+ VERSION = '2.1.0'
15
15
  end
data/lib/generatorlabs.rb CHANGED
@@ -13,14 +13,28 @@ require_relative 'generatorlabs/version'
13
13
  require_relative 'generatorlabs/config'
14
14
  require_relative 'generatorlabs/rate_limit_info'
15
15
  require_relative 'generatorlabs/response'
16
+ require_relative 'generatorlabs/request_options'
16
17
  require_relative 'generatorlabs/client'
17
18
  require_relative 'generatorlabs/request_handler'
18
19
  require_relative 'generatorlabs/webhook'
20
+ require_relative 'generatorlabs/account'
19
21
  require_relative 'generatorlabs/rbl'
20
22
  require_relative 'generatorlabs/contact'
21
23
  require_relative 'generatorlabs/cert'
22
24
 
23
25
  # Generator Labs API SDK
24
26
  module GeneratorLabs
25
- class Error < StandardError; end
27
+ # Error raised for all Generator Labs API failures, carrying the API status_code.
28
+ class Error < StandardError
29
+ attr_reader :status_code
30
+
31
+ # @return [String, nil] The X-Request-Id of the failed request; quote it when contacting support
32
+ attr_reader :request_id
33
+
34
+ def initialize(message = nil, status_code: nil, request_id: nil)
35
+ super(message)
36
+ @status_code = status_code
37
+ @request_id = request_id
38
+ end
39
+ end
26
40
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: generatorlabs
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Generator Labs, Inc.
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2026-04-13 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: faraday
@@ -49,6 +48,7 @@ files:
49
48
  - LICENSE
50
49
  - README.md
51
50
  - lib/generatorlabs.rb
51
+ - lib/generatorlabs/account.rb
52
52
  - lib/generatorlabs/cert.rb
53
53
  - lib/generatorlabs/client.rb
54
54
  - lib/generatorlabs/config.rb
@@ -56,6 +56,7 @@ files:
56
56
  - lib/generatorlabs/rate_limit_info.rb
57
57
  - lib/generatorlabs/rbl.rb
58
58
  - lib/generatorlabs/request_handler.rb
59
+ - lib/generatorlabs/request_options.rb
59
60
  - lib/generatorlabs/response.rb
60
61
  - lib/generatorlabs/version.rb
61
62
  - lib/generatorlabs/webhook.rb
@@ -68,7 +69,6 @@ metadata:
68
69
  bug_tracker_uri: https://github.com/generator-labs/ruby-sdk/issues
69
70
  documentation_uri: https://docs.generatorlabs.com/api/v4/
70
71
  rubygems_mfa_required: 'true'
71
- post_install_message:
72
72
  rdoc_options: []
73
73
  require_paths:
74
74
  - lib
@@ -83,8 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
83
  - !ruby/object:Gem::Version
84
84
  version: '0'
85
85
  requirements: []
86
- rubygems_version: 3.2.33
87
- signing_key:
86
+ rubygems_version: 3.6.9
88
87
  specification_version: 4
89
88
  summary: Official Ruby SDK for the Generator Labs API
90
89
  test_files: []