Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Sample DeliRadio API Request
# get these from deliradio.com
key = "..."
secret = "..."
# split apart URL and params
url = "https://deliradio.com/api/v3/genres?key=#{key}"
base_url, params = url.split("?")
# alphabetize params
sorted_params = params.split("&").sort.join("&")
# concatenate input string
method = "GET"
input_string = [method, base_url, sorted_params].join("&")
input_string = CGI.escape(input_string)
data_string = OpenSSL::HMAC.digest('sha1', secret, input_string)
auth_key = Base64.encode64(data_string)
authorization_code = CGI.escape(auth_key.gsub("\n",""))
# send request
uri = URI.parse(url)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.set_debug_output($stdout)
request = Net::HTTP::Get.new(uri.request_uri)
request['Authorization'] = authorization_code
response = http.request(request)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment