LoginSignup
2
0

More than 5 years have passed since last update.

PHPでQiita APIv2のラッパを作ってみた

Last updated at Posted at 2017-11-10

概要

Qiita APIv2のPHPラッパ。本当に元のAPIをラッピングしているだけ。
https://github.com/kuredev/qiita-php-wrapper

リファレンス

src/api.json に使える関数の一覧とQiita APIv2とのマッピングの情報がある
https://github.com/kuredev/qiita-php-wrapper/blob/master/src/api.json

動機

  • PHPの勉強
  • packagistに登録してみたかった

実装

以下のライブラリを使わせてもらった。
APIのラッピングの部分を、コードの外のファイルで管理できる。
あまり他に使われた実績が見当たらないけど、便利な気がする。
通信の部分はGuzzleが内部的に使われてる。

palanik/wrapi-php: Wrapper for calling Restful API https://github.com/palanik/wrapi-php

使い方

インストール

$ composer require kuredev/qiita-php-wrapper

使い方サンプル

<?php
require 'vendor/autoload.php';
$accessToken = "xxxxxxxxxxxxxx";

try{
    $qiita = new \Kuredev\Qiita($accessToken);

    //sample code
    var_dump($qiita->get->users());
    $arr = array();
    var_dump($qiita->put->userFollowing("kure", json_encode($arr)));
    var_dump($qiita->get->tagsItem("api"));
    $comment = array("body" => "testtest2");
    var_dump($qiita->post->comment("xxxxx", json_encode($comment)));
}catch(Exception $e){
    var_dump($e->getMessage());
}
2
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
2
0