tschucki/laravel-pr0gramm-api

1.0.5 2024-11-04 20:18 UTC

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This package provides a Laravel wrapper for the Pr0gramm API by Pr0gramm. This package is not affiliated with Pr0gramm. I created it for my own use on other projects.

I will try to keep this package up to date with the API and imporve it over time. If you find any bugs or have any suggestions, feel free to open an issue or a PR.

Installation

You can install the package via composer:

composer require tschucki/laravel-pr0gramm-api

You don't need to publish any config files. The package will work out of the box. You just have to log in to Pr0gramm, to get some user related request. (For example conversations or votings)

But if you want to provide your pr0gramm cookie, you can add this to your services.php.

    'pr0gramm' => [
        'cookie' => env('PR0GRAMM_COOKIE'),
    ]

Usage

It is recommended to use the facade Pr0grammApi to access the API.

Pr0grammApi::User()->me();

You can access all endpoints of the API:

  • User
  • Post
  • Tag
  • Comment
  • Contact
  • Inbox
  • Profile

Login to your account

To log in to your account, you can use the login method. It will create a new Session and stores the cookie for you. Afterwards you don't need to provide the cookie on every request. When using a non-bot account, you have to provide a captcha and token parameter (You can get the captcha and token via Pr0grammApi::Captcha).

You can ignore this, when you already provided the cookie in your services.php. You can copy your Cookie from the Dev-Tools, while logged in for example.

Pr0grammApi::login('Gamb', 'Quatschtütenwürger25')

Logout of your account

Logging out will delete the session and the cookie. You have to log in again, to access user related endpoints. Otherwise, you will get an Exception.

Pr0grammApi::logout()

Examples

Retrieving the current user

$currentUser = Pr0grammApi::User()->me();

Retrieving info about a user

$userInfo = Pr0grammApi::User()->info('Gamb');

Voting a post

use Tschucki\Pr0grammApi\Enums\Vote;

Pr0grammApi::Post()->vote(1, Vote::UP);

Add a comment

// Add comment to post with id 1
Pr0grammApi::Comment()->add(1, 'Das Ablecken von Türknöpfen ist auf anderen Planeten illegal.');

// Add comment to another comment
Pr0grammApi::Comment()->add(1, 'Ich bin ne gute Nudel', 22);

Get Comments from Inbox

Pr0grammApi::Inbox()->comments();

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Feel free to open a PR or an issue. I will try to respond as soon as possible.

Credits

License

The MIT License (MIT). Please see License File for more information.