Giter Club home page Giter Club logo

reddit-api-client's Introduction

Reddit API Client

Build Status Latest Stable Version Latest Stable Version Minimum PHP Version

This is a PHP client for Reddit's API, built on the Guzzle web service client framework.

As a quick taster, here's some sample code:

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

$clientFactory = new Reddit\Api\Client\Factory;
$client = $clientFactory->createClient();

$login = $client->getCommand(
    'Login',
    array(
        'api_type' => 'json',
        'user'     => 'Example_User',
        'passwd'   => 'password123',
    )
);
$login->execute();

$submit = $client->getCommand(
    'Submit',
    array(
        'sr'    => 'programming',
        'kind'  => 'link',
        'title' => 'Mongo DB Is Web Scale',
        'url'   => 'http://www.youtube.com/watch?v=b2F-DItXtZs',
    )
);
$submit->execute();

Installation

This project is packaged with Composer. Add the following the the require section of your project's composer.json:

"zetaphor/reddit-api-client": "dev-master"

After that just run php composer.phar update and you're good to go! If you have any trouble, or want more detail, I've set up a working example "Reddit Console" project for reference purposes.

Development Status

Reddit's API is big, and the service description JSON in the ./api/ directory is incomplete.

Supported URIs

  • api/login/{user}
  • api/me.json
  • api/register
  • api/submit
  • api/del
  • api/vote
  • api/comment
  • api/message
  • by_id/t3_{id}.json
  • r/{subreddit}.json
  • user/{id}.json
  • user/{id}/about.json

The above list covers many of the most common interactions such as logging in, reading and posting links and comments, and casting votes. However, there are dozens more services available in Reddit's API, and simple pull requests adding entries to the service description JSON are very welcome.

Contributing

This is a fairly simple project so there aren't many guidelines. If you've fixed a bug or added a feature, let's get it merged back in. There are two hard rules.

1. Test-drive your changes

This project is test-driven. Please don't submit any code changes without a corresponding set of unit tests.

$ make phpunit

2. Follow PSR2

Stick to the PSR-2 standard.

$ make phpcs

License

This project is released under the MIT License.

reddit-api-client's People

Contributors

bkonold avatar ck99 avatar henrycatalinismith avatar isaacbats avatar isometriks avatar llbbl avatar noahbass avatar snacsnoc avatar zetaphor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

reddit-api-client's Issues

sample code in Readme.md doesn't work

The sample code in the readme doesn't seem to work. I receive an error that I need to be logged in.

I presume that the session store needs to be hooked up to the login process.

I ended up modifying the api service description for submit to accept the modhash, but looking at the code that doesn't appear to go along with the overall design of the application.

Am I missing a step and/or is the readme wrong?

Add an API for submitting comments.

See http://www.reddit.com/dev/api#POST_api_comment. Updated comment.json:

{
  "operations": {
    "SubmitComment": {
      "httpMethod": "POST",
      "uri": "/api/comment",
      "summary": "Submit a new comment",
      "parameters": {
        "text": {
          "location": "query",
          "description": "The text to submit.",
          "required": true,
          "type": "string"
        },
        "thing_id": {
          "location": "query",
          "description": "Fullname of parent thing (a comment, or a link)",
          "required": true,
          "type": "string"
        }
      }
    }
  }
}

Private Message handling

Are you likely to add in the PrivateMessages functions?

Specifically get_inbox(), get_mentions(), get_sent(), get_unread() and send_message()??

Fatal error when subreddit doesn't exist

When using the getLinksBySubreddit function on a nonexistent subreddit, a fatal error occurs.

Error is as follows:

PHP Warning:  Invalid argument supplied for foreach() in reddit-api/Reddit.php on line 271

This library doesn't work

With last commit guzzle dependency was changed to guzzleHttp but wasn't updated completely within the code hence resulted in following error:

2017-10-27_1258

when i changed the dependency back to guzzle this is what i get:
2017-10-27_1300

Any help?

Unknown type of Thing triggers an undefined variable notice in ThingFactory.

If ThingFactory encounters a Thing type that is not listed in $kindClassMap, it generates an undefined variable notice. Although a situation like this is unlikely to happen, it still would be better to return NULL (or to throw an exception) rather than to trigger a notice. Here is the modified code of Reddit\Api\Response\ThingFactory::createThing():

public function createThing(array $input)
{
    if (isset($this->kindClassMap[$input['kind']])) {
        $thing = new $this->kindClassMap[$input['kind']];
        $this->hydrateThing($thing, $input['data']);
        return $thing;
    }
    return NULL;
}

how to use the search api or build a custom call not already included?

Sorry if this should be clear but I would like to use this package with some API calls that are not currently included as far as I can tell. In particular I would like to be able to search reddit for keywords without specifying a subreddit.

I was also looking at the recently comitted GetLinksBySubreddit and I notice that it doesn't seem to allow for any other parameter than the subreddit. So I can't specify that I want them ordered by "hot" or "new" and I can't specify the limit or offset that the Reddit API allows for.

Or maybe I can.. but I just don't know how as this is the first time I look into Guzzle. My question is simple.. is it possible to build a custom API call with custom paramters without modifying the current core of this package? If so... a simple example would be very appreciated.

thank you very kindly

Submitting link does not return correct value

reddit is returning an error through this PHP API, but this API is not catching the error returned. It's still outputting true (1) that submit was successful. For example, in the return array from reddit this is correct:

        [12] => Array
            (
                [0] => 12
                [1] => 13
                [2] => call
                [3] => Array
                    (
                        [0] => value
                        [1] => http://www.msn.com
                    )

            )

But this from reddit indicates an error, and this API doesn't notice that:

        [14] => Array
            (
                [0] => 14
                [1] => 15
                [2] => call
                [3] => Array
                    (
                        [0] => a url is required
                    )

            )

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.