itul/bugherdapi

Laravel package for using the bugherd API

v1.0.0 2025-06-24 07:32 UTC

This package is auto-updated.

Last update: 2025-06-24 07:37:02 UTC


README

Latest Version on Packagist Total Downloads

The BugherdAPI Laravel package provides a convenient interface for interacting with the Bugherd API. It includes methods for managing projects, users, tasks, comments, and their associations, while handling API rate limits and caching.

Table of Contents

Getting Started

Requirements

Before using this package, ensure your system meets the following requirements:

  • PHP: Version 8.0 or higher.
  • Laravel: Version 9.x or higher.
  • Bugherd API Key: Obtain an API key from your Bugherd account.

Installation

Install the package via Composer:

composer require itul/bugherdapi

Environment Variables

Set the following environment variables in your .env file:

BUGHERD_API_KEY=your_api_key
BUGHERD_BASE_URL=https://www.bugherd.com/api_v2/

Caching

The package uses Laravel's caching mechanism to store project and user data for improved performance. Cached data is refreshed automatically after 28000 seconds.

Class Overview

BugherdAPI Class

Description:
The BugherdAPI class serves as the main entry point for interacting with the Bugherd API. It provides methods for sending API requests (GET, POST, PUT, DELETE) and includes caching and rate limit management.

Properties

Property NameTypeDescription
$projectCachestaticStores cached project data.
$userCachestaticStores cached user data.
$requestsstaticTracks API requests to manage rate limits.

Methods

Method NameParametersReturn TypeDescription
sendRequest$type, $endpoint, $dataobjectSends a request to the Bugherd API with rate limit management.
sendGet$endpoint, $dataobjectSends a GET request to the Bugherd API.
sendPost$endpoint, $dataobjectSends a POST request to the Bugherd API.
sendPut$endpoint, $dataobjectSends a PUT request to the Bugherd API.
sendDelete$endpoint, $dataobjectSends a DELETE request to the Bugherd API.
getProjectsNoneobjectRetrieves and caches Bugherd projects.
getUserProjectsNoneobjectRetrieves projects with their associated members.
getUsersNoneobjectRetrieves and caches Bugherd users.

BugherdModel Class

Description:
The BugherdModel class serves as a base model for interacting with the Bugherd API. It provides methods to handle relationships, API URLs, and model names, mimicking Laravel's Eloquent ORM functionality.

Properties

Property NameTypeDescription
$apiUrlstringThe API URL for the model.
$modelNamestringThe name of the model.
$relationsarrayAn array of model relationships.
$instancestaticA static instance of the model.

Methods

Method NameParametersReturn TypeDescription
__construct$datavoidInitializes the model with the provided data.
getApiUrlNonestringRetrieves the API URL for the model.
setApiUrl$urlselfSets the API URL for the model.
hasMany$model, ...$argsCollectionMimics the Laravel hasMany relationship to retrieve related models.
belongsTo$model, $idBugherdModel|nullMimics the Laravel belongsTo relationship to retrieve a related model.
getModelNameNonestringRetrieves the model name.
generateApiUrlNonestringGenerates the API URL for the model.
generateModelName$pluralstringGenerates the model name, singular or plural based on the parameter.
list...$argsCollectionLists all instances of the model with optional filters and pagination.
detailsNoneBugherdModel|nullRetrieves the details of the model instance.
find$idBugherdModelFinds a model instance by its ID.

BugherdUser Class

Description:
The BugherdUser class represents a user in the Bugherd API. It provides methods to retrieve the projects the user is a member of and tasks assigned to the user across all projects.

Properties

Property NameTypeDescription
$apiUrlstringThe API URL for the users.
$modelNamestringThe name of the model, which is user.

Methods

Method NameParametersReturn TypeDescription
projectsNoneCollectionRetrieves the projects the user is a member of.
tasks...$argsCollectionRetrieves all tasks assigned to the user across all projects.

BugherdProject Class

Description:
The BugherdProject class represents a project in the Bugherd API. It provides methods to retrieve tasks associated with the project.

Properties

Property NameTypeDescription
$apiUrlstringThe API URL for the project.
$modelNamestringThe name of the project model.

Methods

Method NameParametersReturn TypeDescription
tasks...$argsCollectionRetrieves all tasks associated with the project, enriched with the project name.

BugherdProjectTask Class

Description:
The BugherdProjectTask class represents a task within a Bugherd project. It provides methods to archive the task, retrieve the associated project, and get comments for the task.

Properties

Property NameTypeDescription
$apiUrlstringThe API URL for the tasks in a project.
$modelNamestringThe name of the model, which is task.

Methods

Method NameParametersReturn TypeDescription
archiveNoneobjectArchives the task by changing its status to closed.
projectNoneBugherdProjectRetrieves the project associated with this task.
commentsNoneCollectionRetrieves all comments associated with this task.

BugherdProjectTaskComment Class

Description:
The BugherdProjectTaskComment class represents a comment on a task within a Bugherd project. It provides methods to retrieve the task associated with the comment.

Properties

Property NameTypeDescription
$apiUrlstringThe API URL for task comments.
$modelNamestringThe name of the model, which is comment.

Methods

Method NameParametersReturn TypeDescription
taskNoneBugherdProjectTaskRetrieves the task associated with this comment.

Usage

Sending API Requests

The BugherdAPI class provides methods for sending requests to the Bugherd API:

use Itul\BugherdAPI\BugherdAPI;

// Send a GET request
$response = BugherdAPI::sendGet('projects', ['status' => 'active']);

// Send a POST request
$response = BugherdAPI::sendPost('projects', ['name' => 'New Project']);

// Send a PUT request
$response = BugherdAPI::sendPut('projects/1', ['name' => 'Updated Project']);

// Send a DELETE request
$response = BugherdAPI::sendDelete('projects/1');

Managing Projects

Retrieve tasks and users for projects:

use Itul\BugherdAPI\BugherdAPI;
use Itul\BugherdAPI\BugherdProject;

// Get the project by ID
$project = BugherdProject::find($id);

// Get the tasks
$tasks = $project->tasks();

// Get the users for a specific project
$users = $project->members;

// Get all projects
$projects = BugherdAPI::getProjects();

// Get projects with members
$userProjects = BugherdAPI::getUserProjects();

Managing Users

Retrieve and cache Bugherd users:

use Itul\BugherdAPI\BugherdAPI;

// Get all users
$users = BugherdAPI::getUsers();

Managing Tasks

Archive a task, retrieve its associated project, or get its comments:

use Itul\BugherdAPI\BugherdProjectTask;

// Archive a task
$task = BugherdProjectTask::find($id);
$response = $task->archive();

// Get the associated project
$project = $task->project();

// Get comments for the task
$comments = $task->comments();

Managing Task Comments

Retrieve the task associated with a specific comment:

use Itul\BugherdAPI\BugherdProjectTaskComment;

$comment = BugherdProjectTaskComment::find($id);
$task = $comment->task();

License

This package is open-source and licensed under the MIT License.

Additional Resources