Snuze

Snuze classes for Reddit "thing" objects

Namespace

The classes described here are in the \snuze\Reddit\Thing namespace hierarchy.

One "thing" leads to another

Most first-class Reddit entities have a similar basic data structure, which Reddit calls a "thing." These objects share a set of common properties:

In Snuze, "thing" entities are represented by classes in the \snuze\Reddit\Thing namespace. Snuze returns objects of these types from many of its fetch...() methods, which retrieve data from the Reddit API.

Snuze "thing" objects are immutable; that is, their properties and setter methods are protected. The only source of truth for a "thing" is Reddit's API server, so it doesn't make sense for these values to change dynamically within your application.

The Thing class

The \snuze\Reddit\Thing\Thing class is an abstract class defining the common properties and methods shared by all of the "thing" subtypes. As mentioned above, these include the kind, id, fullname, and the created timestamp.

This class also provides methods called toJson() and fromJson(), which let you get the JSON representing a given object, or create a new object from a JSON string, respectively. Subtypes of Thing will occasionally override these two methods if any special tweaking of the JSON is needed.

Account and its subtypes

The Reddit API lets you fetch information about two types of accounts: your own account (the one Snuze is using to talk to the API), and other users' accounts.

The Account class

The \snuze\Reddit\Thing\Account\Account class is an abstract class that holds shared properties common to both account types.

The MyAccount class

The \snuze\Reddit\Thing\Account\MyAccount class extends Account to expose all of the attributes of your own account (the one Snuze is using to talk to the API). The data returned from this API endpoint is not actually a "thing" entity, but Snuze treats it as one.

The UserAccount class

The \snuze\Reddit\Thing\Account\UserAccount class extends Account to expose the limited public attributes available for other users' accounts.

The \snuze\Reddit\Thing\Link class represents the attributes of a link, otherwise known as a post or a submission.

The Subreddit class

The \snuze\Reddit\Thing\Subreddit class represents the significant attributes of a subreddit.