rennokki/reddit-json-api 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

rennokki/reddit-json-api

Composer 安装命令:

composer require rennokki/reddit-json-api

包简介

Reddit JSON API offers an easy way to retrieve data from subreddits in no time.

README 文档

README

CI codecov StyleCI Latest Stable Version Total Downloads Monthly Downloads License

Reddit JSON API is a PHP wrapper for handling JSON information from public subreddits.

🚀 Installation

You can install the package via composer:

composer require rennokki/reddit-json-api

🙌 Usage

use Rennokki\RedditApi\Reddit;

$app = Reddit::app(
    'renoki-co/reddit-json-api',
    '2.0',
    'web',
    'someusername'
);

$subreddit = Reddit::subreddit(
    'funny', // subreddit name
    $app
);

$posts = $subreddit->get();

foreach ($posts as $post) {
    $id = $post['id'];
}

When retrieving posts, the results are wrapped in a Rennokki\RedditApi\RedditList class. This class is based on Laravel Collection and you can pipeline actions on it more easily. Please see Laravel Collections documentantion.

Pagination

For pagination purposes, you shall call nextPage() from the previous $posts:

$subreddit = Reddit::subreddit('funny', $app);

$posts = $subreddit->get();

$nextPageOfPosts = $posts->nextPage();

Sorting

Reddit allows sorting by posts type. The currently used ones are:

public static $sorts = [
    'hot', 'new', 'controversial', 'top', 'rising',
];

To apply the sorting, you should call sort():

$subreddit = Reddit::subreddit('funny', $app);

$subreddit->sort('top');

Time Filtering

Same as sorting, time filters are only a few:

public static $times = [
    'hour', 'day', 'week', 'month', 'year', 'all',
];
$subreddit = Reddit::subreddit('funny', $app);

// Top, all time sorting.
$subreddit
    ->sort('top')
    ->time('all');

Limit

By default, each call gives you 20 posts.

$subreddit = Reddit::subreddit('funny', $app);

$subreddit->setLimit(100);

Debugging

If you wish to inspect the URL that is being called, you ca do so:

$subreddit = Reddit::subreddit('funny', $app);

$subreddit
    ->setLimit(30)
    ->sort('top')
    ->time('week');

$url = $subreddit->getCallableUrl();

🐛 Testing

vendor/bin/phpunit

🤝 Contributing

Please see CONTRIBUTING for details.

🔒 Security

If you discover any security related issues, please email alex@renoki.org instead of using the issue tracker.

🎉 Credits

统计信息

  • 总下载量: 733
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 21
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 21
  • Watchers: 1
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2019-01-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固