Skip to content

Instantly share code, notes, and snippets.

@scottopolis
Last active August 17, 2019 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save scottopolis/0c853e963e390e2f1db8 to your computer and use it in GitHub Desktop.
Save scottopolis/0c853e963e390e2f1db8 to your computer and use it in GitHub Desktop.
Phonegap Build Developer API (php curl)
<?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();
@Blade83x2
Copy link

How do you get the status from the Build proccess ?

@scottopolis
Copy link
Author

There's a status endpoint you can ping, in our case we hit it every few seconds until it returns as finished.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment