-
-
Save subdigital/a95329452bd08af8754d to your computer and use it in GitHub Desktop.
Sample DeliRadio API Request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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