Permalink
Browse files

updated php lib

  • Loading branch information...
1 parent aa01a6b commit 75211f00def4df44bba408ab2489aff0978c5c55 @rkononov committed Mar 5, 2012
Showing with 13 additions and 30 deletions.
  1. +13 −30 lib/IronWorker.class.php
View
@@ -161,11 +161,10 @@ public static function createZip($base_dir, $files = array(), $destination, $ove
return false;
}
foreach($valid_files as $file) {
-echo "Adding_file ($base_dir.$file, $file)";
$zip->addFile($base_dir.$file, $file);
}
$zip->close();
- return $destination;
+ return file_exists($destination);
}else{
return false;
}
@@ -254,7 +253,6 @@ public function postCode($filename, $zipFilename, $name){
$this->addHeaderToArchive($zipFilename, $filename);
$this->setPostHeaders();
- $this->headers['Content-Length'] = filesize($zipFilename);
$ts = time();
$runtime_type = $this->runtimeFileType($filename);
$sendingData = array(
@@ -270,31 +268,12 @@ public function postCode($filename, $zipFilename, $name){
"options" => array(),
"access_key" => $name
);
-
- $sendingData = json_encode($sendingData);
- $eol = "\r\n";
- $data = '';
- $mime_boundary = md5(time());
- $data .= '--' . $mime_boundary . $eol;
- $data .= 'Content-Disposition: form-data; name="data"' . $eol . $eol;
- $data .= $sendingData . $eol;
- $data .= '--' . $mime_boundary . $eol;
- $data .= 'Content-Disposition: form-data; name="file"; filename=$zipFilename' . $eol;
- $data .= 'Content-Type: text/plain' . $eol;
- $data .= 'Content-Transfer-Encoding: binary' . $eol . $eol;
- $data .= $this->getFileContent($zipFilename) . $eol;
- $data .= "--" . $mime_boundary . "--" . $eol . $eol; // finish with two eol's!!
-
- $params = array('http' => array(
- 'method' => 'POST',
- 'header' => 'Content-Type: multipart/form-data; boundary=' . $mime_boundary . $eol,
- 'content' => $data
- ));
- $ctx = stream_context_create($params);
- $destination = "{$this->url}projects/{$this->project_id}/codes?oauth={$this->token}";
- $this->debug('destination', $destination);
-
- $response = file_get_contents($destination, false, $ctx);
+ $url = "projects/{$this->project_id}/codes";
+ $post = array(
+ "data" => json_encode($sendingData),
+ "file"=>"@".$zipFilename,
+ );
+ $response = $this->apiCall(self::POST, $url, array(), $post);
return self::json_decode($response);
}
@@ -540,7 +519,7 @@ private function runtimeFileType($name) {
}
}
- private function apiCall($type, $url, $params = array()){
+ private function apiCall($type, $url, $params = array(), $raw_post_data = null){
$url = "{$this->url}$url";
$s = curl_init();
@@ -558,7 +537,11 @@ private function apiCall($type, $url, $params = array()){
$this->debug('apiCall url', $url);
curl_setopt($s, CURLOPT_URL, $url);
curl_setopt($s, CURLOPT_POST, true);
- curl_setopt($s, CURLOPT_POSTFIELDS, json_encode($params));
+ if ($raw_post_data){
+ curl_setopt($s, CURLOPT_POSTFIELDS, $raw_post_data);
+ }else{
+ curl_setopt($s, CURLOPT_POSTFIELDS, json_encode($params));
+ }
break;
case self::GET:
$fullUrl = $url . '?' . http_build_query($params);

0 comments on commit 75211f0

Please sign in to comment.