kryvestudio/github-api

PHP wrapper for GitHub REST API by Kryve Studio

Maintainers

Package info

github.com/kryvestudio/github-api

pkg:composer/kryvestudio/github-api

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

dev-master 2026-05-17 14:23 UTC

This package is auto-updated.

Last update: 2026-05-17 14:23:25 UTC


README

PHP wrapper untuk GitHub REST API. Simple, dependency-free, built dengan cURL.

πŸ“– Full Documentation β€” Lengkap dengan authentication methods, API reference, error handling, dan testing guide.

Quick Start

Instalasi

composer require kryvestudio/github-api

Requirements: PHP 8.3+, ext-curl, ext-json

Basic Usage

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

use Kryve\GithubApi\Client;
use Kryve\GithubApi\Api\User;
use Kryve\GithubApi\Api\Repos;

// Setup client (dengan token atau tanpa token untuk public endpoints)
$client = new Client(getenv('GITHUB_TOKEN') ?: null);

// Fetch user profile
$user = new User($client);
$profile = $user->get('kryvestudio');
echo "Bio: {$profile['bio']}\n";

// List repositories
$repos = new Repos($client);
$list = $repos->forUser('kryvestudio', ['per_page' => 5]);
foreach ($list as $repo) {
    echo "- {$repo['name']} ⭐ {$repo['stargazers_count']}\n";
}

Token Setup

  1. Generate token di github.com/settings/tokens
  2. Set environment variable:
    export GITHUB_TOKEN=ghp_xxxxxxxxxxxxxxxxxxxx

Atau pass langsung ke constructor:

$client = new Client('ghp_xxxxxxxxxxxxxxxxxxxx');

API yang Tersedia

Class Method Endpoint
Client get($endpoint, $params) Generic GET request
User get($username) GET /users/:username
Repos forUser($username, $params) GET /users/:username/repos
forOrg($org, $params) GET /orgs/:org/repos
Issues list($owner, $repo, $params) GET /repos/:owner/:repo/issues

Query parameters opsionalβ€”cek docs untuk detail.

Error Handling

Semua error (4xx, 5xx, cURL errors) dilempar sebagai ApiException:

use Kryve\GithubApi\Exception\ApiException;

try {
    $user->get('nonexistent_user');
} catch (ApiException $e) {
    echo $e->getMessage();        // "Not Found"
    echo $e->getCode();           // 404
    print_r($e->getResponseBody()); // Full GitHub error response
}

Use Cases

Portfolio Integration

// Auto-update stats di landing page
$profile = $user->get('your-username');
echo "Total repos: {$profile['public_repos']}";
echo "Followers: {$profile['followers']}";

Repo Showcase

// List project highlights dengan metadata real-time
$repos = $repos->forUser('your-username', [
    'sort' => 'updated',
    'per_page' => 10
]);
// Display dengan stars, forks, language

Issue Tracker Dashboard

// Monitor open issues across projects
$issues = new Issues($client);
$openIssues = $issues->list('owner', 'repo', ['state' => 'open']);

Documentation

πŸ“š Baca dokumentasi lengkap untuk:

  • Authentication methods (Bearer Token, Basic Auth, No Auth)
  • Complete API reference dengan semua parameters
  • Advanced error handling patterns
  • Testing guide dengan PHPUnit
  • Real-world HTML examples (profile card, repo list, issue tracker)

Testing

composer test

Atau langsung:

vendor/bin/phpunit

Project Structure

src/
β”œβ”€β”€ Client.php           # HTTP client core (cURL wrapper)
β”œβ”€β”€ Api/
β”‚   β”œβ”€β”€ User.php        # User endpoints
β”‚   β”œβ”€β”€ Repos.php       # Repository endpoints
β”‚   └── Issues.php      # Issues endpoints
└── Exception/
    └── ApiException.php

License

MIT License - Kryve Studio

Made with β˜• by Kryve Studio

Links