packethost/packet

Packet Host官方PHP库

dev-master 2020-12-03 12:23 UTC

This package is not auto-updated.

Last update: 2024-09-28 18:47:56 UTC


README

Build Status

这个仓库是实验性的,这意味着它基于未经测试的想法或技术,尚未建立或最终确定,或者涉及一种全新且创新的风格!这意味着支持是尽力的(最多!)我们强烈建议您不要在生产环境中使用它。

####要求

  • PHP Curl扩展
  • PHP XSL扩展

使用Composer安装

 "require": {
        "packethost/packet": "dev-master"
    },

如何使用它

<?php

require __DIR__ . '/vendor/autoload.php';

//Create a configuration object
$config = new PacketHost\Client\Adapter\Configuration\DefaultConfiguration(
    'YOUR_API_KEY'
);

//Build the adapter and Api
$adapter = new PacketHost\Client\Adapter\GuzzleAdapter($config);
$api = new PacketHost\Client\PacketApi($adapter);

//Create options array with request params
$options = [
    'queryParams' => 'per_page=20'
];

// Fetching projects
$projects = $api->project()->getAll($params);
var_dump($projects);

// Fetching facilities
$facilities = $api->facility()->getAll();

// Fetching Operating Systems
$oses = $api->operatingSystem()->getAll();

// Fetching Plans
$plans = $api->plan()->getAll();

// Creating a device
$device = new \PacketHost\Client\Domain\Device();

$projectId = 'PROJECT_ID';

$device->hostname = 'sample';
$device->facility = $facilities[0]->code;
$device->plan = $plans[0]->slug;
$device->operatingSystem = $oses[0]->slug;

$device = $api->device()->create($projectId, $device);

var_dump($device);

运行测试

grunt ci