Sapling Logo
Tone API quickstart

Ruby Tone Checker

Analyze overall and sentence-level tone from a Ruby application across 28 fine-grained categories.

  • HTTPS POST
  • JSON HTTP API
  • Bearer API key
POST Ruby logo Ruby /api/v1/tone

Ruby tone checker quickstart

Send text to the tone endpoint. The response ranks overall tones and returns a separate probability breakdown for every sentence.

No language-specific SDK is required. The example uses a standard or commonly used HTTP client to call Sapling's JSON API.
Ruby /api/v1/tone
require 'json'
require 'net/http'

api_key = ENV.fetch('SAPLING_API_KEY') { raise 'Set SAPLING_API_KEY first.' }
uri = URI('https://api.sapling.ai/api/v1/tone')

request = Net::HTTP::Post.new(uri)
request['Authorization'] = "Bearer #{api_key}"
request['Content-Type'] = 'application/json'
request.body = {
  text: 'Really stoked about this! Will it be ready by next week?'
}.to_json

response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
  http.request(request)
end

response.value
puts JSON.pretty_generate(JSON.parse(response.body))
Example response application/json
{
  "overall": [
    [0.9247, "curious", "🤓"],
    [0.0455, "excited", "😀"],
    [0.0057, "confused", "😕"]
  ],
  "results": [
    [[0.9937, "excited", "😀"]],
    [[0.5469, "confused", "😕"], [0.3993, "curious", "🤓"]]
  ],
  "sents": [
    "Really stoked about this!",
    "Will it be ready by next week?"
  ]
}

Probabilities are returned in descending order as probability, tone, and emoji tuples. Use sentence results when a message contains mixed tones.

About Ruby

Ruby is a programming language that shares design philosophies of Python and Perl around scripting, usability, and programming productivity but with a more object-oriented approach. Its popularity and adoption increased with Ruby on Rails, an MVC web framework written in Ruby.