LoginSignup
0
0

More than 5 years have passed since last update.

PHPでCloud Automator APIのラッパを作ってみた

Last updated at Posted at 2017-12-02

※本記事は、Cloud Automator Advent Calendar 2017 の12/3分の記事です。

概要

PHPでCloud Automator APIのラッパを作ってみました。趣味で。
このライブラリを用いることで、PHPでCloud Automator APIを簡易に扱えると思います。
https://github.com/kuredev/cloudutomator-php

Cloud Automator APIとは

Cloud AutomatorのオペレーションするためのREST APIです。
ジョブの大量投下や一覧の取得等に便利です。
本家のドキュメントは以下になります。
https://cloudautomator.com/api_docs/v1/api.html

使い方

インストール

composerでインストールしてください。

$ composer install kuredev/cloudautomator-php

概要

「Kuredev\CA」オブジェクトを初期化/作成すると、Cloud AutomatorAPIをラップしたプロパティ+メソッドを持つオブジェクトが作成されます(それらの要素を持った階層的なstdClassが作成される)。
下記のサンプルを見ていただけるとイメージが付くと思います。

サンプル

<?php
require_once "vendor/autoload.php";
$ca = new \Kuredev\CA("[CloudAutomatorAccessKey]");

try{
    var_dump($ca->get->aws_accounts());
    var_dump($ca->get->aws_account(xxx));
    $accountArr = array(
        "name" => "xxx",
        "account_number" => "12345678910",
        "access_key_id" => "xxxxx",
        "secret_access_key" => "xxxxxxxxxx"
    );
    var_dump($ca->post->aws_accounts(json_encode($accountArr)));
}catch(Exception $e){
    var_dump($e);
}

リファレンス

要件

  • "php": ">=7.0.0"
  • "palanik/wrapi": "*"

※ライブラリ(wrapi)はcomposerで勝手にインストールされる。今回のラップの仕組みはこのライブラリにお世話になってる。通信の部分は内部的にGuzzleを用いているもよう。

参考

PHPでQiita APIv2のラッパを作ってみた Qiita
https://qiita.com/kure/items/b8b1b3e6d71910ff0b06

終わりに

Cloud Automator APIを楽しく操作する一助になれば幸いです。
明日以降の記事も楽しみです。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0