shevabam/jsonbin-sdk-php
Composer 安装命令:
composer require shevabam/jsonbin-sdk-php
包简介
PHP SDK for JsonBin.io API
README 文档
README
A modern PHP SDK for the JsonBin.io API. This SDK uses PHP 8.2+ and follows development best practices to provide you with a clean and fluent interface to the JsonBin.io API.
Table of Contents
- Requirements
- Installation
- Usage
- Error Handling
- Configuration Options
Requirements
- PHP 8.2 or higher
- Composer
Installation
composer require shevabam/jsonbin-sdk
Usage
Initialization
<?php require 'vendor/autoload.php'; use JsonBinSDK\JsonBinClient; // Initialize the client with your Master Key $client = new JsonBinClient('YOUR_API_KEY');
Working with Bins
Create a bin
// Create a simple bin $data = ['name' => 'John Doe', 'age' => 30]; $result = $client->bins()->create($data); // Create a bin with options $result = $client->bins()->create($data, [ 'private' => true, 'name' => 'My test bin', 'collectionId' => 'COLLECTION_ID' ]);
Read a bin
$binId = 'BIN_ID'; $bin = $client->bins()->read($binId);
Update a bin
$binId = 'BIN_ID'; $updatedData = ['name' => 'Jane Doe', 'age' => 31]; $result = $client->bins()->update($binId, $updatedData);
Delete a bin
$binId = 'BIN_ID'; $result = $client->bins()->delete($binId);
Working with Collections
Create a collection
$result = $client->collections()->create('My Collection');
Read a collection
$collectionId = 'COLLECTION_ID'; $collection = $client->collections()->read($collectionId);
Update a collection
$collectionId = 'COLLECTION_ID'; $result = $client->collections()->update($collectionId, 'New Collection Name');
Delete a collection
$collectionId = 'COLLECTION_ID'; $result = $client->collections()->delete($collectionId);
List bins in a collection
$collectionId = 'COLLECTION_ID'; $bins = $client->collections()->listBins($collectionId);
List bins without collection (uncategorized)
$bins = $client->collections()->listUncategorizedBins();
Add a bin to a collection
$collectionId = 'COLLECTION_ID'; $binId = 'BIN_ID'; $result = $client->collections()->addBin($collectionId, $binId);
Remove a bin from a collection
$collectionId = 'COLLECTION_ID'; $binId = 'BIN_ID'; $result = $client->collections()->removeBin($collectionId, $binId);
Working with Access Keys
Create an access key
$result = $client->accessKey()->create('My New Access Key 2', [ 'read' => true, 'update' => true, 'delete' => true, 'create' => true, ]);
List access keys
$bins = $client->accessKey()->list();
Delete an access key
$accessKey = 'abc123'; $bins = $client->accessKey()->delete($accessKey);
Working with Logs
List logs
$bins = $client->log()->list();
Error Handling
The SDK throws JsonBinSDK\Exception\ApiException when an API error occurs:
use JsonBinSDK\Exception\ApiException; try { $bin = $client->bins()->read('non_existent_id'); } catch (ApiException $e) { echo 'API Error: ' . $e->getMessage(); }
Configuration Options
You can customize the SDK behavior when creating the client:
$client = new JsonBinClient('YOUR_API_KEY'); $client->getConfig()->setTimeout(60);
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-only
- 更新时间: 2025-02-26