Git Product home page Git Product logo

devrant-php's Introduction

devrant-php

Build Status

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
comment($rantId, $comment) mixed array
voteRant($rantId, $vote) mixed array
voteComment($commentId, $vote) mixed array
notifs() void array
collabs() void array
deleteRant($rantId) int array
deleteComment($commentId) int array
deleteAccount() void array

Examples

Getting array of rants

$devRant = new \pxgamer\devRant\Connection;
$devRant->getRants(); // Get rants
$devRant->getRants($searchterm); // Get rants using a search query

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
]

Posting a comment

$devRant = new \pxgamer\devRant\Connection;
if ($devRant->login('username', 'password')) {
    $devRant->comment($rantId, 'Comment Content');
}

Returns:

[
    "success" => true
]

Getting Collabs

$devRant = new \pxgamer\devRant\Connection;

$collabs = $devRant->collabs();

Returns:

[
    "success" => true,
    "rants" => [
		[0] => [
		    ...
		]
	]
]

Voting on Rants

$devRant = new \pxgamer\devRant\Connection;
if ($devRant->login('username', 'password')) {
    $voteRant = $devRant->voteRant($rantId, $vote);
}

Returns:

[
    "success" => true,
    "rant" => [
		[id] => ...,
		...
	]
]

Voting on Comments

$devRant = new \pxgamer\devRant\Connection;
if ($devRant->login('username', 'password')) {
    $voteRant = $devRant->voteComment($commentId, $vote);
}

Returns:

[
    "success" => true,
    "comment" => [
		[id] => ...,
		...
	]
]

Getting your notifications

$devRant = new \pxgamer\devRant\Connection;
if ($devRant->login('username', 'password')) {
    $notifications = $devRant->notifs();
}

Returns:

[
    "success" => true,
    "data" => {
		"items" => [
			...
		],
		"check_time" => 11111,
		"username_map" => {
			...
		}
	}
]

Deleting a rant

Please note that this will permanently delete the rant from devRant.

$devRant = new \pxgamer\devRant\Connection;
if ($devRant->login('username', 'password')) {
    $devRant->deleteRant($rantId);
}

Returns:

[
    "success" => true
]

Deleting a comment

Please note that this will permanently delete the comment from devRant.

$devRant = new \pxgamer\devRant\Connection;
if ($devRant->login('username', 'password')) {
    $devRant->deleteComment($commentId);
}

Returns:

[
    "success" => true
]

Deleting your account

Please note that this will permanently delete your account from devRant.

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

Returns:

[
    "success" => true
]

License

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

devrant-php's People

Contributors

curx avatar garrettw avatar incrediblequark avatar owenvoke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

garrettw curx

devrant-php's Issues

Got some ideas

Hey there ๐Ÿ˜„

Well, I took a look at your code and I'm a bit confused. As it is currently, there's not much point in using a class at all, because you're not really making objects with properties. All of your functions are static, there are no member variables, all your static class variables are public... and the constructor is pointless.

So I would say either go fully object-oriented or fully not. Which way do you favor?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.