@@ -17,7 +17,95 @@ composer require rennokki/reddit-json-api
17
17
## 🙌 Usage
18
18
19
19
``` php
20
- //
20
+ use Rennokki\RedditApi\Reddit;
21
+
22
+ $app = Reddit::app(
23
+ 'renoki-co/reddit-json-api',
24
+ '2.0',
25
+ 'web',
26
+ 'someusername'
27
+ );
28
+
29
+ $subreddit = Reddit::subreddit(
30
+ 'funny', // subreddit name
31
+ $app
32
+ );
33
+
34
+ $posts = $subreddit->get()['data']['children'] ?? [];
35
+ ```
36
+
37
+ ## Sorting
38
+
39
+ Reddit allows sorting by posts type. The currently used ones are:
40
+
41
+ ``` php
42
+ public static $sorts = [
43
+ 'hot', 'new', 'controversial', 'top', 'rising',
44
+ ];
45
+ ```
46
+
47
+ To apply the sorting, you should call ` sort() ` :
48
+
49
+ ``` php
50
+ $subreddit = Reddit::subreddit('funny', $app);
51
+
52
+ $subreddit->sort('top');
53
+ ```
54
+
55
+ ## Time Filtering
56
+
57
+ Same as sorting, time filters are only a few:
58
+
59
+ ``` php
60
+ public static $times = [
61
+ 'hour', 'day', 'week', 'month', 'year', 'all',
62
+ ];
63
+ ```
64
+
65
+ ``` php
66
+ $subreddit = Reddit::subreddit('funny', $app);
67
+
68
+ // Top, all time sorting.
69
+ $subreddit
70
+ ->sort('top')
71
+ ->time('all');
72
+ ```
73
+
74
+ ## Limit
75
+
76
+ By default, each call gives you ` 20 ` posts.
77
+
78
+ ``` php
79
+ $subreddit = Reddit::subreddit('funny', $app);
80
+
81
+ $subreddit->setLimit(100);
82
+ ```
83
+
84
+ ## Before & After tokens
85
+
86
+ For paginating, you shall specify before & after from previous requests:
87
+
88
+ ``` php
89
+ $subreddit = Reddit::subreddit('funny', $app);
90
+
91
+ $subreddit->before(...);
92
+
93
+ $subreddit->after(...);
94
+ ```
95
+
96
+ ## Debugging
97
+
98
+ If you wish to inspect the URL that is being called, you ca do so:
99
+
100
+ ``` php
101
+ $subreddit = Reddit::subreddit('funny', $app);
102
+
103
+ $subreddit
104
+ ->setLimit(30)
105
+ ->sort('top')
106
+ ->time('week');
107
+
108
+ $url = $subreddit->getCallableUrl();
21
109
```
22
110
23
111
## 🐛 Testing
0 commit comments