Skip to content

Commit 6be8fb0

Browse files
committed
Initial commit.
0 parents  commit 6be8fb0

12 files changed

+749
-0
lines changed

.codecov.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
codecov:
2+
notify:
3+
require_ci_to_pass: yes
4+
5+
coverage:
6+
precision: 2
7+
round: down
8+
range: “70…100”
9+
10+
status:
11+
project: yes
12+
patch: yes
13+
changes: no
14+
15+
comment:
16+
layout: “reach, diff, flags, files, footer”
17+
behavior: default
18+
require_changes: no

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
vendor/
2+
composer.lock

.styleci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
preset: laravel

.travis.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
language: php
2+
3+
php:
4+
- 7.1
5+
- 7.2
6+
7+
env:
8+
matrix:
9+
- COMPOSER_FLAGS=""
10+
11+
before_script:
12+
- travis_retry composer self-update
13+
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-source
14+
15+
script:
16+
- phpunit --coverage-text --coverage-clover=coverage.xml
17+
18+
after_success:
19+
- bash <(curl -s https://codecov.io/bash)

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 rennokki
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

composer.json

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"name": "rennokki/reddit-json-api",
3+
"description": "Reddit JSON API offers an easy way to retrieve data from subreddits in no time.",
4+
"keywords": [
5+
"laravel",
6+
"mjml",
7+
"wrapper",
8+
"api"
9+
],
10+
"homepage": "https://github.com/rennokki/reddit-json-api",
11+
"license": "MIT",
12+
"authors": [
13+
{
14+
"name": "Alex Renoki",
15+
"email": "rennokki@gmail.com",
16+
"homepage": "https://twitter.com/rennokki",
17+
"role": "Developer"
18+
}
19+
],
20+
"require": {
21+
"guzzlehttp/guzzle": "^6.3@dev"
22+
},
23+
"require-dev": {
24+
"phpunit/phpunit": "^6.2|^7.0",
25+
"orchestra/testbench": "~3.5.0|~3.6.0",
26+
"orchestra/database": "~3.5.0|~3.6.0"
27+
},
28+
"autoload": {
29+
"psr-4": {
30+
"Rennokki\\RedditAPI\\": "src"
31+
}
32+
},
33+
"autoload-dev": {
34+
"psr-4": {
35+
"Rennokki\\RedditAPI\\Test\\": "tests"
36+
}
37+
},
38+
"scripts": {
39+
"test": "vendor/bin/phpunit"
40+
},
41+
"extra": {
42+
"laravel": {
43+
"providers": [
44+
"Rennokki\\RedditAPI\\RedditAPIServiceProvider"
45+
]
46+
}
47+
},
48+
"config": {
49+
"sort-packages": true
50+
},
51+
"minimum-stability": "dev"
52+
}

phpunit.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit bootstrap="vendor/autoload.php"
3+
backupGlobals="false"
4+
backupStaticAttributes="false"
5+
colors="true"
6+
verbose="true"
7+
convertErrorsToExceptions="true"
8+
convertNoticesToExceptions="true"
9+
convertWarningsToExceptions="true"
10+
processIsolation="false"
11+
stopOnFailure="false">
12+
<testsuites>
13+
<testsuite name="Rennokki Test Suite">
14+
<directory>tests</directory>
15+
</testsuite>
16+
</testsuites>
17+
<filter>
18+
<whitelist>
19+
<directory suffix=".php">src/</directory>
20+
</whitelist>
21+
</filter>
22+
</phpunit>

readme.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
[![Build Status](https://travis-ci.org/rennokki/reddit-json-api.svg?branch=master)](https://travis-ci.org/rennokki/reddit-json-api)
2+
[![codecov](https://codecov.io/gh/rennokki/reddit-json-api/branch/master/graph/badge.svg)](https://codecov.io/gh/rennokki/reddit-json-api/branch/master)
3+
[![StyleCI](https://github.styleci.io/repos/166289783/shield?branch=master)](https://github.styleci.io/repos/166289783)
4+
[![Latest Stable Version](https://poser.pugx.org/rennokki/reddit-json-api/v/stable)](https://packagist.org/packages/rennokki/reddit-json-api)
5+
[![Total Downloads](https://poser.pugx.org/rennokki/reddit-json-api/downloads)](https://packagist.org/packages/rennokki/reddit-json-api)
6+
[![Monthly Downloads](https://poser.pugx.org/rennokki/reddit-json-api/d/monthly)](https://packagist.org/packages/rennokki/reddit-json-api)
7+
[![License](https://poser.pugx.org/rennokki/reddit-json-api/license)](https://packagist.org/packages/rennokki/reddit-json-api)
8+
9+
[![PayPal](https://img.shields.io/badge/PayPal-donate-blue.svg)](https://paypal.me/rennokki)
10+
11+
# Reddit JSON API
12+
Reddit JSON API is a simple request builder which helps you retrieve data from Reddit's JSON API. You can query subreddit for posts so far, so go ahead parsing posts!
13+
14+
# Installation
15+
Install the package:
16+
```bash
17+
$ composer require rennokki/reddit-json-api
18+
```
19+
20+
If you are using Laravel and your Laravel version does not support package discovery, add this line in the `providers` array in your `config/app.php` file:
21+
```php
22+
Rennokki\RedditAPI\RedditAPIServiceProvider::class,
23+
```
24+
25+
# Setting up the API
26+
This kind of API does not need credentials. The only things you need is to specify an User Agent for your requests. This can be done easy:
27+
```php
28+
use Rennokki\RedditAPI\RedditAPI;
29+
30+
$api = (new RedditAPI())->platform('web')
31+
->appId('my-awesome-app')
32+
->version('1.0.0-beta')
33+
->redditUsername('myRedditUsername');
34+
35+
$dankPosts = $api->subreddit('dankmemes')->hot()->get();
36+
37+
foreach ($dankPosts->data->children as $post) {
38+
//
39+
}
40+
```
41+
42+
# Available methods
43+
You can sort posts, you can specify a time for `controversial` or `top` sorts, you can query for `after`, `before` and even constrain a limit:
44+
45+
Specify a `limit`:
46+
```php
47+
$posts = $api->subreddit('memes')->limit(100)->get();
48+
```
49+
50+
Specify a `before` or an `after`:
51+
```php
52+
$afterPosts = $api->subreddit('memes')->after('id_here')->get();
53+
$beforePosts = $api->subreddit('memes')->before('id_here')->get();
54+
```
55+
56+
Sort by importance:
57+
```php
58+
$hotPosts = $api->subreddit('memes')->hot()->get();
59+
``
60+
61+
Alternatively, you can sort like this:
62+
```php
63+
$hotPosts = $api->subreddit('memes')->sort('hot')->get();
64+
```
65+
66+
The remaining methods are the following, with their `sort()` alternative:
67+
```php
68+
->new()
69+
->rising()
70+
->controversial()
71+
->top()
72+
73+
->sort('new')
74+
->sort('rising')
75+
->sort('controversial')
76+
->sort('top')
77+
```
78+
79+
The last two, `controversial` and `top` allow to specify a `time`:
80+
```php
81+
$allTimeTopPosts = $api->subreddit('memes')->top()->all()->get();
82+
```
83+
84+
Alternatively, exactly like the `sort()` function, there's the `time()` function that allows you to input a string. All methods to sort the time are the following:
85+
```php
86+
->hour()
87+
->day()
88+
->week()
89+
->month()
90+
->year()
91+
92+
->time('hour')
93+
->time('day')
94+
->time('week')
95+
->time('month')
96+
->time('year')
97+
```
98+
99+
If no time is specified, the default one is `all()`.
100+
101+
Since the class is a builder, you might want to clear time, sort, before or after. You can do so:
102+
```php
103+
$api->clearBefore()->...;
104+
$api->clearAfter()->...;
105+
$api->clearSort()->...;
106+
$api->clearTime()->...; // this reverts to default: 'all'
107+
```

0 commit comments

Comments
 (0)