Skip to content

Instantly share code, notes, and snippets.

@subdigital
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save subdigital/a95329452bd08af8754d to your computer and use it in GitHub Desktop.
Save subdigital/a95329452bd08af8754d to your computer and use it in GitHub Desktop.
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