Create an API key on Tether
Knowledge Base
Create an API key on Tether
How to create an API key on Tether
How to create Authenticated Requests on Tether
require 'time'
require 'httparty'
@base_uri = 'https://app.tether.to/api/v1'
@api_key = 'YOUR-KEY'
@api_secret = 'YOUR-SECRET'
def b64_encode(string)
Base64.strict_encode64(string)
end
def md5_base64digest(string)
Digest::MD5.base64digest(string)
end
def hmac_signature(canonical_string)
digest = OpenSSL::Digest.new('sha1')
b64_encode(OpenSSL::HMAC.digest(digest, @api_secret, canonical_string))
end
def do_request(verb, uri, options={})
path = @base_uri + uri
if [:get, :delete].include? verb
request_options = {}
path = "#{@base_uri}#{uri}?#{URI.encode_www_form(options)}" unless options.empty?
content_md5 = md5_base64digest('')
else
body = options.to_json
request_options = { body: body }
content_md5 = md5_base64digest(body)
end
# Generate valid headers and signature
headers = {
'Content-MD5' => content_md5,
'Date' => Time.now.utc.httpdate,
'Content-Type' => 'application/json',
}
canonical_string = [ verb.upcase,
headers['Content-Type'],
headers['Content-MD5'],
URI(@base_uri + uri).path,
headers['Date']
].join(',')
signature = hmac_signature(canonical_string)
headers['Authorization'] = "APIAuth #{@api_key}:#{signature}"
request_options[:headers] = headers
# forward to HTTParty
response = HTTParty.send(verb, path, request_options)
parsed_response = JSON.parse(response.body)
parsed_response
end
def get(path, options={})
do_request :get, path, options
end
## Define the functions to perform the authenticated calls
# returns current account balances
def balances
get '/balances.json'
end
# returns list of most recent transactions
def transactions
get '/transactions.json'
end
# returns specific page of transactions
def transactionPage(page)
get "/transactions/page/#{page}"
end
# returns details of a specific transaction
def get_transaction(id)
get "/transactions/#{id}.json"
end
The Future of Money
Sign UpTether token
Tether supports and empowers growing ventures and innovation as a digital token built on multiple blockchains.