-
-
Save mssyogi/e5a48fbe2e7b154aed9d to your computer and use it in GitHub Desktop.
Phonegap Build Developer API (php curl)
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
<?php | |
class PGB_API { | |
// A single instance of this class. | |
public static $instance = null; | |
public static $auth_token = ''; | |
/** | |
* Creates or returns an instance of this class. | |
* @since 1.0.0 | |
* @return A single instance of this class. | |
*/ | |
public static function run() { | |
if ( self::$instance === null ) | |
self::$instance = new self(); | |
return self::$instance; | |
} | |
public function pgapi_setup() { | |
self::$auth_token = 'XXXXXXX'; | |
$this->ch = curl_init(); | |
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, false); | |
} | |
public function uploadApp($filepath) { | |
self::pgapi_setup(); | |
$url = "https://build.phonegap.com/api/v1/apps?create_method=file"; | |
curl_setopt($this->ch, CURLOPT_URL, $url); | |
curl_setopt($this->ch, CURLOPT_POST, 1); | |
$file = $filepath; | |
$title = 'My App'; | |
$createMethod = 'file'; | |
$pg_post = array( | |
"data" => json_encode( array( 'create_method' => $createMethod, 'title' => $title, "share" => true ) ), | |
"file" => "@" . $file, | |
'auth_token' => self::$auth_token | |
); | |
curl_setopt($this->ch, CURLOPT_POSTFIELDS, $pg_post); | |
$output = curl_exec($this->ch); | |
$obj = json_decode($output); | |
if (is_object($obj) && isset($obj->id)) { | |
return $obj->id; | |
} else { | |
print_r( 'Phonegap Build upload error.' ); | |
} | |
} | |
} | |
PGB_API::run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment