apiverve_csrparser 1.2.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6555b8e22241d6862302d1d4edb96abad1102ae22a947696f84eeb67ac8979ba
4
+ data.tar.gz: cfee9967193ca3ca43a44c6366f7b6c04c82b121fdfb22509eb66be76e42cef8
5
+ SHA512:
6
+ metadata.gz: 1db358c26a360e8faf05c48db890618c734c040dae95587744268553c93d715b11dee45c897d60e03da99c73e2d64e468d00c211e7f96a64fe06e9471fe0cb30
7
+ data.tar.gz: 77ec1a3f43d1beee7362ab2393b6eb57d3d3452b00251108b371eb75531fc8c9707a8cf961106141f4743ceb5bdeb5a6ea7f6e6b0df0c9f912729126e6452e32
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) {{year}} APIVerve
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,154 @@
1
+ # CSR Parser API - Ruby Gem
2
+
3
+ CSR Parser extracts and analyzes information from Certificate Signing Requests (CSRs), providing detailed subject information, public key details, and fingerprints.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'apiverve_csrparser'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```bash
16
+ $ bundle install
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```bash
22
+ $ gem install apiverve_csrparser
23
+ ```
24
+
25
+ ## Getting Started
26
+
27
+ Get your API key at [APIVerve](https://apiverve.com)
28
+
29
+ ### Basic Usage
30
+
31
+ ```ruby
32
+ require 'apiverve_csrparser'
33
+
34
+ # Initialize the client
35
+ client = APIVerve::Csrparser::Client.new(api_key: "YOUR_API_KEY")
36
+
37
+ # Make a request
38
+ response = client.execute({ csr: "-----BEGIN CERTIFICATE REQUEST-----
39
+ MIICvDCCAaQCAQAwdzELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNhbGlmb3JuaWEx
40
+ FjAUBgNVBAcMDVNhbiBGcmFuY2lzY28xEzARBgNVBAoMCkV4YW1wbGUgQ28xEDAO
41
+ BgNVBAsMB0RldlRlYW0xFDASBgNVBAMMC2V4YW1wbGUuY29tMIIBIjANBgkqhkiG
42
+ 9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuqKT3qPzGqKqV3LqR2r3XqKqKqKqKqKqKqKq
43
+ KqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKq
44
+ KqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKq
45
+ KqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKq
46
+ KqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKq
47
+ KqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKq
48
+ KwIDAQABoAAwDQYJKoZIhvcNAQELBQADggEBAH4jI5yKqKqKqKqKqKqKqKqKqKqK
49
+ qKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqK
50
+ qKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqK
51
+ qKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqK
52
+ qKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqK
53
+ qKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqK
54
+ -----END CERTIFICATE REQUEST-----" })
55
+
56
+ # Print the response
57
+ puts response
58
+ ```
59
+
60
+
61
+ ### Error Handling
62
+
63
+ ```ruby
64
+ begin
65
+ response = client.execute({ csr: "-----BEGIN CERTIFICATE REQUEST-----
66
+ MIICvDCCAaQCAQAwdzELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNhbGlmb3JuaWEx
67
+ FjAUBgNVBAcMDVNhbiBGcmFuY2lzY28xEzARBgNVBAoMCkV4YW1wbGUgQ28xEDAO
68
+ BgNVBAsMB0RldlRlYW0xFDASBgNVBAMMC2V4YW1wbGUuY29tMIIBIjANBgkqhkiG
69
+ 9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuqKT3qPzGqKqV3LqR2r3XqKqKqKqKqKqKqKq
70
+ KqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKq
71
+ KqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKq
72
+ KqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKq
73
+ KqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKq
74
+ KqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKq
75
+ KwIDAQABoAAwDQYJKoZIhvcNAQELBQADggEBAH4jI5yKqKqKqKqKqKqKqKqKqKqK
76
+ qKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqK
77
+ qKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqK
78
+ qKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqK
79
+ qKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqK
80
+ qKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqK
81
+ -----END CERTIFICATE REQUEST-----" })
82
+ puts response["data"]
83
+ rescue APIVerve::Csrparser::ValidationError => e
84
+ puts "Validation error: #{e.errors.join(', ')}"
85
+ rescue APIVerve::Csrparser::APIError => e
86
+ puts "API error: #{e.message}"
87
+ puts "Status code: #{e.status_code}"
88
+ end
89
+ ```
90
+
91
+ ### Debug Mode
92
+
93
+ ```ruby
94
+ # Enable debug logging
95
+ client = APIVerve::Csrparser::Client.new(
96
+ api_key: "YOUR_API_KEY",
97
+ debug: true
98
+ )
99
+ ```
100
+
101
+ ## Example Response
102
+
103
+ ```json
104
+ {
105
+ "status": "ok",
106
+ "error": null,
107
+ "data": {
108
+ "version": "v1",
109
+ "subject": {
110
+ "common_name": "example.com",
111
+ "organization": "Example Company Inc",
112
+ "organizational_unit": "IT Department",
113
+ "locality": "San Francisco",
114
+ "state": "California",
115
+ "country": "US",
116
+ "email": "admin@example.com"
117
+ },
118
+ "public_key": {
119
+ "algorithm": "RSA",
120
+ "size_bits": 2048,
121
+ "exponent": 65537
122
+ },
123
+ "signature_algorithm": "SHA256withRSA",
124
+ "extensions": [],
125
+ "fingerprints": {
126
+ "sha1": "82:D3:E3:9A:FB:85:22:65:16:84:43:2F:BB:05:35:2A:95:37:BF:58",
127
+ "sha256": "D8:73:E8:A3:DE:22:57:D6:AD:A0:AD:AB:53:75:FB:09:07:79:4D:21:CF:F1:0A:C0:55:EF:4B:67:A0:20:FE:9D",
128
+ "md5": "4A:AC:A6:9D:40:6C:2F:34:51:D3:A7:7E:06:23:66:0A"
129
+ },
130
+ "pem": "-----BEGIN CERTIFICATE REQUEST-----\nMIICvDCCAaQCAQAwdzELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNhbGlmb3JuaWEx\nFjAUBgNVBAcMDVNhbiBGcmFuY2lzY28xEzARBgNVBAoMCkV4YW1wbGUgQ28xEDAO\nBgNVBAsMB0RldlRlYW0xFDASBgNVBAMMC2V4YW1wbGUuY29tMIIBIjANBgkqhkiG\n9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuqKT3qPzGqKqV3LqR2r3XqKqKqKqKqKqKqKq\nKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKq\nKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKq\nKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKq\nKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKq\nKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKq\nKwIDAQABoAAwDQYJKoZIhvcNAQELBQADggEBAH4jI5yKqKqKqKqKqKqKqKqKqKqK\nqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqK\nqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqK\nqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqK\nqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqK\nqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqK\n-----END CERTIFICATE REQUEST-----",
131
+ "size_bytes": 705,
132
+ "format": "PEM",
133
+ "is_valid": true,
134
+ "security_assessment": {
135
+ "is_weak_key": false,
136
+ "is_deprecated_signature": false,
137
+ "key_strength": "acceptable"
138
+ }
139
+ }
140
+ }
141
+ ```
142
+
143
+ ## Documentation
144
+
145
+ For more information, visit the [API Documentation](https://docs.apiverve.com/ref/csrparser?utm_source=rubygems&utm_medium=readme).
146
+
147
+ ## Support
148
+
149
+ - Website: [https://apiverve.com/marketplace/csrparser?utm_source=ruby&utm_medium=readme](https://apiverve.com/marketplace/csrparser?utm_source=ruby&utm_medium=readme)
150
+ - Email: hello@apiverve.com
151
+
152
+ ## License
153
+
154
+ This gem is available under the [MIT License](LICENSE).
@@ -0,0 +1,200 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+ require "faraday/multipart"
5
+ require "json"
6
+
7
+ module APIVerve
8
+ module Csrparser
9
+ # Client for the CSR Parser API
10
+ #
11
+ # @example Basic usage
12
+ # client = APIVerve::Csrparser::Client.new(api_key: "your_api_key")
13
+ # response = client.execute({ csr: "-----BEGIN CERTIFICATE REQUEST-----
14
+ MIICvDCCAaQCAQAwdzELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNhbGlmb3JuaWEx
15
+ FjAUBgNVBAcMDVNhbiBGcmFuY2lzY28xEzARBgNVBAoMCkV4YW1wbGUgQ28xEDAO
16
+ BgNVBAsMB0RldlRlYW0xFDASBgNVBAMMC2V4YW1wbGUuY29tMIIBIjANBgkqhkiG
17
+ 9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuqKT3qPzGqKqV3LqR2r3XqKqKqKqKqKqKqKq
18
+ KqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKq
19
+ KqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKq
20
+ KqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKq
21
+ KqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKq
22
+ KqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKq
23
+ KwIDAQABoAAwDQYJKoZIhvcNAQELBQADggEBAH4jI5yKqKqKqKqKqKqKqKqKqKqK
24
+ qKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqK
25
+ qKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqK
26
+ qKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqK
27
+ qKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqK
28
+ qKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqK
29
+ -----END CERTIFICATE REQUEST-----" })
30
+ # puts response
31
+ #
32
+ # @see https://apiverve.com/marketplace/csrparser?utm_source=ruby&utm_medium=readme
33
+ class Client
34
+ BASE_URL = "https://api.apiverve.com/v1/csrparser"
35
+ DEFAULT_TIMEOUT = 30
36
+
37
+ # Validation rules for parameters
38
+ VALIDATION_RULES = { 'csr' => { type: 'string', required: true } }
39
+
40
+ # Format validation patterns
41
+ FORMAT_PATTERNS = {
42
+ 'email' => /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
43
+ 'url' => /^https?:\/\/.+/,
44
+ 'ip' => /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$|^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$/,
45
+ 'date' => /^\d{4}-\d{2}-\d{2}$/,
46
+ 'hexColor' => /^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/
47
+ }.freeze
48
+
49
+ # Initialize the client
50
+ #
51
+ # @param api_key [String] Your APIVerve API key
52
+ # @param timeout [Integer] Request timeout in seconds (default: 30)
53
+ # @param debug [Boolean] Enable debug logging (default: false)
54
+ # @raise [ArgumentError] If API key is invalid
55
+ def initialize(api_key:, timeout: DEFAULT_TIMEOUT, debug: false)
56
+ validate_api_key!(api_key)
57
+
58
+ @api_key = api_key
59
+ @timeout = timeout
60
+ @debug = debug
61
+
62
+ @connection = Faraday.new(url: BASE_URL) do |conn|
63
+ conn.request :multipart
64
+ conn.request :url_encoded
65
+ conn.adapter Faraday.default_adapter
66
+ conn.options.timeout = @timeout
67
+ conn.headers["x-api-key"] = @api_key
68
+ conn.headers["auth-mode"] = "rubygems-package"
69
+ conn.headers["Content-Type"] = "application/json"
70
+ end
71
+ end
72
+
73
+ # Execute the API request
74
+ #
75
+ # @param params [Hash] Query parameters or request body
76
+ # @return [Hash] API response
77
+ # @raise [APIError] If the request fails
78
+ # @raise [ValidationError] If parameter validation fails
79
+ def execute(params = {})
80
+ validate_params!(params)
81
+
82
+ log("Making POST request to #{BASE_URL}")
83
+ log("Parameters: #{params.inspect}") if params.any?
84
+
85
+ response = @connection.post do |req|
86
+ req.body = params.to_json
87
+ end
88
+
89
+ handle_response(response)
90
+ end
91
+
92
+ private
93
+
94
+ def validate_api_key!(api_key)
95
+ raise ArgumentError, "API key is required. Get your API key at: https://apiverve.com" if api_key.nil? || api_key.strip.empty?
96
+
97
+ unless api_key.match?(/^[a-zA-Z0-9_-]+$/)
98
+ raise ArgumentError, "Invalid API key format. API key should only contain letters, numbers, hyphens, and underscores."
99
+ end
100
+ end
101
+
102
+ def validate_params!(params)
103
+ return if VALIDATION_RULES.empty?
104
+
105
+ errors = []
106
+
107
+ VALIDATION_RULES.each do |param_name, rules|
108
+ value = params[param_name.to_sym] || params[param_name]
109
+
110
+ # Check required
111
+ if rules[:required] && (value.nil? || value.to_s.empty?)
112
+ errors << "Required parameter [#{param_name}] is missing."
113
+ next
114
+ end
115
+
116
+ next if value.nil?
117
+
118
+ case rules[:type]
119
+ when "integer", "number"
120
+ begin
121
+ num_value = rules[:type] == "number" ? Float(value) : Integer(value)
122
+ errors << "Parameter [#{param_name}] must be at least #{rules[:min]}." if rules[:min] && num_value < rules[:min]
123
+ errors << "Parameter [#{param_name}] must be at most #{rules[:max]}." if rules[:max] && num_value > rules[:max]
124
+ rescue ArgumentError, TypeError
125
+ errors << "Parameter [#{param_name}] must be a valid #{rules[:type]}."
126
+ end
127
+ when "string"
128
+ unless value.is_a?(String)
129
+ errors << "Parameter [#{param_name}] must be a string."
130
+ next
131
+ end
132
+ errors << "Parameter [#{param_name}] must be at least #{rules[:min_length]} characters." if rules[:min_length] && value.length < rules[:min_length]
133
+ errors << "Parameter [#{param_name}] must be at most #{rules[:max_length]} characters." if rules[:max_length] && value.length > rules[:max_length]
134
+
135
+ if rules[:format] && FORMAT_PATTERNS[rules[:format]]
136
+ unless value.match?(FORMAT_PATTERNS[rules[:format]])
137
+ errors << "Parameter [#{param_name}] must be a valid #{rules[:format]}."
138
+ end
139
+ end
140
+ when "boolean"
141
+ unless [true, false, "true", "false"].include?(value)
142
+ errors << "Parameter [#{param_name}] must be a boolean."
143
+ end
144
+ end
145
+
146
+ # Enum validation
147
+ if rules[:enum] && !rules[:enum].include?(value)
148
+ errors << "Parameter [#{param_name}] must be one of: #{rules[:enum].join(', ')}."
149
+ end
150
+ end
151
+
152
+ raise ValidationError, errors unless errors.empty?
153
+ end
154
+
155
+ def handle_response(response)
156
+ log("Response status: #{response.status}")
157
+
158
+ data = JSON.parse(response.body)
159
+
160
+ if data["status"] == "error"
161
+ raise APIError.new(data["error"] || "Unknown API error", response.status, data)
162
+ end
163
+
164
+ unless response.success?
165
+ raise APIError.new(data["error"] || "HTTP #{response.status} error", response.status, data)
166
+ end
167
+
168
+ log("Request successful")
169
+ data
170
+ rescue JSON::ParserError => e
171
+ raise APIError.new("Invalid JSON response: #{e.message}", response.status)
172
+ end
173
+
174
+ def log(message)
175
+ puts "[APIVerve::Csrparser] #{message}" if @debug
176
+ end
177
+ end
178
+
179
+ # Custom error class for API errors
180
+ class APIError < StandardError
181
+ attr_reader :status_code, :response
182
+
183
+ def initialize(message, status_code = nil, response = nil)
184
+ @status_code = status_code
185
+ @response = response
186
+ super(message)
187
+ end
188
+ end
189
+
190
+ # Custom error class for validation errors
191
+ class ValidationError < StandardError
192
+ attr_reader :errors
193
+
194
+ def initialize(errors)
195
+ @errors = errors
196
+ super("Validation failed: #{errors.join(' ')}")
197
+ end
198
+ end
199
+ end
200
+ end
@@ -0,0 +1,202 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+ require "faraday/multipart"
5
+ require "json"
6
+
7
+ module APIVerve
8
+ module Csrparser
9
+ # Client for the CSR Parser API
10
+ #
11
+ # @example Basic usage
12
+ # client = APIVerve::Csrparser::Client.new(api_key: "your_api_key")
13
+ # response = client.execute({ csr: "-----BEGIN CERTIFICATE REQUEST-----
14
+ MIICvDCCAaQCAQAwdzELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNhbGlmb3JuaWEx
15
+ FjAUBgNVBAcMDVNhbiBGcmFuY2lzY28xEzARBgNVBAoMCkV4YW1wbGUgQ28xEDAO
16
+ BgNVBAsMB0RldlRlYW0xFDASBgNVBAMMC2V4YW1wbGUuY29tMIIBIjANBgkqhkiG
17
+ 9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuqKT3qPzGqKqV3LqR2r3XqKqKqKqKqKqKqKq
18
+ KqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKq
19
+ KqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKq
20
+ KqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKq
21
+ KqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKq
22
+ KqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKq
23
+ KwIDAQABoAAwDQYJKoZIhvcNAQELBQADggEBAH4jI5yKqKqKqKqKqKqKqKqKqKqK
24
+ qKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqK
25
+ qKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqK
26
+ qKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqK
27
+ qKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqK
28
+ qKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqKqK
29
+ -----END CERTIFICATE REQUEST-----" })
30
+ # puts response
31
+ #
32
+ # @see https://apiverve.com/marketplace/csrparser?utm_source=ruby&utm_medium=readme
33
+ class Client
34
+ BASE_URL = "https://api.apiverve.com/v1/csrparser"
35
+ DEFAULT_TIMEOUT = 30
36
+
37
+ # Validation rules for parameters
38
+ VALIDATION_RULES = {
39
+ 'csr' => { type: 'string', required: true }
40
+ }
41
+
42
+ # Format validation patterns
43
+ FORMAT_PATTERNS = {
44
+ 'email' => /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
45
+ 'url' => /^https?:\/\/.+/,
46
+ 'ip' => /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$|^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$/,
47
+ 'date' => /^\d{4}-\d{2}-\d{2}$/,
48
+ 'hexColor' => /^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/
49
+ }.freeze
50
+
51
+ # Initialize the client
52
+ #
53
+ # @param api_key [String] Your APIVerve API key
54
+ # @param timeout [Integer] Request timeout in seconds (default: 30)
55
+ # @param debug [Boolean] Enable debug logging (default: false)
56
+ # @raise [ArgumentError] If API key is invalid
57
+ def initialize(api_key:, timeout: DEFAULT_TIMEOUT, debug: false)
58
+ validate_api_key!(api_key)
59
+
60
+ @api_key = api_key
61
+ @timeout = timeout
62
+ @debug = debug
63
+
64
+ @connection = Faraday.new(url: BASE_URL) do |conn|
65
+ conn.request :multipart
66
+ conn.request :url_encoded
67
+ conn.adapter Faraday.default_adapter
68
+ conn.options.timeout = @timeout
69
+ conn.headers["x-api-key"] = @api_key
70
+ conn.headers["auth-mode"] = "rubygems-package"
71
+ conn.headers["Content-Type"] = "application/json"
72
+ end
73
+ end
74
+
75
+ # Execute the API request
76
+ #
77
+ # @param params [Hash] Query parameters or request body
78
+ # @return [Hash] API response
79
+ # @raise [APIError] If the request fails
80
+ # @raise [ValidationError] If parameter validation fails
81
+ def execute(params = {})
82
+ validate_params!(params)
83
+
84
+ log("Making POST request to #{BASE_URL}")
85
+ log("Parameters: #{params.inspect}") if params.any?
86
+
87
+ response = @connection.post do |req|
88
+ req.body = params.to_json
89
+ end
90
+
91
+ handle_response(response)
92
+ end
93
+
94
+ private
95
+
96
+ def validate_api_key!(api_key)
97
+ raise ArgumentError, "API key is required. Get your API key at: https://apiverve.com" if api_key.nil? || api_key.strip.empty?
98
+
99
+ unless api_key.match?(/^[a-zA-Z0-9_-]+$/)
100
+ raise ArgumentError, "Invalid API key format. API key should only contain letters, numbers, hyphens, and underscores."
101
+ end
102
+ end
103
+
104
+ def validate_params!(params)
105
+ return if VALIDATION_RULES.empty?
106
+
107
+ errors = []
108
+
109
+ VALIDATION_RULES.each do |param_name, rules|
110
+ value = params[param_name.to_sym] || params[param_name]
111
+
112
+ # Check required
113
+ if rules[:required] && (value.nil? || value.to_s.empty?)
114
+ errors << "Required parameter [#{param_name}] is missing."
115
+ next
116
+ end
117
+
118
+ next if value.nil?
119
+
120
+ case rules[:type]
121
+ when "integer", "number"
122
+ begin
123
+ num_value = rules[:type] == "number" ? Float(value) : Integer(value)
124
+ errors << "Parameter [#{param_name}] must be at least #{rules[:min]}." if rules[:min] && num_value < rules[:min]
125
+ errors << "Parameter [#{param_name}] must be at most #{rules[:max]}." if rules[:max] && num_value > rules[:max]
126
+ rescue ArgumentError, TypeError
127
+ errors << "Parameter [#{param_name}] must be a valid #{rules[:type]}."
128
+ end
129
+ when "string"
130
+ unless value.is_a?(String)
131
+ errors << "Parameter [#{param_name}] must be a string."
132
+ next
133
+ end
134
+ errors << "Parameter [#{param_name}] must be at least #{rules[:min_length]} characters." if rules[:min_length] && value.length < rules[:min_length]
135
+ errors << "Parameter [#{param_name}] must be at most #{rules[:max_length]} characters." if rules[:max_length] && value.length > rules[:max_length]
136
+
137
+ if rules[:format] && FORMAT_PATTERNS[rules[:format]]
138
+ unless value.match?(FORMAT_PATTERNS[rules[:format]])
139
+ errors << "Parameter [#{param_name}] must be a valid #{rules[:format]}."
140
+ end
141
+ end
142
+ when "boolean"
143
+ unless [true, false, "true", "false"].include?(value)
144
+ errors << "Parameter [#{param_name}] must be a boolean."
145
+ end
146
+ end
147
+
148
+ # Enum validation
149
+ if rules[:enum] && !rules[:enum].include?(value)
150
+ errors << "Parameter [#{param_name}] must be one of: #{rules[:enum].join(', ')}."
151
+ end
152
+ end
153
+
154
+ raise ValidationError, errors unless errors.empty?
155
+ end
156
+
157
+ def handle_response(response)
158
+ log("Response status: #{response.status}")
159
+
160
+ data = JSON.parse(response.body)
161
+
162
+ if data["status"] == "error"
163
+ raise APIError.new(data["error"] || "Unknown API error", response.status, data)
164
+ end
165
+
166
+ unless response.success?
167
+ raise APIError.new(data["error"] || "HTTP #{response.status} error", response.status, data)
168
+ end
169
+
170
+ log("Request successful")
171
+ data
172
+ rescue JSON::ParserError => e
173
+ raise APIError.new("Invalid JSON response: #{e.message}", response.status)
174
+ end
175
+
176
+ def log(message)
177
+ puts "[APIVerve::Csrparser] #{message}" if @debug
178
+ end
179
+ end
180
+
181
+ # Custom error class for API errors
182
+ class APIError < StandardError
183
+ attr_reader :status_code, :response
184
+
185
+ def initialize(message, status_code = nil, response = nil)
186
+ @status_code = status_code
187
+ @response = response
188
+ super(message)
189
+ end
190
+ end
191
+
192
+ # Custom error class for validation errors
193
+ class ValidationError < StandardError
194
+ attr_reader :errors
195
+
196
+ def initialize(errors)
197
+ @errors = errors
198
+ super("Validation failed: #{errors.join(' ')}")
199
+ end
200
+ end
201
+ end
202
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "apiverve_csrparser/client"
4
+
5
+ module APIVerve
6
+ module Csrparser
7
+ VERSION = "1.2.0"
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: apiverve_csrparser
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.0
5
+ platform: ruby
6
+ authors:
7
+ - APIVerve
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: faraday
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '1.0'
19
+ - - "<"
20
+ - !ruby/object:Gem::Version
21
+ version: '3.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '1.0'
29
+ - - "<"
30
+ - !ruby/object:Gem::Version
31
+ version: '3.0'
32
+ - !ruby/object:Gem::Dependency
33
+ name: faraday-multipart
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - "~>"
37
+ - !ruby/object:Gem::Version
38
+ version: '1.0'
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - "~>"
44
+ - !ruby/object:Gem::Version
45
+ version: '1.0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: json
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: '2.0'
53
+ type: :runtime
54
+ prerelease: false
55
+ version_requirements: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '2.0'
60
+ description: CSR Parser extracts and analyzes information from Certificate Signing
61
+ Requests (CSRs), providing detailed subject information, public key details, and
62
+ fingerprints.
63
+ email:
64
+ - hello@apiverve.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - LICENSE
70
+ - README.md
71
+ - lib/apiverve/client.rb
72
+ - lib/apiverve_csrparser.rb
73
+ - lib/apiverve_csrparser/client.rb
74
+ homepage: https://apiverve.com/marketplace/csrparser?utm_source=ruby&utm_medium=homepage
75
+ licenses:
76
+ - MIT
77
+ metadata:
78
+ homepage_uri: https://apiverve.com/marketplace/csrparser?utm_source=ruby&utm_medium=homepage
79
+ source_code_uri: https://github.com/apiverve/csrparser-API/tree/main/ruby
80
+ changelog_uri: https://apiverve.com/changelog
81
+ documentation_uri: https://docs.apiverve.com/ref/csrparser
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 2.7.0
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubygems_version: 3.6.9
97
+ specification_version: 4
98
+ summary: CSR Parser API - Ruby Client
99
+ test_files: []