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.
Add this line to your application's Gemfile:
gem 'apiverve_codedetector'And then execute:
$ bundle installOr install it yourself as:
$ gem install apiverve_codedetectorGet your API key at APIVerve
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 responsebegin
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# Enable debug logging
client = APIVerve::Codedetector::Client.new(
api_key: "YOUR_API_KEY",
debug: true
){
"status": "ok",
"error": null,
"data": {
"likelihood": 0.99,
"family": "PYTHON",
"current": "python",
"readable": "Python Code",
"extension": ".py",
"paradigm": "multi-paradigm",
"isCompiled": false
}
}For more information, visit the API Documentation.
- Website: https://apiverve.com/marketplace/codedetector?utm_source=ruby&utm_medium=referral&utm_content=readme
- Email: hello@apiverve.com
This gem is available under the MIT License.