garrettw / devrant-php

A simple PHP wrapper for utilising the devRant api.

Home Page:https://packagist.org/packages/pxgamer/devrant-php

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

devrant-php

Scrutinizer Code Quality

A simple PHP wrapper for utilising the devRant api.

Usage

Include the class:

  • Using Composer

composer require pxgamer/devrant-php

<?php
require 'vendor/autoload.php';
  • Including the files manually
<?php
include 'src/Connection.php';
include 'src/Rant.php';

Once included, you can initialise the class using either of the following:

$devRant = new \pxgamer\devRant\Connection;
use \pxgamer\devRant\Connection;
$devRant = new Connection;

Class Methods

Method Name Parameters Returns
getRants($searchterm) string (optional) array of Rant objects
getRantById($id) int Rant object
getUserById($id) int array
getUsersId($username) string array
login($username, $password) strings boolean
logout() void void
rant($rant) Rant object array

Examples

Getting array of rants

$devRant = new \pxgamer\devRant\Connection;
$devRant->getRants();

Returns false on failure, or:

[
    0 => Rant object,
    1 => Rant object,
    ...
]

Getting a single rant by its id

$devRant = new \pxgamer\devRant\Connection;
$devRant->getRantById(int);

Returns false on failure, or a Rant object.

Getting a user by their id

$devRant = new \pxgamer\devRant\Connection;
$devRant->getUserById(int);

Returns:

[
    "success" => true,
    "profile" => [
        "username" => "",
        "score" => 0,
        "about" => "",
        "location" => "",
        "created_time" => 1474613872,
        "skills" => "",
        "github" => "",
        "website" => "",
        "content" => [
            "content" => [
                "rants" => [],
                "upvoted" => [],
                "comments" => [],
                "favorites" => []
            [,
            "counts" => []
        ],
        "avatar" => []
    ]
]

Search rants

$devRant = new \pxgamer\devRant\Connection;
$devRant->getRants('string');

Returns false on failure, or:

[
    0 => Rant object [
        "id" => 0,
        "text" => "string",
        "num_upvotes" => 0,
        "num_downvotes" => 0,
        "score" => 0,
        "created_time" => 0,
        "attached_image" => [
            "url" => "string",
            "width" => 0,
            "height" => 0
        ],
        "num_comments" => 0,
        "tags" => [
            "string"
        ],
        "vote_state" => 0,
        "edited" => false,
        "user_id" => 0,
        "user_username" => "string",
        "user_score" => 0,
        "user_avatar" => [
            "b" => "string"
        ]
    ],
    1 => Rant object,
    ...
]

Getting a user's id from their username

$devRant = new \pxgamer\devRant\Connection;
$devRant->getUserId('username');

Returns:

[
    "success" => true,
    "user_id" => 0
]

Getting signed in

$devRant = new \pxgamer\devRant\Connection;
$devRant->login('username', 'password');

Returns true if successful, false if not

Posting a rant

use \pxgamer\devRant\Rant;

$devRant = new \pxgamer\devRant\Connection;
if ($devRant->login('username', 'password')) {
    $devRant->rant(new Rant($rant_content, $tags));
}

Returns:

[
    "success" => true,
    "rant_id" => 31131
]

About

A simple PHP wrapper for utilising the devRant api.

https://packagist.org/packages/pxgamer/devrant-php


Languages

Language:PHP 93.4%Language:Shell 6.6%