Android Open Source - android-reddit Reddit Data Source






From Project

Back to project page android-reddit.

License

The source code is released under:

MIT License

If you think the Android project android-reddit listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.pocketreddit.library.datasources;
//from  ww  w  .j  a  v  a  2  s  . c  o  m
import com.pocketreddit.library.things.Link;
import com.pocketreddit.library.things.Listing;
import com.pocketreddit.library.things.Subreddit;
import com.pocketreddit.library.things.Thing;
import com.pocketreddit.library.things.factories.ThingFactoryException;
import com.pocketreddit.library.things.utils.JsonToThingConverter;

public class RedditDataSource {
    private JsonDataSource dataSource;

    public RedditDataSource() {
        dataSource = new LiveDataSource();
    }

    public Listing<Subreddit> getSubreddits(String sessionId) throws DataSourceException {
        try {
            return new JsonToThingConverter<Listing<Subreddit>>().convert(dataSource
                    .getSubreddits(sessionId));
        } catch (ThingFactoryException e) {
            throw new DataSourceException("Could not parse subreddits from JSON.", e);
        }
    }

    /**
     * @param subreddit
     *            The unique slug that identifies the subreddit
     * @return a list of links for the subreddit.
     * @throws DataSourceException
     */
    public Listing<Link> getLinksForSubreddit(String subreddit) throws DataSourceException {
        try {
            return new JsonToThingConverter<Listing<Link>>()
                    .convert(dataSource.getLinks(subreddit));
        } catch (ThingFactoryException e) {
            throw new DataSourceException("Could not parse links for subreddit: " + subreddit, e);
        }
    }

    public Listing<? extends Thing> getCommentsForLink(Link link) throws DataSourceException {
        try {
            return new JsonToThingConverter<Listing<? extends Thing>>().convert(dataSource
                    .getComments(link.getPermalink()));
        } catch (ThingFactoryException e) {
            throw new DataSourceException("Could not parse comments for link: " + link, e);
        }
    }

    public Subreddit getSubreddit(String subreddit) throws DataSourceException {
        try {
            return new JsonToThingConverter<Subreddit>()
                    .convert(dataSource.getSubreddit(subreddit));
        } catch (ThingFactoryException e) {
            throw new DataSourceException("Could not parse subreddits from JSON.", e);
        }
    }

    public Listing<Subreddit> getDefaultSubreddits() throws DataSourceException {
        try {
            return new JsonToThingConverter<Listing<Subreddit>>().convert(dataSource
                    .getDefaultSubreddits());
        } catch (ThingFactoryException e) {
            throw new DataSourceException("Could not parse subreddits from JSON.", e);
        }
    }

    public Listing<Link> getLinksForFrontPage() throws DataSourceException {
        try {
            return new JsonToThingConverter<Listing<Link>>().convert(dataSource
                    .getLinksForFrontPage());
        } catch (ThingFactoryException e) {
            throw new DataSourceException("Could not parse links for front page.", e);
        }
    }

    JsonDataSource getDataSource() {
        return dataSource;
    }

    void setDataSource(JsonDataSource dataSource) {
        this.dataSource = dataSource;
    }
}




Java Source Code List

com.pocketreddit.library.Constants.java
com.pocketreddit.library.Created.java
com.pocketreddit.library.JsonParsingException.java
com.pocketreddit.library.Votable.java
com.pocketreddit.library.authentication.AuthenticationException.java
com.pocketreddit.library.authentication.Authenticator.java
com.pocketreddit.library.authentication.LiveAuthenticator.java
com.pocketreddit.library.authentication.LoginResult.java
com.pocketreddit.library.datasources.DataSourceException.java
com.pocketreddit.library.datasources.JsonDataSource.java
com.pocketreddit.library.datasources.LiveDataSource.java
com.pocketreddit.library.datasources.RedditDataSource.java
com.pocketreddit.library.net.HttpHelper.java
com.pocketreddit.library.net.NetException.java
com.pocketreddit.library.things.Account.java
com.pocketreddit.library.things.Comment.java
com.pocketreddit.library.things.Kind.java
com.pocketreddit.library.things.Link.java
com.pocketreddit.library.things.Listing.java
com.pocketreddit.library.things.Message.java
com.pocketreddit.library.things.More.java
com.pocketreddit.library.things.Subreddit.java
com.pocketreddit.library.things.Thing.java
com.pocketreddit.library.things.UserSubmittedContent.java
com.pocketreddit.library.things.factories.CommentFactory.java
com.pocketreddit.library.things.factories.LinkFactory.java
com.pocketreddit.library.things.factories.ListingFactory.java
com.pocketreddit.library.things.factories.SubredditFactory.java
com.pocketreddit.library.things.factories.ThingFactoryException.java
com.pocketreddit.library.things.factories.ThingFactory.java
com.pocketreddit.library.things.utils.JsonToThingConverter.java
com.pocketreddit.library.utils.StreamUtils.java
com.pocketreddit.library.utils.UtilsException.java