API Examples

Ruby DNS API code sample

Ruby Example

The following example code can be used as a framework to build an interface to the Conexim API in Ruby.

require 'net/https' require 'openssl' require 'base64' require 'json' require 'time' secretkey = '<insert-your-secret-key>' keyid = '<insert-key-id>' server = URI('https://api.conexim.net') action = '/api/dns/v1/domains' verb = 'GET' params = Hash[] queryString = '' paramSep = '' params.sort.map do |key, value| queryString << paramSep << key << "=" << value if paramSep == '' paramSep = '&' end end utimeGMT = Time.now.getutc.to_i() sigString = "#{keyid}\n#{utimeGMT}\n#{verb}\n#{action}\n#{queryString}" digest = OpenSSL::Digest::Digest.new("sha256") hmac = OpenSSL::HMAC.digest(digest, secretkey, sigString) sig = Base64.strict_encode64(hmac) Net::HTTP.start(server.host, server.port, :use_ssl => server.scheme == 'https') do |http| case verb when 'GET' req = Net::HTTP::Get.new(action) when 'POST' req = Net::HTTP::Post.new(action) when 'PUT' req = Net::HTTP::Put.new(action) when 'DELETE' req = Net::HTTP::Delete.new(action) end req.body = params.to_json req['Authorization'] = "CONEXIM #{keyid}:#{sig}" req['Conexim-Time'] = utimeGMT.to_s() response = http.request(req) puts JSON.pretty_generate(JSON.parse(response.body)) end

Python example Retrieving DNS Records from the API