cayetanosoriano/kcy
PSR-0 PHP library for the Karmacracy API (karmacracy-php). Provides client-side access to Karmacracy services; currently marked as “working” but with minimal documentation.
Installation Add the package via Composer:
composer require cayetanosoriano/kcy
Ensure autoload is regenerated:
composer dump-autoload
First Use Case Import the core class and initialize a client:
use CayetanoSoriano\Kcy\KarmacracyClient;
$client = new KarmacracyClient('your_api_key_here');
Verify connectivity with a simple request:
$response = $client->getKarmaPoints('user@example.com');
Where to Look First
src/KarmacracyClient.php: Core class for API interactions.README.md: Basic usage examples (if expanded).tests/: Test cases for expected behavior (if available).Authentication Pass API keys via constructor or set dynamically:
$client = new KarmacracyClient();
$client->setApiKey('your_key_here');
CRUD Operations Follow PSR-0 conventions for method naming:
// Create
$client->createKarmaEntry($userId, $points);
// Read
$client->getKarmaPoints($userId);
// Update
$client->updateKarmaPoints($userId, $increment);
// Delete (if supported)
$client->deleteKarmaEntry($userId);
Error Handling Implement a wrapper for robust error handling:
try {
$response = $client->getKarmaPoints($userId);
} catch (\CayetanoSoriano\Kcy\Exceptions\KarmaException $e) {
Log::error("Karma API Error: " . $e->getMessage());
}
Integration with Laravel
Bind the client to the container in config/app.php:
'bindings' => [
CayetanoSoriano\Kcy\KarmacracyClient::class => function ($app) {
return new KarmacracyClient(config('services.kcy.api_key'));
},
];
Use dependency injection in controllers:
public function __construct(private KarmacracyClient $kcyClient) {}
Batch Processing If the API supports bulk operations, leverage collections:
$userIds = [1, 2, 3];
$client->batchUpdateKarmaPoints($userIds, 10); // Hypothetical method
API Key Management
.env and config/services.php:
KCY_API_KEY=your_key_here
// config/services.php
'kcy' => [
'api_key' => env('KCY_API_KEY'),
],
Rate Limiting
use Symfony\Component\RateLimiter\RateLimiter;
$limiter = new RateLimiter(10, 'minute');
if (!$limiter->isAllowed()) {
sleep($limiter->getWaitTime());
}
PSR-0 Compliance
composer.json autoload rules:
"autoload": {
"psr-0": {
"CayetanoSoriano\\Kcy\\": "src/"
}
}
Debugging
$client->setDebug(true); // If supported
// Or manually log responses:
Log::debug('Karma API Response:', $response->getBody());
Extension Points
class CustomKarmacracyClient extends KarmacracyClient {
public function getKarmaPoints($userId) {
$response = parent::getKarmaPoints($userId);
return $this->transformResponse($response);
}
}
Testing
$mock = Mockery::mock(KarmacracyClient::class);
$mock->shouldReceive('getKarmaPoints')->andReturn(['points' => 100]);
Documentation Gaps
var_dump() or dd() on responses to infer structure:
dd($client->getKarmaPoints('test@example.com'));
How can I help you explore Laravel packages today?