HTML to Text API - Ruby Gem
HTML to Text is a simple tool for converting HTML to text. It returns the text extracted from the HTML.
Installation
Add this line to your application's Gemfile:
gem 'apiverve_htmltotext'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install apiverve_htmltotext
Getting Started
Get your API key at APIVerve
Basic Usage
require 'apiverve_htmltotext'
# Initialize the client
client = APIVerve::Htmltotext::Client.new(api_key: "YOUR_API_KEY")
# Make a request
response = client.execute({ html: "<!doctype html> <html> <head> <title>This is the title of the webpage!</title> </head> <body> <p>This is an example paragraph. Anything in the <strong>body</strong> tag will appear on the page, just like this <strong>p</strong> tag and its contents.</p> </body> </html>" })
# Print the response
puts response
Error Handling
begin
response = client.execute({ html: "<!doctype html> <html> <head> <title>This is the title of the webpage!</title> </head> <body> <p>This is an example paragraph. Anything in the <strong>body</strong> tag will appear on the page, just like this <strong>p</strong> tag and its contents.</p> </body> </html>" })
puts response["data"]
rescue APIVerve::Htmltotext::ValidationError => e
puts "Validation error: #{e.errors.join(', ')}"
rescue APIVerve::Htmltotext::APIError => e
puts "API error: #{e.}"
puts "Status code: #{e.status_code}"
end
Debug Mode
# Enable debug logging
client = APIVerve::Htmltotext::Client.new(
api_key: "YOUR_API_KEY",
debug: true
)
Example Response
{
"status": "ok",
"error": null,
"data": {
"text": "This is an example paragraph. Anything in the body tag will appear on the page, just like this p tag and its contents.",
"parsed": true,
"detectedLanguage": {
"language": "english",
"confidence": 0.3507446808510638
},
"characterCount": 118,
"wordCount": 22
}
}
Documentation
For more information, visit the API Documentation.
Support
- Website: https://htmltotext.apiverve.com?utm_source=ruby&utm_medium=readme
- Email: hello@apiverve.com
License
This gem is available under the MIT License.