mirror of
https://gh.llkk.cc/https://github.com/CaptainCore/captaincore-manager.git
synced 2025-08-18 05:21:07 +08:00
📦 NEW: Spaceship API wrapper
This commit is contained in:
parent
12fc2590c2
commit
5657210ec5
4 changed files with 81 additions and 0 deletions
19
app/Providers/Spaceship.php
Normal file
19
app/Providers/Spaceship.php
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace CaptainCore\Providers;
|
||||
|
||||
class Spaceship {
|
||||
|
||||
public static function credentials( $record = "" ) {
|
||||
$credentials = ( new \CaptainCore\Provider( "spaceship" ) )->credentials();
|
||||
if ( $record == "" ) {
|
||||
return $credentials;
|
||||
}
|
||||
foreach( $credentials as $credential ) {
|
||||
if ( $credential->name == $record ) {
|
||||
return $credential->value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
56
app/Remote/Spaceship.php
Normal file
56
app/Remote/Spaceship.php
Normal file
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
/**
|
||||
* Spaceship API WordPress Wrapper
|
||||
*
|
||||
* @author Austin Ginder
|
||||
*/
|
||||
|
||||
namespace CaptainCore\Remote;
|
||||
|
||||
class Spaceship {
|
||||
|
||||
private static $base_url = 'https://spaceship.dev/api/v1';
|
||||
|
||||
public static function get( $endpoint, $parameters = [] ) {
|
||||
$args = [
|
||||
'timeout' => 120,
|
||||
'headers' => [
|
||||
'X-Api-Secret' => \CaptainCore\Providers\Spaceship::credentials("api_secret"),
|
||||
'X-Api-Key' => \CaptainCore\Providers\Spaceship::credentials("api_key"),
|
||||
],
|
||||
];
|
||||
$url = self::$base_url . "/$endpoint";
|
||||
if ( ! empty( $parameters ) ) {
|
||||
$url .= "?" . http_build_query( $parameters );
|
||||
}
|
||||
$remote = wp_remote_get( $url, $args );
|
||||
|
||||
if ( is_wp_error( $remote ) ) {
|
||||
return $remote->get_error_message();
|
||||
} else {
|
||||
return json_decode( $remote['body'] );
|
||||
}
|
||||
}
|
||||
|
||||
public static function put( $endpoint, $parameters = [] ) {
|
||||
$args = [
|
||||
'timeout' => 120,
|
||||
'headers' => [
|
||||
'Content-type' => 'application/json',
|
||||
'X-Api-Secret' => \CaptainCore\Providers\Spaceship::credentials("api_secret"),
|
||||
'X-Api-Key' => \CaptainCore\Providers\Spaceship::credentials("api_key"),
|
||||
],
|
||||
'body' => json_encode( $parameters ),
|
||||
'method' => 'PUT',
|
||||
];
|
||||
$url = self::$base_url . "/$endpoint";
|
||||
$remote = wp_remote_post( $url, $args );
|
||||
|
||||
if ( is_wp_error( $remote ) ) {
|
||||
return $remote->get_error_message();
|
||||
} else {
|
||||
return json_decode( $remote['body'] );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -7367,6 +7367,10 @@ new Vue({
|
|||
"text": "Domain - Hover.com",
|
||||
"value": "hoverdotcom"
|
||||
},
|
||||
{
|
||||
"text": "Domain - Spaceship",
|
||||
"value": "spaceship"
|
||||
},
|
||||
{
|
||||
"text": "Email - Mailgun",
|
||||
"value": "mailgun"
|
||||
|
|
2
vendor/composer/autoload_static.php
vendored
2
vendor/composer/autoload_static.php
vendored
|
@ -247,6 +247,7 @@ class ComposerStaticInit9f7509cc1c55bc410ccf6f05510f2050
|
|||
'CaptainCore\\Providers\\Kinsta' => __DIR__ . '/../..' . '/app/Providers/Kinsta.php',
|
||||
'CaptainCore\\Providers\\Mailgun' => __DIR__ . '/../..' . '/app/Providers/Mailgun.php',
|
||||
'CaptainCore\\Providers\\Rocketdotnet' => __DIR__ . '/../..' . '/app/Providers/Rocketdotnet.php',
|
||||
'CaptainCore\\Providers\\Spaceship' => __DIR__ . '/../..' . '/app/Providers/Spaceship.php',
|
||||
'CaptainCore\\Quicksave' => __DIR__ . '/../..' . '/app/Quicksave.php',
|
||||
'CaptainCore\\Recipes' => __DIR__ . '/../..' . '/app/Recipes.php',
|
||||
'CaptainCore\\Remote\\Constellix' => __DIR__ . '/../..' . '/app/Remote/Constellix.php',
|
||||
|
@ -254,6 +255,7 @@ class ComposerStaticInit9f7509cc1c55bc410ccf6f05510f2050
|
|||
'CaptainCore\\Remote\\Kinsta' => __DIR__ . '/../..' . '/app/Remote/Kinsta.php',
|
||||
'CaptainCore\\Remote\\Mailgun' => __DIR__ . '/../..' . '/app/Remote/Mailgun.php',
|
||||
'CaptainCore\\Remote\\Missive' => __DIR__ . '/../..' . '/app/Remote/Missive.php',
|
||||
'CaptainCore\\Remote\\Spaceship' => __DIR__ . '/../..' . '/app/Remote/Spaceship.php',
|
||||
'CaptainCore\\Run' => __DIR__ . '/../..' . '/app/Run.php',
|
||||
'CaptainCore\\Site' => __DIR__ . '/../..' . '/app/Site.php',
|
||||
'CaptainCore\\Sites' => __DIR__ . '/../..' . '/app/Sites.php',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue