src/snapchat_agent.php
public function post($endpoint, $data, $params, $multipart = FALSE) {
		$ch = curl_init();

		$data['req_token'] = self::hash($params[0], $params[1]);
		$data['version'] = self::VERSION;

		if (!$multipart) {
			$data = http_build_query($data);
		}

		$options = self::$CURL_OPTIONS + array(
			CURLOPT_POST => TRUE,
			CURLOPT_POSTFIELDS => $data,
			CURLOPT_URL => self::URL . $endpoint,
			CURLOPT_HTTPHEADER => array(
				'Accept-Language: en-GB;q=1, en;q=0.9',
				'Accept-Locale: en'
			),
		);
		curl_setopt_array($ch, $options);

		$result = curl_exec($ch);

		// If cURL doesn't have a bundle of root certificates handy, we provide
		// ours (see http://curl.haxx.se/docs/sslcerts.html).
		if (curl_errno($ch) == 60) {
			curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . '/ca_bundle.crt');
			$result = curl_exec($ch);
		}

		// If the cURL request fails, return FALSE. Also check the status code
		// since the API generally won't return friendly errors.
		if ($result === FALSE || curl_getinfo($ch, CURLINFO_HTTP_CODE) != 200) {
			curl_close($ch);
			return FALSE;
		}

		curl_close($ch);

		if ($endpoint == '/blob') {
			return $result;
		}

		// Add support for foreign characters in the JSON response.
		$result = iconv('UTF-8', 'UTF-8//IGNORE', utf8_encode($result));

		$data = json_decode($result);
		return json_last_error() == JSON_ERROR_NONE ? $data : FALSE;
	}
public function post($endpoint, $data, $params, $multipart = FALSE) {
		$ch = curl_init();

		$data['req_token'] = self::hash($params[0], $params[1]);
		$data['version'] = self::VERSION;

		if (!$multipart) {
			$data = http_build_query($data);
		}

		$options = self::$CURL_OPTIONS + array(
			CURLOPT_POST => TRUE,
			CURLOPT_POSTFIELDS => $data,
			CURLOPT_URL => self::URL . $endpoint,
			CURLOPT_HTTPHEADER => array(
				'Accept-Language: en-GB;q=1, en;q=0.9',
				'Accept-Locale: en'
			),
		);
		curl_setopt_array($ch, $options);

		$result = curl_exec($ch);

		// If cURL doesn't have a bundle of root certificates handy, we provide
		// ours (see http://curl.haxx.se/docs/sslcerts.html).
		if (curl_errno($ch) == 60) {
			curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . '/ca_bundle.crt');
			$result = curl_exec($ch);
		}

		// If the cURL request fails, return FALSE. Also check the status code
		// since the API generally won't return friendly errors.
		if ($result === FALSE || curl_getinfo($ch, CURLINFO_HTTP_CODE) != 200) {
			curl_close($ch);
			return FALSE;
		}

		curl_close($ch);

		if ($endpoint == '/blob') {
			return $result;
		}

		// Add support for foreign characters in the JSON response.
		$result = iconv('UTF-8', 'UTF-8//IGNORE', utf8_encode($result));

		$data = json_decode($result);
		return json_last_error() == JSON_ERROR_NONE ? $data : FALSE;
	}
public function post ( $ endpoint , $ data , $ params , $ multipart = FALSE ) { $ ch = curl_init ( ) ; $ data [ 'req_token' ] = self :: hash ( $ params [ 0 ] , $ params [ 1 ] ) ; $ data [ 'version' ] = self :: VERSION ; if ( ! $ multipart ) { $ data = http_build_query ( $ data ) ; } $ options = self :: $ CURL_OPTIONS + array ( CURLOPT_POST => TRUE , CURLOPT_POSTFIELDS => $ data , CURLOPT_URL => self :: URL . $ endpoint , CURLOPT_HTTPHEADER => array ( 'Accept-Language: en-GB;q=1, en;q=0.9' , 'Accept-Locale: en' ) , ) ; curl_setopt_array ( $ ch , $ options ) ; $ result = curl_exec ( $ ch ) ; // If cURL doesn't have a bundle of root certificates handy, we provide // ours (see http://curl.haxx.se/docs/sslcerts.html). if ( curl_errno ( $ ch ) == 60 ) { curl_setopt ( $ ch , CURLOPT_CAINFO , dirname ( __FILE__ ) . '/ca_bundle.crt' ) ; $ result = curl_exec ( $ ch ) ; } // If the cURL request fails, return FALSE. Also check the status code // since the API generally won't return friendly errors. if ( $ result === FALSE || curl_getinfo ( $ ch , CURLINFO_HTTP_CODE ) != 200 ) { curl_close ( $ ch ) ; return FALSE ; } curl_close ( $ ch ) ; if ( $ endpoint == '/blob' ) { return $ result ; } // Add support for foreign characters in the JSON response. $ result = iconv ( 'UTF-8' , 'UTF-8//IGNORE' , utf8_encode ( $ result ) ) ; $ data = json_decode ( $ result ) ; return json_last_error ( ) == JSON_ERROR_NONE ? $ data : FALSE ; }
Performs a POST request. Used for pretty much everything.

@todo
Replace the blob endpoint check with a more robust check for
application/octet-stream.

@param string $endpoint
The address of the resource being requested (e.g. '/update_snaps' or
'/friend').
@param array $data
An dictionary of values to send to the API. A request token is added
automatically.
@param array $params
An array containing the parameters used to generate the request token.
@param bool $multipart
If TRUE, sends the request as multipart/form-data. Defaults to FALSE.

@return mixed
The data returned from the API (decoded if JSON). Returns FALSE if
the request failed.
Performs a POST request . Used for pretty much everything .