Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Ruby connect to TicketMatic 3 API JSON
require 'openssl'
require 'Base64'
require 'net/http'
def connect(url)
# I'm calling this method from other files, url is what you want to get. For example '/events'
# Put your keys and customer name in 3 config files or change the code to get them from environment variables
access_key ='access_key.txt', &:readline).strip
secret_key ='secret_key.txt', &:readline).strip
name ='customer.txt', &:readline).strip
# Here is wat the example request from TicketMatic looks like
# Authorization: TM-HMAC-SHA256 key=242dda885ec6024f934a40c0 ts=2014-09-23T17:23:00 sign=c27dc92415cb20dca85fec44f31b60b522bc3c9e422cb24a35dfc8538a1ab570
time ='%Y-%m-%dT%H:%M:%S')
uri = URI("{name}" + url)
hmac = OpenSSL::HMAC.hexdigest('sha256'), secret_key, access_key + name + time)
req =
req['Authorization'] = "TM-HMAC-SHA256 key=#{access_key} ts=#{time} sign=#{hmac}"
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http| http.request(req) }
# This returns the result, you have will probably have to parse it with JSON.parse
return res.body
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment