Public Member Functions | |
__construct (AuthenticationState $auth, Persistence\Interfaces\StorageProviderInterface $storage=null) | |
fetchAccessToken () | |
fetchInfo (array $thingFullnames) | |
fetchLink (string $linkFullname) | |
fetchLinksControversial (string $subredditName, int $limit=25, string $after=null, string $before=null, int $count=null, bool $showAll=false, string $period='day') | |
fetchLinksHot (string $subredditName, int $limit=25, string $after=null, string $before=null, int $count=null, bool $showAll=false, string $locality=null) | |
fetchLinksNew (string $subredditName, int $limit=25, string $after=null, string $before=null, int $count=null, bool $showAll=false) | |
fetchLinksRandom (string $subredditName, int $limit=1) | |
fetchLinksRising (string $subredditName, int $limit=25, string $after=null, string $before=null, int $count=null, bool $showAll=false) | |
fetchLinksTop (string $subredditName, int $limit=25, string $after=null, string $before=null, int $count=null, bool $showAll=false, string $period='day') | |
fetchMyAccount () | |
fetchSubreddit (string $subredditName) | |
fetchUser (string $username) | |
getAccountMapper () | |
getLinkMapper () | |
getSubredditMapper () | |
Public Member Functions inherited from snuze\SnuzeObject | |
__construct (array $args=null) | |
_getSnuzeId () | |
_getSnuzeClass () | |
_ident () | |
Public Attributes | |
const | VERSION = 1000801 |
Private Member Functions | |
authenticate () | |
sendRequest (Request\Request $request) | |
getStorageMapper (string $objectClass) | |
Private Attributes | |
$auth = null | |
$storage = null | |
$autosleep = true | |
Additional Inherited Members | |
Protected Member Functions inherited from snuze\SnuzeObject | |
debug (string $message, bool $echo=false) | |
info (string $message, bool $echo=false) | |
warning (string $message, bool $echo=false) | |
error (string $message, bool $echo=false) | |
Protected Attributes inherited from snuze\SnuzeObject | |
$_snuzeId = null | |
$_snuzeClass = null | |
The Snuze object is the primary public interface to all of the functionality this package provides. This is the object your application uses to interact directly with the Reddit API and the storage provider (if one is enabled). You get a Snuze object by passing an array of configuration parameters to a SnuzeFactory and calling its getSnuze() method.
To help elucidate when API requests are involved, methods that retrieve data from Reddit's API have names beginning with "fetch" instead of "get." All methods whose names begin with "fetch" will, when called, initiate at least one outbound connection to the remote API server.
This file is part of Snuze, a PHP client for the Reddit API. Copyright 2019 Shaun Cummiskey shaun @sha unc.c omhttps://shaunc.com/ Repository: https://github.com/snuze/snuze/ Documentation: https://snuze.shaunc.com/
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
snuze\Snuze::__construct | ( | AuthenticationState | $auth, |
Persistence\Interfaces\StorageProviderInterface | $storage = null |
||
) |
Constructor. An AuthenticationState must be supplied. Optionally, a storage provider object that implements StorageProviderInterface may be supplied; if it's null or not passed, storage will be disabled.
Instantiating a Snuze object really ought to be done via a SnuzeFactory.
\snuze\AuthenticationState | $auth | A configured AuthenticationState object |
\snuze\Persistence\Interfaces\StorageProviderInterface | $storage | Optional; a storage provider object that implements StorageProviderInterface. |
|
private |
Check that the current authentication state is valid. If not, an access token is sought, first from storage if that's enabled, and then from the API server.
snuze\Snuze::fetchAccessToken | ( | ) |
Retrieve a new access token from the Reddit API server. The token will be associated with whichever Reddit account is running Snuze at the time the request is made.
snuze\Snuze::fetchInfo | ( | array | $thingFullnames | ) |
Retrieve the properties of one or more Thing objects from the API server.
Things of different kinds can be requested at the same time, but only comments, links, and subreddits (t1, t3, and t5 kinds) may be requested via this method.
array | $thingFullnames | An array containing one or more Thing fullnames, e.g. ['t1_abc', 't3_def', 't5_ghi'], about which to request properties. |
snuze\Snuze::fetchLink | ( | string | $linkFullname | ) |
Retrieve a single link's properties from the API server.
string | $linkFullname | The target link's fullname e.g. "t3_cnrvpk" |
snuze\Snuze::fetchLinksControversial | ( | string | $subredditName, |
int | $limit = 25 , |
||
string | $after = null , |
||
string | $before = null , |
||
int | $count = null , |
||
bool | $showAll = false , |
||
string | $period = 'day' |
||
) |
Retrieve a subreddit's "Controversial" links listing from the API server.
All arguments other than $subredditName are optional.
Only one of $after or $before may be set; if either argument is passed, the other must be null (or not passed).
string | $subredditName | The target subreddit's name e.g. "funny" |
int | $limit | Optional. The maximum number of links to retrieve. Values from 1 to 100 are acceptable; if not set, defaults to 25 |
string | $after | Optional. The fullname e.g. "t3_cevca2" of a link to retrieve results after, akin to "next page" |
string | $before | Optional. The fullname e.g. "t3_cevca2" of a link to retrieve results before, akin to "previous page" |
int | $count | Optional. When paging through a subreddit, set this to the number of links that have already been retrieved. Use in combination with $after or $before. |
bool | $showAll | Optional. If true, disregards any "hide links..." preferences enabled for the currently authenticated user |
string | $period | Optional. One of 'hour', 'day', 'week', 'month', 'year', or 'all', to define which time period this request is constrained to. If not set, defaults to 'day' |
snuze\Snuze::fetchLinksHot | ( | string | $subredditName, |
int | $limit = 25 , |
||
string | $after = null , |
||
string | $before = null , |
||
int | $count = null , |
||
bool | $showAll = false , |
||
string | $locality = null |
||
) |
Retrieve a subreddit's "Hot" links listing from the API server.
All arguments other than $subredditName are optional.
Only one of $after or $before may be set; if either argument is passed, the other must be null (or not passed).
string | $subredditName | The target subreddit's name e.g. "funny" |
int | $limit | Optional. The maximum number of links to retrieve. Values from 1 to 100 are acceptable; if not set, defaults to 25 |
string | $after | Optional. The fullname e.g. "t3_cevca2" of a link to retrieve results after, akin to "next page" |
string | $before | Optional. The fullname e.g. "t3_cevca2" of a link to retrieve results before, akin to "previous page" |
int | $count | Optional. When paging through a subreddit, set this to the number of links that have already been retrieved. Use in combination with $after or $before. |
bool | $showAll | Optional. If true, disregards any "hide links..." preferences enabled for the currently authenticated user |
string | $locality | Optional. A locality code for which to request a geographically-oriented "hot" listing. Valid locality codes can be found in the Request\Links\HotLinks class, or at the URL below. |
snuze\Snuze::fetchLinksNew | ( | string | $subredditName, |
int | $limit = 25 , |
||
string | $after = null , |
||
string | $before = null , |
||
int | $count = null , |
||
bool | $showAll = false |
||
) |
Retrieve a subreddit's "New" links listing from the API server.
All arguments other than $subredditName are optional.
Only one of $after or $before may be set; if either argument is passed, the other must be null (or not passed).
string | $subredditName | The target subreddit's name e.g. "funny" |
int | $limit | Optional. The maximum number of links to retrieve. Values from 1 to 100 are acceptable; if not set, defaults to 25 |
string | $after | Optional. The fullname e.g. "t3_cevca2" of a link to retrieve results after, akin to "next page" |
string | $before | Optional. The fullname e.g. "t3_cevca2" of a link to retrieve results before, akin to "previous page" |
int | $count | Optional. When paging through a subreddit, set this to the number of links that have already been retrieved. Use in combination with $after or $before. |
bool | $showAll | Optional. If true, disregards any "hide links..." preferences enabled for the currently authenticated user |
snuze\Snuze::fetchLinksRandom | ( | string | $subredditName, |
int | $limit = 1 |
||
) |
Retrieve random link(s) for a subreddit from the API server.
By default, only one link is retrieved (it's still returned inside of a LinkListing object). If $limit is specified, and its value is greater than 1, a separate API request will be made for each link, with each one counting against the rate limit.
This method doesn't work on subreddits with the "allow this subreddit to be exposed to users in /r/all, /r/popular, default, and trending lists" preference disabled.
string | $subredditName | The target subreddit's name e.g. "funny" |
int | $limit | Optional. The maximum number of links to retrieve. Values from 1 to 100 are acceptable; if not set, defaults to 1. |
snuze\Snuze::fetchLinksRising | ( | string | $subredditName, |
int | $limit = 25 , |
||
string | $after = null , |
||
string | $before = null , |
||
int | $count = null , |
||
bool | $showAll = false |
||
) |
Retrieve a subreddit's "Rising" links listing from the API server.
All arguments other than $subredditName are optional.
Only one of $after or $before may be set; if either argument is passed, the other must be null (or not passed).
string | $subredditName | The target subreddit's name e.g. "funny" |
int | $limit | Optional. The maximum number of links to retrieve. Values from 1 to 100 are acceptable; if not set, defaults to 25 |
string | $after | Optional. The fullname e.g. "t3_cevca2" of a link to retrieve results after, akin to "next page" |
string | $before | Optional. The fullname e.g. "t3_cevca2" of a link to retrieve results before, akin to "previous page" |
int | $count | Optional. When paging through a subreddit, set this to the number of links that have already been retrieved. Use in combination with $after or $before. |
bool | $showAll | Optional. If true, disregards any "hide links..." preferences enabled for the currently authenticated user |
snuze\Snuze::fetchLinksTop | ( | string | $subredditName, |
int | $limit = 25 , |
||
string | $after = null , |
||
string | $before = null , |
||
int | $count = null , |
||
bool | $showAll = false , |
||
string | $period = 'day' |
||
) |
Retrieve a subreddit's "Top" links listing from the API server.
All arguments other than $subredditName are optional.
Only one of $after or $before may be set; if either argument is passed, the other must be null (or not passed).
string | $subredditName | The target subreddit's name e.g. "funny" |
int | $limit | Optional. The maximum number of links to retrieve. Values from 1 to 100 are acceptable; if not set, defaults to 25 |
string | $after | Optional. The fullname e.g. "t3_cevca2" of a link to retrieve results after, akin to "next page" |
string | $before | Optional. The fullname e.g. "t3_cevca2" of a link to retrieve results before, akin to "previous page" |
int | $count | Optional. When paging through a subreddit, set this to the number of links that have already been retrieved. Use in combination with $after or $before. |
bool | $showAll | Optional. If true, disregards any "hide links..." preferences enabled for the currently authenticated user |
string | $period | Optional. One of 'hour', 'day', 'week', 'month', 'year', or 'all', to define which time period this request is constrained to. If not set, defaults to 'day' |
snuze\Snuze::fetchMyAccount | ( | ) |
Retrieve the currently authenticated user's account information from the API server. The data will correspond to whichever Reddit account is running Snuze at the time the request is made.
snuze\Snuze::fetchSubreddit | ( | string | $subredditName | ) |
Retrieve a subreddit's main properties from the API server.
string | $subredditName | The target subreddit's name e.g. "funny" |
snuze\Snuze::fetchUser | ( | string | $username | ) |
Retrieve a Reddit user's public account information from the API server.
string | $username | The username of the target account |
snuze\Snuze::getAccountMapper | ( | ) |
Get an AccountMapper from the storage provider to facilitate persisting and retrieving accounts.
snuze\Snuze::getLinkMapper | ( | ) |
Get a LinkMapper from the storage provider to facilitate persisting and retrieving links.
|
private |
Get a Mapper object from the storage provider to facilitate persisting and retrieving objects to and from storage. Pass the type of object you want a Mapper for: 'Subreddit', 'Link', 'Comment', etc. The public convenience methods that wrap this one should be used instead of calling this directly.
string | $objectClass | The type of object a Mapper is needed for |
snuze\Snuze::getSubredditMapper | ( | ) |
Get a SubredditMapper from the storage provider to facilitate persisting and retrieving subreddits.
|
private |
Dispatch a RequestSender to send a request to the Reddit API server.
\snuze\Request\Request | $request | A Request subtype object to send to the Reddit API server |
const snuze\Snuze::VERSION = 1000801 |
The Snuze build number.