Skip to content

Instantly share code, notes, and snippets.

@AikedeJongste
Last active March 21, 2023 14:18
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save AikedeJongste/38e7e5059afd2352a7cc66fb6b691247 to your computer and use it in GitHub Desktop.
Save AikedeJongste/38e7e5059afd2352a7cc66fb6b691247 to your computer and use it in GitHub Desktop.
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 = File.open('access_key.txt', &:readline).strip
secret_key = File.open('secret_key.txt', &:readline).strip
name = File.open('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 = Time.now.utc.strftime('%Y-%m-%dT%H:%M:%S')
uri = URI("https://apps.ticketmatic.com/api/1/#{name}" + url)
hmac = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), secret_key, access_key + name + time)
req = Net::HTTP::Get.new(uri)
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
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment