Created
October 25, 2011 20:26
-
-
Save vc27/1314155 to your computer and use it in GitHub Desktop.
Build Ooyala Query URL
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
/** | |
* Build Query URL | |
**/ | |
function build_query_url( $params, $request_type ) { | |
// Add an expire time of 15 minutes unless otherwise specified | |
if ( is_array( $params ) AND !array_key_exists( 'expires', $params ) ) | |
$params['expires'] = time() + 900; | |
$string_to_sign = OOYALA_SECRET_CODE; | |
$url = "http://api.ooyala.com/partner/$request_type?pcode=" . OOYALA_PARTNER_CODE; | |
// set Delete values | |
if ( is_array( $params['delete'] ) ) | |
$params['delete'] = implode( '\0', $params['delete'] ); | |
$keys = array_keys( $params ); | |
sort( $keys ); | |
foreach ( $keys as $key ) { | |
$string_to_sign .= $key . '=' . $params[$key]; | |
$url .= '&' . rawurlencode( $key ) . '=' . rawurlencode( $params[$key] ); | |
} | |
$digest = hash( 'sha256', $string_to_sign, true ); | |
$signature = ereg_replace( '=+$', '', trim( base64_encode( $digest ) ) ); | |
$url .= '&signature=' . rawurlencode( $signature ); | |
$this->url = $url; | |
return $url; | |
} // end function build_query_url |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment