Snuze  0.8.1
snuze\Snuze Class Reference
Inheritance diagram for snuze\Snuze:

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
 

Detailed Description

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.nosp@m.@sha.nosp@m.unc.c.nosp@m.om https://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.

Constructor & Destructor Documentation

◆ __construct()

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.

Parameters
\snuze\AuthenticationState$authA configured AuthenticationState object
\snuze\Persistence\Interfaces\StorageProviderInterface$storageOptional; a storage provider object that implements StorageProviderInterface.
See also
\snuze\SnuzeFactory

Member Function Documentation

◆ authenticate()

snuze\Snuze::authenticate ( )
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.

Returns
bool True if authentication succeeded, else an exception is thrown
Exceptions

◆ fetchAccessToken()

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.

Returns
\snuze\Reddit\AccessToken

◆ fetchInfo()

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.

Parameters
array$thingFullnamesAn array containing one or more Thing fullnames, e.g. ['t1_abc', 't3_def', 't5_ghi'], about which to request properties.
Returns
\snuze\Reddit\Listing\Listing A generic Listing object containing Thing descendant objects. The Listing is iterable. If you request multiple Thing types, use instanceof or get_class() to determine each Thing's subtype.
See also
https://www.reddit.com/dev/api/#GET_api_info

◆ fetchLink()

snuze\Snuze::fetchLink ( string  $linkFullname)

Retrieve a single link's properties from the API server.

Parameters
string$linkFullnameThe target link's fullname e.g. "t3_cnrvpk"
Returns
\snuze\Reddit\Thing\Link A Link object populated with information about the target link

◆ fetchLinksControversial()

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).

Parameters
string$subredditNameThe target subreddit's name e.g. "funny"
int$limitOptional. The maximum number of links to retrieve. Values from 1 to 100 are acceptable; if not set, defaults to 25
string$afterOptional. The fullname e.g. "t3_cevca2" of a link to retrieve results after, akin to "next page"
string$beforeOptional. The fullname e.g. "t3_cevca2" of a link to retrieve results before, akin to "previous page"
int$countOptional. 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$showAllOptional. If true, disregards any "hide links..." preferences enabled for the currently authenticated user
string$periodOptional. 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'
Returns
\snuze\Reddit\Listing\LinkListing A LinkListing object containing a collection of Link objects, each one representing a single Reddit link. The LinkListing is iterable.

◆ fetchLinksHot()

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).

Parameters
string$subredditNameThe target subreddit's name e.g. "funny"
int$limitOptional. The maximum number of links to retrieve. Values from 1 to 100 are acceptable; if not set, defaults to 25
string$afterOptional. The fullname e.g. "t3_cevca2" of a link to retrieve results after, akin to "next page"
string$beforeOptional. The fullname e.g. "t3_cevca2" of a link to retrieve results before, akin to "previous page"
int$countOptional. 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$showAllOptional. If true, disregards any "hide links..." preferences enabled for the currently authenticated user
string$localityOptional. 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.
Returns
\snuze\Reddit\Listing\LinkListing A LinkListing object containing a collection of Link objects, each one representing a single Reddit link. The LinkListing is iterable.
See also
\snuze\Request\Links\HotLinks for valid locality codes
https://www.reddit.com/dev/api/#GET_hot for valid locality codes

◆ fetchLinksNew()

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).

Parameters
string$subredditNameThe target subreddit's name e.g. "funny"
int$limitOptional. The maximum number of links to retrieve. Values from 1 to 100 are acceptable; if not set, defaults to 25
string$afterOptional. The fullname e.g. "t3_cevca2" of a link to retrieve results after, akin to "next page"
string$beforeOptional. The fullname e.g. "t3_cevca2" of a link to retrieve results before, akin to "previous page"
int$countOptional. 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$showAllOptional. If true, disregards any "hide links..." preferences enabled for the currently authenticated user
Returns
\snuze\Reddit\Listing\LinkListing A LinkListing object containing a collection of Link objects, each one representing a single Reddit link. The LinkListing is iterable.

◆ fetchLinksRandom()

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.

Parameters
string$subredditNameThe target subreddit's name e.g. "funny"
int$limitOptional. The maximum number of links to retrieve. Values from 1 to 100 are acceptable; if not set, defaults to 1.
Returns
\snuze\Reddit\Listing\LinkListing A LinkListing object containing a collection of Link objects, each one representing a single Reddit link. The LinkListing is iterable.

◆ fetchLinksRising()

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).

Parameters
string$subredditNameThe target subreddit's name e.g. "funny"
int$limitOptional. The maximum number of links to retrieve. Values from 1 to 100 are acceptable; if not set, defaults to 25
string$afterOptional. The fullname e.g. "t3_cevca2" of a link to retrieve results after, akin to "next page"
string$beforeOptional. The fullname e.g. "t3_cevca2" of a link to retrieve results before, akin to "previous page"
int$countOptional. 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$showAllOptional. If true, disregards any "hide links..." preferences enabled for the currently authenticated user
Returns
\snuze\Reddit\Listing\LinkListing A LinkListing object containing a collection of Link objects, each one representing a single Reddit link. The LinkListing is iterable.

◆ fetchLinksTop()

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).

Parameters
string$subredditNameThe target subreddit's name e.g. "funny"
int$limitOptional. The maximum number of links to retrieve. Values from 1 to 100 are acceptable; if not set, defaults to 25
string$afterOptional. The fullname e.g. "t3_cevca2" of a link to retrieve results after, akin to "next page"
string$beforeOptional. The fullname e.g. "t3_cevca2" of a link to retrieve results before, akin to "previous page"
int$countOptional. 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$showAllOptional. If true, disregards any "hide links..." preferences enabled for the currently authenticated user
string$periodOptional. 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'
Returns
\snuze\Reddit\Listing\LinkListing A LinkListing object containing a collection of Link objects, each one representing a single Reddit link. The LinkListing is iterable.

◆ fetchMyAccount()

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.

Returns
\snuze\Reddit\Thing\Account\MyAccount A MyAccount object populated with the Snuze user's account information

◆ fetchSubreddit()

snuze\Snuze::fetchSubreddit ( string  $subredditName)

Retrieve a subreddit's main properties from the API server.

Parameters
string$subredditNameThe target subreddit's name e.g. "funny"
Returns
\snuze\Reddit\Thing\Subreddit A Subreddit object populated with information about the target subreddit

◆ fetchUser()

snuze\Snuze::fetchUser ( string  $username)

Retrieve a Reddit user's public account information from the API server.

Parameters
string$usernameThe username of the target account
Returns
\snuze\Reddit\Thing\Account\UserAccount A UserAccount object populated with information about the target account

◆ getAccountMapper()

snuze\Snuze::getAccountMapper ( )

Get an AccountMapper from the storage provider to facilitate persisting and retrieving accounts.

Returns
\snuze\Persistence\Interfaces\AccountMapperInterface

◆ getLinkMapper()

snuze\Snuze::getLinkMapper ( )

Get a LinkMapper from the storage provider to facilitate persisting and retrieving links.

Returns
\snuze\Persistence\Interfaces\LinkMapperInterface

◆ getStorageMapper()

snuze\Snuze::getStorageMapper ( string  $objectClass)
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.

Parameters
string$objectClassThe type of object a Mapper is needed for
Returns
\snuze\Persistence\Interfaces\MapperInterface
Exceptions

◆ getSubredditMapper()

snuze\Snuze::getSubredditMapper ( )

Get a SubredditMapper from the storage provider to facilitate persisting and retrieving subreddits.

Returns
\snuze\Persistence\Interfaces\SubredditMapperInterface

◆ sendRequest()

snuze\Snuze::sendRequest ( Request\Request  $request)
private

Dispatch a RequestSender to send a request to the Reddit API server.

Parameters
\snuze\Request\Request$requestA Request subtype object to send to the Reddit API server
Returns
string A JSON response from the Reddit API server
Exceptions

Member Data Documentation

◆ VERSION

const snuze\Snuze::VERSION = 1000801

The Snuze build number.


The documentation for this class was generated from the following file: