generatorlabs 2.0.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,220 @@
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
+ module GeneratorLabs
13
+ # Certificate monitoring API namespace
14
+ class Cert
15
+ def initialize(handler)
16
+ @handler = handler
17
+ end
18
+
19
+ # Access certificate error operations
20
+ # @return [CertErrors]
21
+ def errors
22
+ @errors ||= CertErrors.new(@handler)
23
+ end
24
+
25
+ # Access certificate monitor management operations
26
+ # @return [CertMonitors]
27
+ def monitors
28
+ @monitors ||= CertMonitors.new(@handler)
29
+ end
30
+
31
+ # Access certificate profile management operations
32
+ # @return [CertProfiles]
33
+ def profiles
34
+ @profiles ||= CertProfiles.new(@handler)
35
+ end
36
+ end
37
+
38
+ # Certificate error retrieval
39
+ class CertErrors
40
+ def initialize(handler)
41
+ @handler = handler
42
+ end
43
+
44
+ # Get certificate errors
45
+ # @param params [nil, Hash] Optional parameters
46
+ # @return [Hash] Error data
47
+ def get(params = {})
48
+ @handler.get('cert/errors', params)
49
+ end
50
+
51
+ # Get all errors with automatic pagination
52
+ # @param params [Hash] Optional parameters (e.g., page_size)
53
+ # @return [Array] All errors across all pages
54
+ def get_all(params = {})
55
+ all_items = []
56
+ page = 1
57
+ params = params.dup
58
+
59
+ loop do
60
+ params[:page] = page
61
+ response = get(params)
62
+ errors = response['errors'] || []
63
+
64
+ all_items.concat(errors)
65
+
66
+ break unless page < (response['total_pages'] || 1) && !errors.empty?
67
+
68
+ page += 1
69
+ end
70
+
71
+ all_items
72
+ end
73
+ end
74
+
75
+ # Certificate monitor management
76
+ class CertMonitors
77
+ def initialize(handler)
78
+ @handler = handler
79
+ end
80
+
81
+ # Get monitors (all, by ID, or by array of IDs)
82
+ # @param ids [nil, String, Integer, Hash, Array] Optional ID(s) or parameters
83
+ # @return [Hash] Monitor data
84
+ def get(*ids)
85
+ return @handler.get('cert/monitors') if ids.empty?
86
+
87
+ # Check if first argument is a hash (parameters)
88
+ return @handler.get('cert/monitors', ids.first) if ids.first.is_a?(Hash)
89
+
90
+ return @handler.get("cert/monitors/#{ids.first}") if ids.length == 1
91
+
92
+ @handler.get('cert/monitors', { ids: ids.join(',') })
93
+ end
94
+
95
+ # Get all monitors with automatic pagination
96
+ # @param params [Hash] Optional parameters (e.g., page_size)
97
+ # @return [Array] All monitors across all pages
98
+ def get_all(params = {})
99
+ all_items = []
100
+ page = 1
101
+ params = params.dup
102
+
103
+ loop do
104
+ params[:page] = page
105
+ response = get(params)
106
+ monitors = response['monitors'] || []
107
+
108
+ all_items.concat(monitors)
109
+
110
+ break unless page < (response['total_pages'] || 1) && !monitors.empty?
111
+
112
+ page += 1
113
+ end
114
+
115
+ all_items
116
+ end
117
+
118
+ # Create a new certificate monitor
119
+ # @param params [Hash] Monitor parameters
120
+ # @return [Hash] Created monitor data
121
+ def create(params)
122
+ @handler.post('cert/monitors', params)
123
+ end
124
+
125
+ # Update a certificate monitor
126
+ # @param id [String, Integer] Monitor ID
127
+ # @param params [Hash] Updated parameters
128
+ # @return [Hash] Updated monitor data
129
+ def update(id, params)
130
+ @handler.put("cert/monitors/#{id}", params)
131
+ end
132
+
133
+ # Delete a certificate monitor
134
+ # @param id [String, Integer] Monitor ID
135
+ # @return [Hash] Deletion confirmation
136
+ def delete(id)
137
+ @handler.delete("cert/monitors/#{id}")
138
+ end
139
+
140
+ # Pause monitoring for a certificate
141
+ # @param id [String, Integer] Monitor ID
142
+ # @return [Hash] Response
143
+ def pause(id)
144
+ @handler.post("cert/monitors/#{id}/pause")
145
+ end
146
+
147
+ # Resume monitoring for a certificate
148
+ # @param id [String, Integer] Monitor ID
149
+ # @return [Hash] Response
150
+ def resume(id)
151
+ @handler.post("cert/monitors/#{id}/resume")
152
+ end
153
+ end
154
+
155
+ # Certificate profile management
156
+ class CertProfiles
157
+ def initialize(handler)
158
+ @handler = handler
159
+ end
160
+
161
+ # Get profiles (all, by ID, or by array of IDs)
162
+ # @param ids [nil, String, Integer, Hash, Array] Optional ID(s) or parameters
163
+ # @return [Hash] Profile data
164
+ def get(*ids)
165
+ return @handler.get('cert/profiles') if ids.empty?
166
+
167
+ # Check if first argument is a hash (parameters)
168
+ return @handler.get('cert/profiles', ids.first) if ids.first.is_a?(Hash)
169
+
170
+ return @handler.get("cert/profiles/#{ids.first}") if ids.length == 1
171
+
172
+ @handler.get('cert/profiles', { ids: ids.join(',') })
173
+ end
174
+
175
+ # Get all profiles with automatic pagination
176
+ # @param params [Hash] Optional parameters (e.g., page_size)
177
+ # @return [Array] All profiles across all pages
178
+ def get_all(params = {})
179
+ all_items = []
180
+ page = 1
181
+ params = params.dup
182
+
183
+ loop do
184
+ params[:page] = page
185
+ response = get(params)
186
+ profiles = response['profiles'] || []
187
+
188
+ all_items.concat(profiles)
189
+
190
+ break unless page < (response['total_pages'] || 1) && !profiles.empty?
191
+
192
+ page += 1
193
+ end
194
+
195
+ all_items
196
+ end
197
+
198
+ # Create a new certificate monitoring profile
199
+ # @param params [Hash] Profile parameters
200
+ # @return [Hash] Created profile data
201
+ def create(params)
202
+ @handler.post('cert/profiles', params)
203
+ end
204
+
205
+ # Update a certificate monitoring profile
206
+ # @param id [String, Integer] Profile ID
207
+ # @param params [Hash] Updated parameters
208
+ # @return [Hash] Updated profile data
209
+ def update(id, params)
210
+ @handler.put("cert/profiles/#{id}", params)
211
+ end
212
+
213
+ # Delete a certificate monitoring profile
214
+ # @param id [String, Integer] Profile ID
215
+ # @return [Hash] Deletion confirmation
216
+ def delete(id)
217
+ @handler.delete("cert/profiles/#{id}")
218
+ end
219
+ end
220
+ end
@@ -0,0 +1,128 @@
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
+ module GeneratorLabs
13
+ # Main API client for Generator Labs.
14
+ #
15
+ # The Generator Labs API is a RESTful web service API that lets customers manage
16
+ # their RBL monitoring hosts, certificate monitoring, contacts, and retrieve
17
+ # listing information.
18
+ #
19
+ # @example Basic usage
20
+ # client = GeneratorLabs::Client.new('your_account_sid', 'your_auth_token')
21
+ #
22
+ # # RBL monitoring
23
+ # hosts = client.rbl.hosts.get
24
+ #
25
+ # # Certificate monitoring
26
+ # monitors = client.cert.monitors.get
27
+ #
28
+ # # Contact management
29
+ # contacts = client.contact.contacts.get
30
+ #
31
+ # @example With custom configuration
32
+ # config = GeneratorLabs::Config.new(
33
+ # timeout: 45,
34
+ # max_retries: 5,
35
+ # retry_backoff: 2.0
36
+ # )
37
+ # client = GeneratorLabs::Client.new('your_account_sid', 'your_auth_token', config)
38
+ class Client
39
+ # @return [String] The account SID (2 uppercase + 32 hex characters)
40
+ attr_reader :account_sid
41
+
42
+ # @return [String] The authentication token (64 hex characters)
43
+ attr_reader :auth_token
44
+
45
+ # @return [Config] The configuration object
46
+ attr_reader :config
47
+
48
+ # Initialize a new Generator Labs client.
49
+ #
50
+ # The account SID must be in the format of 2 uppercase letters followed by
51
+ # 32 hexadecimal characters (e.g., "AC" + 32 hex chars).
52
+ #
53
+ # The auth token must be 64 hexadecimal characters.
54
+ #
55
+ # @param account_sid [String] Your Generator Labs account SID
56
+ # @param auth_token [String] Your Generator Labs auth token
57
+ # @param config [Config, nil] Optional configuration object for custom timeouts and retry behavior
58
+ # @raise [Error] if account_sid or auth_token format is invalid
59
+ #
60
+ # @example
61
+ # client = GeneratorLabs::Client.new('ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'your_auth_token')
62
+ #
63
+ # @example With custom config
64
+ # config = GeneratorLabs::Config.new(timeout: 60)
65
+ # client = GeneratorLabs::Client.new('ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'your_auth_token', config)
66
+ def initialize(account_sid, auth_token, config = nil)
67
+ # Validate account SID format
68
+ raise Error, "Invalid account SID format: #{account_sid}" unless account_sid.match?(/^[A-Z]{2}[0-9a-fA-F]{32}$/)
69
+
70
+ # Validate auth token format
71
+ raise Error, 'Invalid auth token format' unless auth_token.match?(/^[0-9a-fA-F]{64}$/)
72
+
73
+ @account_sid = account_sid
74
+ @auth_token = auth_token
75
+ @config = config || Config.default
76
+ @handler = RequestHandler.new(account_sid, auth_token, @config)
77
+ end
78
+
79
+ # Get the RBL monitoring API namespace.
80
+ #
81
+ # The RBL namespace provides access to:
82
+ # - Hosts: Manage monitored hosts (IP addresses and domains)
83
+ # - Profiles: Manage monitoring profiles (which RBLs to check)
84
+ # - Sources: Manage RBL sources
85
+ # - Check: Perform ad-hoc RBL checks
86
+ # - Listings: Retrieve current RBL listings
87
+ #
88
+ # @return [RBL] RBL namespace with endpoints for hosts, profiles, sources, etc.
89
+ #
90
+ # @example
91
+ # hosts = client.rbl.hosts.get
92
+ # listings = client.rbl.listings
93
+ def rbl
94
+ @rbl ||= RBL.new(@handler)
95
+ end
96
+
97
+ # Get the Contact management API namespace.
98
+ #
99
+ # The Contact namespace provides access to:
100
+ # - Contacts: Manage individual contacts
101
+ # - Groups: Manage contact groups
102
+ #
103
+ # @return [Contact] Contact namespace with endpoints for contacts and groups
104
+ #
105
+ # @example
106
+ # contacts = client.contact.contacts.get
107
+ # groups = client.contact.groups.get
108
+ def contact
109
+ @contact ||= Contact.new(@handler)
110
+ end
111
+
112
+ # Get the Certificate monitoring API namespace.
113
+ #
114
+ # The Cert namespace provides access to:
115
+ # - Monitors: Manage certificate monitors
116
+ # - Profiles: Manage certificate monitoring profiles
117
+ # - Errors: Retrieve current certificate errors
118
+ #
119
+ # @return [Cert] Cert namespace with endpoints for errors, monitors, and profiles
120
+ #
121
+ # @example
122
+ # monitors = client.cert.monitors.get
123
+ # errors = client.cert.errors.get
124
+ def cert
125
+ @cert ||= Cert.new(@handler)
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,85 @@
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
+ module GeneratorLabs
13
+ # Configuration options for the Generator Labs API client.
14
+ #
15
+ # All fields are optional. If not provided, default values are used.
16
+ # Create a custom config to override timeouts, retry behavior, or API endpoint.
17
+ #
18
+ # @example Basic usage with defaults
19
+ # config = GeneratorLabs::Config.new
20
+ #
21
+ # @example Custom timeouts and retries
22
+ # config = GeneratorLabs::Config.new(
23
+ # timeout: 45,
24
+ # max_retries: 5,
25
+ # retry_backoff: 2.0
26
+ # )
27
+ # client = GeneratorLabs::Client.new(account_sid, auth_token, config)
28
+ class Config
29
+ # @return [Integer] Request timeout in seconds (default: 30)
30
+ attr_accessor :timeout
31
+
32
+ # @return [Integer] Connection timeout in seconds (default: 5)
33
+ attr_accessor :connect_timeout
34
+
35
+ # @return [Integer] Maximum number of retry attempts (default: 3).
36
+ # The SDK automatically retries on connection errors, 5xx server errors,
37
+ # and 429 rate limit errors.
38
+ attr_accessor :max_retries
39
+
40
+ # @return [Float] Exponential backoff multiplier for retries (default: 1.0).
41
+ # Each retry waits retry_backoff^attemptNum seconds.
42
+ # Set to 2.0 for exponential backoff (1s, 2s, 4s, 8s, etc.)
43
+ attr_accessor :retry_backoff
44
+
45
+ # @return [String] Custom API base URL (default: "https://api.generatorlabs.com/4.0/").
46
+ # Override this for testing or if using a proxy.
47
+ attr_accessor :base_url
48
+
49
+ # Initialize a new configuration.
50
+ #
51
+ # @param options [Hash] Configuration options
52
+ # @option options [Integer] :timeout Request timeout in seconds
53
+ # @option options [Integer] :connect_timeout Connection timeout in seconds
54
+ # @option options [Integer] :max_retries Maximum retry attempts
55
+ # @option options [Float] :retry_backoff Exponential backoff multiplier
56
+ # @option options [String] :base_url Custom API base URL
57
+ #
58
+ # @example
59
+ # config = GeneratorLabs::Config.new(timeout: 60, max_retries: 5)
60
+ def initialize(options = {})
61
+ @timeout = options.fetch(:timeout, 30)
62
+ @connect_timeout = options.fetch(:connect_timeout, 5)
63
+ @max_retries = options.fetch(:max_retries, 3)
64
+ @retry_backoff = options.fetch(:retry_backoff, 1.0)
65
+ @base_url = options.fetch(:base_url, 'https://api.generatorlabs.com/4.0/')
66
+ end
67
+
68
+ # Create a default configuration with standard values.
69
+ #
70
+ # Returns a Config with:
71
+ # - timeout: 30 seconds
72
+ # - connect_timeout: 5 seconds
73
+ # - max_retries: 3
74
+ # - retry_backoff: 1.0
75
+ # - base_url: "https://api.generatorlabs.com/4.0/"
76
+ #
77
+ # @return [Config] Default configuration instance
78
+ #
79
+ # @example
80
+ # config = GeneratorLabs::Config.default
81
+ def self.default
82
+ new
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,192 @@
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
+ module GeneratorLabs
13
+ # Contact management API namespace
14
+ class Contact
15
+ def initialize(handler)
16
+ @handler = handler
17
+ end
18
+
19
+ # Access contact management operations
20
+ # @return [Contacts]
21
+ def contacts
22
+ @contacts ||= Contacts.new(@handler)
23
+ end
24
+
25
+ # Access group management operations
26
+ # @return [Groups]
27
+ def groups
28
+ @groups ||= Groups.new(@handler)
29
+ end
30
+ end
31
+
32
+ # Contact management
33
+ class Contacts
34
+ def initialize(handler)
35
+ @handler = handler
36
+ end
37
+
38
+ # Get contacts (all, by ID, or by array of IDs)
39
+ # @param ids [nil, String, Integer, Hash, Array] Optional ID(s) or parameters
40
+ # @return [Hash] Contact data
41
+ def get(*ids)
42
+ return @handler.get('contact/contacts') if ids.empty?
43
+
44
+ # Check if first argument is a hash (parameters)
45
+ return @handler.get('contact/contacts', ids.first) if ids.first.is_a?(Hash)
46
+
47
+ return @handler.get("contact/contacts/#{ids.first}") if ids.length == 1
48
+
49
+ @handler.get('contact/contacts', { ids: ids.join(',') })
50
+ end
51
+
52
+ # Get all contacts with automatic pagination
53
+ # @param params [Hash] Optional parameters (e.g., page_size)
54
+ # @return [Array] All contacts across all pages
55
+ def get_all(params = {})
56
+ all_items = []
57
+ page = 1
58
+ params = params.dup
59
+
60
+ loop do
61
+ params[:page] = page
62
+ response = get(params)
63
+ contacts = response['contacts'] || []
64
+
65
+ all_items.concat(contacts)
66
+
67
+ break unless page < (response['total_pages'] || 1) && !contacts.empty?
68
+
69
+ page += 1
70
+ end
71
+
72
+ all_items
73
+ end
74
+
75
+ # Create a new contact
76
+ # @param params [Hash] Contact parameters
77
+ # @return [Hash] Created contact data
78
+ def create(params)
79
+ @handler.post('contact/contacts', params)
80
+ end
81
+
82
+ # Update a contact
83
+ # @param id [String, Integer] Contact ID
84
+ # @param params [Hash] Updated parameters
85
+ # @return [Hash] Updated contact data
86
+ def update(id, params)
87
+ @handler.put("contact/contacts/#{id}", params)
88
+ end
89
+
90
+ # Delete a contact
91
+ # @param id [String, Integer] Contact ID
92
+ # @return [Hash] Deletion confirmation
93
+ def delete(id)
94
+ @handler.delete("contact/contacts/#{id}")
95
+ end
96
+
97
+ # Pause a contact
98
+ # @param id [String, Integer] Contact ID
99
+ # @return [Hash] Response
100
+ def pause(id)
101
+ @handler.post("contact/contacts/#{id}/pause")
102
+ end
103
+
104
+ # Resume a contact
105
+ # @param id [String, Integer] Contact ID
106
+ # @return [Hash] Response
107
+ def resume(id)
108
+ @handler.post("contact/contacts/#{id}/resume")
109
+ end
110
+
111
+ # Confirm a contact with an auth code
112
+ # @param id [String, Integer] Contact ID
113
+ # @param params [Hash] Confirmation parameters (authcode)
114
+ # @return [Hash] Response
115
+ def confirm(id, params)
116
+ @handler.post("contact/contacts/#{id}/confirm", params)
117
+ end
118
+
119
+ # Resend confirmation to a contact
120
+ # @param id [String, Integer] Contact ID
121
+ # @return [Hash] Response
122
+ def resend(id)
123
+ @handler.post("contact/contacts/#{id}/resend")
124
+ end
125
+ end
126
+
127
+ # Group management
128
+ class Groups
129
+ def initialize(handler)
130
+ @handler = handler
131
+ end
132
+
133
+ # Get groups (all, by ID, or by array of IDs)
134
+ # @param ids [nil, String, Integer, Hash, Array] Optional ID(s) or parameters
135
+ # @return [Hash] Group data
136
+ def get(*ids)
137
+ return @handler.get('contact/groups') if ids.empty?
138
+
139
+ # Check if first argument is a hash (parameters)
140
+ return @handler.get('contact/groups', ids.first) if ids.first.is_a?(Hash)
141
+
142
+ return @handler.get("contact/groups/#{ids.first}") if ids.length == 1
143
+
144
+ @handler.get('contact/groups', { ids: ids.join(',') })
145
+ end
146
+
147
+ # Get all groups with automatic pagination
148
+ # @param params [Hash] Optional parameters (e.g., page_size)
149
+ # @return [Array] All groups across all pages
150
+ def get_all(params = {})
151
+ all_items = []
152
+ page = 1
153
+ params = params.dup
154
+
155
+ loop do
156
+ params[:page] = page
157
+ response = get(params)
158
+ groups = response['groups'] || []
159
+
160
+ all_items.concat(groups)
161
+
162
+ break unless page < (response['total_pages'] || 1) && !groups.empty?
163
+
164
+ page += 1
165
+ end
166
+
167
+ all_items
168
+ end
169
+
170
+ # Create a new contact group
171
+ # @param params [Hash] Group parameters
172
+ # @return [Hash] Created group data
173
+ def create(params)
174
+ @handler.post('contact/groups', params)
175
+ end
176
+
177
+ # Update a contact group
178
+ # @param id [String, Integer] Group ID
179
+ # @param params [Hash] Updated parameters
180
+ # @return [Hash] Updated group data
181
+ def update(id, params)
182
+ @handler.put("contact/groups/#{id}", params)
183
+ end
184
+
185
+ # Delete a contact group
186
+ # @param id [String, Integer] Group ID
187
+ # @return [Hash] Deletion confirmation
188
+ def delete(id)
189
+ @handler.delete("contact/groups/#{id}")
190
+ end
191
+ end
192
+ end
@@ -0,0 +1,30 @@
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
+ module GeneratorLabs
13
+ # Rate limit information from API response headers.
14
+ class RateLimitInfo
15
+ # @return [String] Active rate limit policies, e.g. "1000;w=3600, 100;w=1"
16
+ attr_reader :limit
17
+
18
+ # @return [Integer] Requests remaining in the most restrictive active window
19
+ attr_reader :remaining
20
+
21
+ # @return [Integer] Seconds until the most restrictive window resets
22
+ attr_reader :reset
23
+
24
+ def initialize(limit:, remaining:, reset:)
25
+ @limit = limit
26
+ @remaining = remaining
27
+ @reset = reset
28
+ end
29
+ end
30
+ end