HTML Entities Encoder/Decoder API - Ruby Gem

HTML Entities Encoder/Decoder is a tool for encoding and decoding HTML entities. It converts special characters to HTML entities and vice versa to prevent XSS attacks and display special characters properly.

Installation

Add this line to your application's Gemfile:

gem 'apiverve_htmlentities'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install apiverve_htmlentities

Getting Started

Get your API key at APIVerve

Basic Usage

require 'apiverve_htmlentities'

# Initialize the client
client = APIVerve::Htmlentities::Client.new(api_key: "YOUR_API_KEY")

# Make a request
response = client.execute({
  html: "<div class=\"test\">Hello & World</div>",
  action: "encode"
})

# Print the response
puts response

Error Handling

begin
  response = client.execute({ html: "<div class=\"test\">Hello & World</div>", action: "encode" })
  puts response["data"]
rescue APIVerve::Htmlentities::ValidationError => e
  puts "Validation error: #{e.errors.join(', ')}"
rescue APIVerve::Htmlentities::APIError => e
  puts "API error: #{e.message}"
  puts "Status code: #{e.status_code}"
end

Debug Mode

# Enable debug logging
client = APIVerve::Htmlentities::Client.new(
  api_key: "YOUR_API_KEY",
  debug: true
)

Example Response

{
  "status": "ok",
  "error": null,
  "data": {
    "action": "encode",
    "original": "<div class=\"test\">Hello & World</div>",
    "encoded": "&lt;div class=&quot;test&quot;&gt;Hello &amp; World&lt;&#x2F;div&gt;",
    "entities_replaced": [
      "<",
      "\"",
      ">",
      "&",
      "/"
    ],
    "count": 8
  }
}

Documentation

For more information, visit the API Documentation.

Support

License

This gem is available under the MIT License.