Skip to content

Latest commit

 

History

History

ruby

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

README.md

Code Detector API - Ruby Gem

Code Detector identifies the programming language of any submitted code snippet. It returns the canonical language name, readable title, and standard file extension for the detected code.

Installation

Add this line to your application's Gemfile:

gem 'apiverve_codedetector'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install apiverve_codedetector

Getting Started

Get your API key at APIVerve

Basic Usage

require 'apiverve_codedetector'

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

# Make a request
response = client.execute({ code: "a = 5
b = 6
c = 7

# calculate the semi-perimeter
s = (a + b + c) / 2

# calculate the area
area = (s*(s-a)*(s-b)*(s-c)) ** 0.5
print('The area of the triangle is %0.2f' %area)" })

# Print the response
puts response

Error Handling

begin
  response = client.execute({ code: "a = 5
b = 6
c = 7

# calculate the semi-perimeter
s = (a + b + c) / 2

# calculate the area
area = (s*(s-a)*(s-b)*(s-c)) ** 0.5
print('The area of the triangle is %0.2f' %area)" })
  puts response["data"]
rescue APIVerve::Codedetector::ValidationError => e
  puts "Validation error: #{e.errors.join(', ')}"
rescue APIVerve::Codedetector::APIError => e
  puts "API error: #{e.message}"
  puts "Status code: #{e.status_code}"
end

Debug Mode

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

Example Response

{
  "status": "ok",
  "error": null,
  "data": {
    "likelihood": 0.99,
    "family": "PYTHON",
    "current": "python",
    "readable": "Python Code",
    "extension": ".py",
    "paradigm": "multi-paradigm",
    "isCompiled": false
  }
}

Documentation

For more information, visit the API Documentation.

Support

License

This gem is available under the MIT License.