apiverve_markdowntohtml 1.2.0 → 1.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: 905bb51e8a44cc8000454327e03b7da341a57b82c2181555ac3b9e64117f5f70
4
- data.tar.gz: 70193324982e64d942314cb8eb53fc97926463cd68d3fdee7931f62c3ce72b6b
3
+ metadata.gz: 000ca126196b21a460ccb7febed3cc16bd07257e135bd3f713846c53d5e38509
4
+ data.tar.gz: 3fdc4fdb94577a6ebc658b28df85963ad2a2ea6dafc57a7be4e71bdcd78cb8eb
5
5
  SHA512:
6
- metadata.gz: 5e337d112d0852c452fea3788d671552af80819482d495f8435ed6352d8a684a840704c0d053d6387fb4b84fb1b3e4906182cf85ffd563fb8135e234825b7e33
7
- data.tar.gz: 2f182d16283b9fd002bb7015b94694d1e68f24c6f3cab9c335b1861065f10ee666046f4552345e226b0b549df63daa40a23fd3fc1cdaa3f841660e328ebb4a9d
6
+ metadata.gz: 419a3fc4b14a1b4cff68abd98596e7eb7ba2bc43d505c4088d0e94f72bca657b4fe0155a35d944fc2cbb127ef1efc68f36cdfb9ec8a7be46f92aef2ca8d8bf61
7
+ data.tar.gz: b9c504759223ad35a7f8cde7659b999b1cba1e705fe2f30cb03b15f1669121803f28a03689adb801def8ceed367e27c904da87f10e69db13aede6c7811242a59
data/LICENSE CHANGED
@@ -1,21 +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.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 APIVerve and EvlarSoft LLC
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 CHANGED
@@ -1,40 +1,40 @@
1
- # Markdown to HTML API - Ruby Gem
2
-
3
- Markdown to HTML parses markdown syntax and converts it to clean, semantic HTML suitable for web rendering and content management.
4
-
5
- ## Installation
6
-
7
- Add this line to your application's Gemfile:
8
-
9
- ```ruby
10
- gem 'apiverve_markdowntohtml'
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_markdowntohtml
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_markdowntohtml'
33
-
34
- # Initialize the client
35
- client = APIVerve::Markdowntohtml::Client.new(api_key: "YOUR_API_KEY")
36
-
37
- # Make a request
1
+ # Markdown to HTML API - Ruby Gem
2
+
3
+ Markdown to HTML is a markdown converter API that parses markdown syntax and converts it to clean, semantic HTML suitable for web rendering and content management.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'apiverve_markdowntohtml'
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_markdowntohtml
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_markdowntohtml'
33
+
34
+ # Initialize the client
35
+ client = APIVerve::Markdowntohtml::Client.new(api_key: "YOUR_API_KEY")
36
+
37
+ # Make a request
38
38
  response = client.execute({ markdown: "# Hello World
39
39
 
40
40
  This is a **bold** statement and this is *italic*.
@@ -45,17 +45,17 @@ This is a **bold** statement and this is *italic*.
45
45
  - Fast conversion
46
46
  - Supports common markdown syntax
47
47
 
48
- [Link to example](https://example.com)" })
49
-
50
- # Print the response
51
- puts response
52
- ```
53
-
54
-
55
- ### Error Handling
56
-
57
- ```ruby
58
- begin
48
+ [Link to example](https://example.com)" })
49
+
50
+ # Print the response
51
+ puts response
52
+ ```
53
+
54
+
55
+ ### Error Handling
56
+
57
+ ```ruby
58
+ begin
59
59
  response = client.execute({ markdown: "# Hello World
60
60
 
61
61
  This is a **bold** statement and this is *italic*.
@@ -66,29 +66,29 @@ This is a **bold** statement and this is *italic*.
66
66
  - Fast conversion
67
67
  - Supports common markdown syntax
68
68
 
69
- [Link to example](https://example.com)" })
70
- puts response["data"]
71
- rescue APIVerve::Markdowntohtml::ValidationError => e
72
- puts "Validation error: #{e.errors.join(', ')}"
73
- rescue APIVerve::Markdowntohtml::APIError => e
74
- puts "API error: #{e.message}"
75
- puts "Status code: #{e.status_code}"
76
- end
77
- ```
78
-
79
- ### Debug Mode
80
-
81
- ```ruby
82
- # Enable debug logging
83
- client = APIVerve::Markdowntohtml::Client.new(
84
- api_key: "YOUR_API_KEY",
85
- debug: true
86
- )
87
- ```
88
-
89
- ## Example Response
90
-
91
- ```json
69
+ [Link to example](https://example.com)" })
70
+ puts response["data"]
71
+ rescue APIVerve::Markdowntohtml::ValidationError => e
72
+ puts "Validation error: #{e.errors.join(', ')}"
73
+ rescue APIVerve::Markdowntohtml::APIError => e
74
+ puts "API error: #{e.message}"
75
+ puts "Status code: #{e.status_code}"
76
+ end
77
+ ```
78
+
79
+ ### Debug Mode
80
+
81
+ ```ruby
82
+ # Enable debug logging
83
+ client = APIVerve::Markdowntohtml::Client.new(
84
+ api_key: "YOUR_API_KEY",
85
+ debug: true
86
+ )
87
+ ```
88
+
89
+ ## Example Response
90
+
91
+ ```json
92
92
  {
93
93
  "status": "ok",
94
94
  "error": null,
@@ -97,18 +97,18 @@ client = APIVerve::Markdowntohtml::Client.new(
97
97
  "markdownLength": 185,
98
98
  "htmlLength": 272
99
99
  }
100
- }
101
- ```
102
-
103
- ## Documentation
104
-
105
- For more information, visit the [API Documentation](https://docs.apiverve.com/ref/markdowntohtml?utm_source=rubygems&utm_medium=readme).
106
-
107
- ## Support
108
-
109
- - Website: [https://markdowntohtml.apiverve.com?utm_source=ruby&utm_medium=readme](https://markdowntohtml.apiverve.com?utm_source=ruby&utm_medium=readme)
110
- - Email: hello@apiverve.com
111
-
112
- ## License
113
-
114
- This gem is available under the [MIT License](LICENSE).
100
+ }
101
+ ```
102
+
103
+ ## Documentation
104
+
105
+ For more information, visit the [API Documentation](https://docs.apiverve.com/ref/markdowntohtml?utm_source=rubygems&utm_medium=referral&utm_content=readme).
106
+
107
+ ## Support
108
+
109
+ - Website: [https://apiverve.com/marketplace/markdowntohtml?utm_source=ruby&utm_medium=referral&utm_content=readme](https://apiverve.com/marketplace/markdowntohtml?utm_source=ruby&utm_medium=referral&utm_content=readme)
110
+ - Email: hello@apiverve.com
111
+
112
+ ## License
113
+
114
+ This gem is available under the [MIT License](LICENSE).
@@ -1,15 +1,15 @@
1
- # frozen_string_literal: true
2
-
3
- require "faraday"
4
- require "faraday/multipart"
5
- require "json"
6
-
7
- module APIVerve
8
- module Markdowntohtml
9
- # Client for the Markdown to HTML API
10
- #
11
- # @example Basic usage
12
- # client = APIVerve::Markdowntohtml::Client.new(api_key: "your_api_key")
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+ require "faraday/multipart"
5
+ require "json"
6
+
7
+ module APIVerve
8
+ module Markdowntohtml
9
+ # Client for the Markdown to HTML API
10
+ #
11
+ # @example Basic usage
12
+ # client = APIVerve::Markdowntohtml::Client.new(api_key: "your_api_key")
13
13
  # response = client.execute({ markdown: "# Hello World
14
14
 
15
15
  This is a **bold** statement and this is *italic*.
@@ -20,177 +20,175 @@ This is a **bold** statement and this is *italic*.
20
20
  - Fast conversion
21
21
  - Supports common markdown syntax
22
22
 
23
- [Link to example](https://example.com)" })
24
- # puts response
25
- #
26
- # @see https://markdowntohtml.apiverve.com?utm_source=ruby&utm_medium=readme
27
- class Client
28
- BASE_URL = "https://api.apiverve.com/v1/markdowntohtml"
29
- DEFAULT_TIMEOUT = 30
30
-
31
- # Validation rules for parameters
32
- VALIDATION_RULES = {
33
- 'markdown' => { type: 'string', required: true }
34
- }
35
-
36
- # Format validation patterns
37
- FORMAT_PATTERNS = {
38
- 'email' => /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
39
- 'url' => /^https?:\/\/.+/,
40
- '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}$/,
41
- 'date' => /^\d{4}-\d{2}-\d{2}$/,
42
- 'hexColor' => /^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/
43
- }.freeze
44
-
45
- # Initialize the client
46
- #
47
- # @param api_key [String] Your APIVerve API key
48
- # @param timeout [Integer] Request timeout in seconds (default: 30)
49
- # @param debug [Boolean] Enable debug logging (default: false)
50
- # @raise [ArgumentError] If API key is invalid
51
- def initialize(api_key:, timeout: DEFAULT_TIMEOUT, debug: false)
52
- validate_api_key!(api_key)
53
-
54
- @api_key = api_key
55
- @timeout = timeout
56
- @debug = debug
57
-
58
- @connection = Faraday.new(url: BASE_URL) do |conn|
59
- conn.request :multipart
60
- conn.request :url_encoded
61
- conn.adapter Faraday.default_adapter
62
- conn.options.timeout = @timeout
63
- conn.headers["x-api-key"] = @api_key
64
- conn.headers["auth-mode"] = "rubygems-package"
65
- conn.headers["Content-Type"] = "application/json"
66
- end
67
- end
68
-
69
- # Execute the API request
70
- #
71
- # @param params [Hash] Query parameters or request body
72
- # @return [Hash] API response
73
- # @raise [APIError] If the request fails
74
- # @raise [ValidationError] If parameter validation fails
75
- def execute(params = {})
76
- validate_params!(params)
77
-
78
- log("Making POST request to #{BASE_URL}")
79
- log("Parameters: #{params.inspect}") if params.any?
80
-
81
- response = @connection.post do |req|
82
- req.body = params.to_json
83
- end
84
-
85
- handle_response(response)
86
- end
87
-
88
- private
89
-
90
- def validate_api_key!(api_key)
91
- raise ArgumentError, "API key is required. Get your API key at: https://apiverve.com" if api_key.nil? || api_key.strip.empty?
92
-
93
- unless api_key.match?(/^[a-zA-Z0-9_-]+$/)
94
- raise ArgumentError, "Invalid API key format. API key should only contain letters, numbers, hyphens, and underscores."
95
- end
96
- end
97
-
98
- def validate_params!(params)
99
- return if VALIDATION_RULES.empty?
100
-
101
- errors = []
102
-
103
- VALIDATION_RULES.each do |param_name, rules|
104
- value = params[param_name.to_sym] || params[param_name]
105
-
106
- # Check required
107
- if rules[:required] && (value.nil? || value.to_s.empty?)
108
- errors << "Required parameter [#{param_name}] is missing."
109
- next
110
- end
111
-
112
- next if value.nil?
113
-
114
- case rules[:type]
115
- when "integer", "number"
116
- begin
117
- num_value = rules[:type] == "number" ? Float(value) : Integer(value)
118
- errors << "Parameter [#{param_name}] must be at least #{rules[:min]}." if rules[:min] && num_value < rules[:min]
119
- errors << "Parameter [#{param_name}] must be at most #{rules[:max]}." if rules[:max] && num_value > rules[:max]
120
- rescue ArgumentError, TypeError
121
- errors << "Parameter [#{param_name}] must be a valid #{rules[:type]}."
122
- end
123
- when "string"
124
- unless value.is_a?(String)
125
- errors << "Parameter [#{param_name}] must be a string."
126
- next
127
- end
128
- errors << "Parameter [#{param_name}] must be at least #{rules[:min_length]} characters." if rules[:min_length] && value.length < rules[:min_length]
129
- errors << "Parameter [#{param_name}] must be at most #{rules[:max_length]} characters." if rules[:max_length] && value.length > rules[:max_length]
130
-
131
- if rules[:format] && FORMAT_PATTERNS[rules[:format]]
132
- unless value.match?(FORMAT_PATTERNS[rules[:format]])
133
- errors << "Parameter [#{param_name}] must be a valid #{rules[:format]}."
134
- end
135
- end
136
- when "boolean"
137
- unless [true, false, "true", "false"].include?(value)
138
- errors << "Parameter [#{param_name}] must be a boolean."
139
- end
140
- end
141
-
142
- # Enum validation
143
- if rules[:enum] && !rules[:enum].include?(value)
144
- errors << "Parameter [#{param_name}] must be one of: #{rules[:enum].join(', ')}."
145
- end
146
- end
147
-
148
- raise ValidationError, errors unless errors.empty?
149
- end
150
-
151
- def handle_response(response)
152
- log("Response status: #{response.status}")
153
-
154
- data = JSON.parse(response.body)
155
-
156
- if data["status"] == "error"
157
- raise APIError.new(data["error"] || "Unknown API error", response.status, data)
158
- end
159
-
160
- unless response.success?
161
- raise APIError.new(data["error"] || "HTTP #{response.status} error", response.status, data)
162
- end
163
-
164
- log("Request successful")
165
- data
166
- rescue JSON::ParserError => e
167
- raise APIError.new("Invalid JSON response: #{e.message}", response.status)
168
- end
169
-
170
- def log(message)
171
- puts "[APIVerve::Markdowntohtml] #{message}" if @debug
172
- end
173
- end
174
-
175
- # Custom error class for API errors
176
- class APIError < StandardError
177
- attr_reader :status_code, :response
178
-
179
- def initialize(message, status_code = nil, response = nil)
180
- @status_code = status_code
181
- @response = response
182
- super(message)
183
- end
184
- end
185
-
186
- # Custom error class for validation errors
187
- class ValidationError < StandardError
188
- attr_reader :errors
189
-
190
- def initialize(errors)
191
- @errors = errors
192
- super("Validation failed: #{errors.join(' ')}")
193
- end
194
- end
195
- end
196
- end
23
+ [Link to example](https://example.com)" })
24
+ # puts response
25
+ #
26
+ # @see https://apiverve.com/marketplace/markdowntohtml?utm_source=ruby&utm_medium=referral&utm_content=readme
27
+ class Client
28
+ BASE_URL = "https://api.apiverve.com/v1/markdowntohtml"
29
+ DEFAULT_TIMEOUT = 30
30
+
31
+ # Validation rules for parameters
32
+ VALIDATION_RULES = { 'markdown' => { type: 'string', required: true } }
33
+
34
+ # Format validation patterns
35
+ FORMAT_PATTERNS = {
36
+ 'email' => /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
37
+ 'url' => /^https?:\/\/.+/,
38
+ '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}$/,
39
+ 'date' => /^\d{4}-\d{2}-\d{2}$/,
40
+ 'hexColor' => /^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/
41
+ }.freeze
42
+
43
+ # Initialize the client
44
+ #
45
+ # @param api_key [String] Your APIVerve API key
46
+ # @param timeout [Integer] Request timeout in seconds (default: 30)
47
+ # @param debug [Boolean] Enable debug logging (default: false)
48
+ # @raise [ArgumentError] If API key is invalid
49
+ def initialize(api_key:, timeout: DEFAULT_TIMEOUT, debug: false)
50
+ validate_api_key!(api_key)
51
+
52
+ @api_key = api_key
53
+ @timeout = timeout
54
+ @debug = debug
55
+
56
+ @connection = Faraday.new(url: BASE_URL) do |conn|
57
+ conn.request :multipart
58
+ conn.request :url_encoded
59
+ conn.adapter Faraday.default_adapter
60
+ conn.options.timeout = @timeout
61
+ conn.headers["x-api-key"] = @api_key
62
+ conn.headers["auth-mode"] = "rubygems-package"
63
+ conn.headers["Content-Type"] = "application/json"
64
+ end
65
+ end
66
+
67
+ # Execute the API request
68
+ #
69
+ # @param params [Hash] Query parameters or request body
70
+ # @return [Hash] API response
71
+ # @raise [APIError] If the request fails
72
+ # @raise [ValidationError] If parameter validation fails
73
+ def execute(params = {})
74
+ validate_params!(params)
75
+
76
+ log("Making POST request to #{BASE_URL}")
77
+ log("Parameters: #{params.inspect}") if params.any?
78
+
79
+ response = @connection.post do |req|
80
+ req.body = params.to_json
81
+ end
82
+
83
+ handle_response(response)
84
+ end
85
+
86
+ private
87
+
88
+ def validate_api_key!(api_key)
89
+ raise ArgumentError, "API key is required. Get your API key at: https://apiverve.com" if api_key.nil? || api_key.strip.empty?
90
+
91
+ unless api_key.match?(/^[a-zA-Z0-9_-]+$/)
92
+ raise ArgumentError, "Invalid API key format. API key should only contain letters, numbers, hyphens, and underscores."
93
+ end
94
+ end
95
+
96
+ def validate_params!(params)
97
+ return if VALIDATION_RULES.empty?
98
+
99
+ errors = []
100
+
101
+ VALIDATION_RULES.each do |param_name, rules|
102
+ value = params[param_name.to_sym] || params[param_name]
103
+
104
+ # Check required
105
+ if rules[:required] && (value.nil? || value.to_s.empty?)
106
+ errors << "Required parameter [#{param_name}] is missing."
107
+ next
108
+ end
109
+
110
+ next if value.nil?
111
+
112
+ case rules[:type]
113
+ when "integer", "number"
114
+ begin
115
+ num_value = rules[:type] == "number" ? Float(value) : Integer(value)
116
+ errors << "Parameter [#{param_name}] must be at least #{rules[:min]}." if rules[:min] && num_value < rules[:min]
117
+ errors << "Parameter [#{param_name}] must be at most #{rules[:max]}." if rules[:max] && num_value > rules[:max]
118
+ rescue ArgumentError, TypeError
119
+ errors << "Parameter [#{param_name}] must be a valid #{rules[:type]}."
120
+ end
121
+ when "string"
122
+ unless value.is_a?(String)
123
+ errors << "Parameter [#{param_name}] must be a string."
124
+ next
125
+ end
126
+ errors << "Parameter [#{param_name}] must be at least #{rules[:min_length]} characters." if rules[:min_length] && value.length < rules[:min_length]
127
+ errors << "Parameter [#{param_name}] must be at most #{rules[:max_length]} characters." if rules[:max_length] && value.length > rules[:max_length]
128
+
129
+ if rules[:format] && FORMAT_PATTERNS[rules[:format]]
130
+ unless value.match?(FORMAT_PATTERNS[rules[:format]])
131
+ errors << "Parameter [#{param_name}] must be a valid #{rules[:format]}."
132
+ end
133
+ end
134
+ when "boolean"
135
+ unless [true, false, "true", "false"].include?(value)
136
+ errors << "Parameter [#{param_name}] must be a boolean."
137
+ end
138
+ end
139
+
140
+ # Enum validation
141
+ if rules[:enum] && !rules[:enum].include?(value)
142
+ errors << "Parameter [#{param_name}] must be one of: #{rules[:enum].join(', ')}."
143
+ end
144
+ end
145
+
146
+ raise ValidationError, errors unless errors.empty?
147
+ end
148
+
149
+ def handle_response(response)
150
+ log("Response status: #{response.status}")
151
+
152
+ data = JSON.parse(response.body)
153
+
154
+ if data["status"] == "error"
155
+ raise APIError.new(data["error"] || "Unknown API error", response.status, data)
156
+ end
157
+
158
+ unless response.success?
159
+ raise APIError.new(data["error"] || "HTTP #{response.status} error", response.status, data)
160
+ end
161
+
162
+ log("Request successful")
163
+ data
164
+ rescue JSON::ParserError => e
165
+ raise APIError.new("Invalid JSON response: #{e.message}", response.status)
166
+ end
167
+
168
+ def log(message)
169
+ puts "[APIVerve::Markdowntohtml] #{message}" if @debug
170
+ end
171
+ end
172
+
173
+ # Custom error class for API errors
174
+ class APIError < StandardError
175
+ attr_reader :status_code, :response
176
+
177
+ def initialize(message, status_code = nil, response = nil)
178
+ @status_code = status_code
179
+ @response = response
180
+ super(message)
181
+ end
182
+ end
183
+
184
+ # Custom error class for validation errors
185
+ class ValidationError < StandardError
186
+ attr_reader :errors
187
+
188
+ def initialize(errors)
189
+ @errors = errors
190
+ super("Validation failed: #{errors.join(' ')}")
191
+ end
192
+ end
193
+ end
194
+ end
@@ -1,9 +1,9 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "apiverve_markdowntohtml/client"
4
-
5
- module APIVerve
6
- module Markdowntohtml
7
- VERSION = "1.2.0"
8
- end
9
- end
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "apiverve_markdowntohtml/client"
4
+
5
+ module APIVerve
6
+ module Markdowntohtml
7
+ VERSION = "1.2.2"
8
+ end
9
+ end
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apiverve_markdowntohtml
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - APIVerve
8
+ autorequire:
8
9
  bindir: bin
9
10
  cert_chain: []
10
- date: 1980-01-02 00:00:00.000000000 Z
11
+ date: 2026-10-21 00:00:00.000000000 Z
11
12
  dependencies:
12
13
  - !ruby/object:Gem::Dependency
13
14
  name: faraday
@@ -57,8 +58,8 @@ dependencies:
57
58
  - - "~>"
58
59
  - !ruby/object:Gem::Version
59
60
  version: '2.0'
60
- description: Markdown to HTML parses markdown syntax and converts it to clean, semantic
61
- HTML suitable for web rendering and content management.
61
+ description: Markdown to HTML is a markdown converter API that parses markdown syntax
62
+ and converts it to clean, semantic HTML suitable for web rendering and content management.
62
63
  email:
63
64
  - hello@apiverve.com
64
65
  executables: []
@@ -67,17 +68,17 @@ extra_rdoc_files: []
67
68
  files:
68
69
  - LICENSE
69
70
  - README.md
70
- - lib/apiverve/client.rb
71
71
  - lib/apiverve_markdowntohtml.rb
72
72
  - lib/apiverve_markdowntohtml/client.rb
73
- homepage: https://markdowntohtml.apiverve.com?utm_source=ruby&utm_medium=homepage
73
+ homepage: https://apiverve.com/marketplace/markdowntohtml?utm_source=ruby&utm_medium=referral&utm_content=homepage
74
74
  licenses:
75
75
  - MIT
76
76
  metadata:
77
- homepage_uri: https://markdowntohtml.apiverve.com?utm_source=ruby&utm_medium=homepage
77
+ homepage_uri: https://apiverve.com/marketplace/markdowntohtml?utm_source=ruby&utm_medium=referral&utm_content=homepage
78
78
  source_code_uri: https://github.com/apiverve/markdowntohtml-API/tree/main/ruby
79
79
  changelog_uri: https://apiverve.com/changelog
80
80
  documentation_uri: https://docs.apiverve.com/ref/markdowntohtml
81
+ post_install_message:
81
82
  rdoc_options: []
82
83
  require_paths:
83
84
  - lib
@@ -92,7 +93,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
93
  - !ruby/object:Gem::Version
93
94
  version: '0'
94
95
  requirements: []
95
- rubygems_version: 3.6.9
96
+ rubygems_version: 3.0.3.1
97
+ signing_key:
96
98
  specification_version: 4
97
99
  summary: Markdown to HTML API - Ruby Client
98
100
  test_files: []
@@ -1,194 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "faraday"
4
- require "faraday/multipart"
5
- require "json"
6
-
7
- module APIVerve
8
- module Markdowntohtml
9
- # Client for the Markdown to HTML API
10
- #
11
- # @example Basic usage
12
- # client = APIVerve::Markdowntohtml::Client.new(api_key: "your_api_key")
13
- # response = client.execute({ markdown: "# Hello World
14
-
15
- This is a **bold** statement and this is *italic*.
16
-
17
- ## Features
18
-
19
- - Easy to use
20
- - Fast conversion
21
- - Supports common markdown syntax
22
-
23
- [Link to example](https://example.com)" })
24
- # puts response
25
- #
26
- # @see https://markdowntohtml.apiverve.com?utm_source=ruby&utm_medium=readme
27
- class Client
28
- BASE_URL = "https://api.apiverve.com/v1/markdowntohtml"
29
- DEFAULT_TIMEOUT = 30
30
-
31
- # Validation rules for parameters
32
- VALIDATION_RULES = { 'markdown' => { type: 'string', required: true } }
33
-
34
- # Format validation patterns
35
- FORMAT_PATTERNS = {
36
- 'email' => /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
37
- 'url' => /^https?:\/\/.+/,
38
- '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}$/,
39
- 'date' => /^\d{4}-\d{2}-\d{2}$/,
40
- 'hexColor' => /^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/
41
- }.freeze
42
-
43
- # Initialize the client
44
- #
45
- # @param api_key [String] Your APIVerve API key
46
- # @param timeout [Integer] Request timeout in seconds (default: 30)
47
- # @param debug [Boolean] Enable debug logging (default: false)
48
- # @raise [ArgumentError] If API key is invalid
49
- def initialize(api_key:, timeout: DEFAULT_TIMEOUT, debug: false)
50
- validate_api_key!(api_key)
51
-
52
- @api_key = api_key
53
- @timeout = timeout
54
- @debug = debug
55
-
56
- @connection = Faraday.new(url: BASE_URL) do |conn|
57
- conn.request :multipart
58
- conn.request :url_encoded
59
- conn.adapter Faraday.default_adapter
60
- conn.options.timeout = @timeout
61
- conn.headers["x-api-key"] = @api_key
62
- conn.headers["auth-mode"] = "rubygems-package"
63
- conn.headers["Content-Type"] = "application/json"
64
- end
65
- end
66
-
67
- # Execute the API request
68
- #
69
- # @param params [Hash] Query parameters or request body
70
- # @return [Hash] API response
71
- # @raise [APIError] If the request fails
72
- # @raise [ValidationError] If parameter validation fails
73
- def execute(params = {})
74
- validate_params!(params)
75
-
76
- log("Making POST request to #{BASE_URL}")
77
- log("Parameters: #{params.inspect}") if params.any?
78
-
79
- response = @connection.post do |req|
80
- req.body = params.to_json
81
- end
82
-
83
- handle_response(response)
84
- end
85
-
86
- private
87
-
88
- def validate_api_key!(api_key)
89
- raise ArgumentError, "API key is required. Get your API key at: https://apiverve.com" if api_key.nil? || api_key.strip.empty?
90
-
91
- unless api_key.match?(/^[a-zA-Z0-9_-]+$/)
92
- raise ArgumentError, "Invalid API key format. API key should only contain letters, numbers, hyphens, and underscores."
93
- end
94
- end
95
-
96
- def validate_params!(params)
97
- return if VALIDATION_RULES.empty?
98
-
99
- errors = []
100
-
101
- VALIDATION_RULES.each do |param_name, rules|
102
- value = params[param_name.to_sym] || params[param_name]
103
-
104
- # Check required
105
- if rules[:required] && (value.nil? || value.to_s.empty?)
106
- errors << "Required parameter [#{param_name}] is missing."
107
- next
108
- end
109
-
110
- next if value.nil?
111
-
112
- case rules[:type]
113
- when "integer", "number"
114
- begin
115
- num_value = rules[:type] == "number" ? Float(value) : Integer(value)
116
- errors << "Parameter [#{param_name}] must be at least #{rules[:min]}." if rules[:min] && num_value < rules[:min]
117
- errors << "Parameter [#{param_name}] must be at most #{rules[:max]}." if rules[:max] && num_value > rules[:max]
118
- rescue ArgumentError, TypeError
119
- errors << "Parameter [#{param_name}] must be a valid #{rules[:type]}."
120
- end
121
- when "string"
122
- unless value.is_a?(String)
123
- errors << "Parameter [#{param_name}] must be a string."
124
- next
125
- end
126
- errors << "Parameter [#{param_name}] must be at least #{rules[:min_length]} characters." if rules[:min_length] && value.length < rules[:min_length]
127
- errors << "Parameter [#{param_name}] must be at most #{rules[:max_length]} characters." if rules[:max_length] && value.length > rules[:max_length]
128
-
129
- if rules[:format] && FORMAT_PATTERNS[rules[:format]]
130
- unless value.match?(FORMAT_PATTERNS[rules[:format]])
131
- errors << "Parameter [#{param_name}] must be a valid #{rules[:format]}."
132
- end
133
- end
134
- when "boolean"
135
- unless [true, false, "true", "false"].include?(value)
136
- errors << "Parameter [#{param_name}] must be a boolean."
137
- end
138
- end
139
-
140
- # Enum validation
141
- if rules[:enum] && !rules[:enum].include?(value)
142
- errors << "Parameter [#{param_name}] must be one of: #{rules[:enum].join(', ')}."
143
- end
144
- end
145
-
146
- raise ValidationError, errors unless errors.empty?
147
- end
148
-
149
- def handle_response(response)
150
- log("Response status: #{response.status}")
151
-
152
- data = JSON.parse(response.body)
153
-
154
- if data["status"] == "error"
155
- raise APIError.new(data["error"] || "Unknown API error", response.status, data)
156
- end
157
-
158
- unless response.success?
159
- raise APIError.new(data["error"] || "HTTP #{response.status} error", response.status, data)
160
- end
161
-
162
- log("Request successful")
163
- data
164
- rescue JSON::ParserError => e
165
- raise APIError.new("Invalid JSON response: #{e.message}", response.status)
166
- end
167
-
168
- def log(message)
169
- puts "[APIVerve::Markdowntohtml] #{message}" if @debug
170
- end
171
- end
172
-
173
- # Custom error class for API errors
174
- class APIError < StandardError
175
- attr_reader :status_code, :response
176
-
177
- def initialize(message, status_code = nil, response = nil)
178
- @status_code = status_code
179
- @response = response
180
- super(message)
181
- end
182
- end
183
-
184
- # Custom error class for validation errors
185
- class ValidationError < StandardError
186
- attr_reader :errors
187
-
188
- def initialize(errors)
189
- @errors = errors
190
- super("Validation failed: #{errors.join(' ')}")
191
- end
192
- end
193
- end
194
- end