Android Open Source - pocket4android Retrieve Request






From Project

Back to project page pocket4android.

License

The source code is released under:

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, includin...

If you think the Android project pocket4android 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

/*
 * Copyright (c) 2012-2014 Yu AOKI//from ww w.  jav  a 2  s . c o m
 *
 * This software may be modified and distributed under the terms
 * of the MIT license.  See the LICENSE file for details.
 */

package com.aokyu.dev.pocket;

public class RetrieveRequest extends Request {

    private RetrieveRequest() {}

    /* package */ String getAccessToken() {
        return (String) get(RetrieveRequestParameter.ACCESS_TOKEN);
    }

    /* package */ String getConsumerKey() {
        return (String) get(RetrieveRequestParameter.CONSUMER_KEY);
    }

    public boolean hasPageState() {
        return containsKey(RetrieveRequestParameter.STATE);
    }

    public String getPageState() {
        return (String) get(RetrieveRequestParameter.STATE);
    }

    public boolean hasFavorited() {
        return containsKey(RetrieveRequestParameter.FAVORITE);
    }

    public boolean getFavorited() {
        int favorited = -1;
        try {
            favorited = Integer.parseInt((String) get(RetrieveRequestParameter.FAVORITE));
            if (favorited == RetrieveRequestParameter.Favorite.FAVORITED) {
                return true;
            }
        } catch (NumberFormatException e) {}
        return false;
    }

    public boolean hasTag() {
        return containsKey(RetrieveRequestParameter.TAG);
    }

    public String getTag() {
        return (String) get(RetrieveRequestParameter.TAG);
    }

    public boolean hasContentType() {
        return containsKey(RetrieveRequestParameter.CONTENT_TYPE);
    }

    public String getContentType() {
        return (String) get(RetrieveRequestParameter.CONTENT_TYPE);
    }

    public boolean hasSort() {
        return containsKey(RetrieveRequestParameter.SORT);
    }

    public String getSort() {
        return (String) get(RetrieveRequestParameter.SORT);
    }

    public boolean hasDetailType() {
        return containsKey(RetrieveRequestParameter.DETAIL_TYPE);
    }

    public String getDetailType() {
        return (String) get(RetrieveRequestParameter.DETAIL_TYPE);
    }

    public boolean hasSearch() {
        return containsKey(RetrieveRequestParameter.SEARCH);
    }

    public String getSearch() {
        return (String) get(RetrieveRequestParameter.SEARCH);
    }

    public boolean hasDomain() {
        return containsKey(RetrieveRequestParameter.DOMAIN);
    }

    public String getDomain() {
        return (String) get(RetrieveRequestParameter.DOMAIN);
    }

    public boolean hasSince() {
        return containsKey(RetrieveRequestParameter.SINCE);
    }

    public long getSince() {
        long since = -1;
        try {
            since = Long.parseLong((String) get(RetrieveRequestParameter.SINCE));
        } catch (NumberFormatException e) {}

        return since;
    }

    public boolean hasCount() {
        return containsKey(RetrieveRequestParameter.COUNT);
    }

    public int getCount() {
        int count = -1;
        try {
            count = Integer.parseInt((String) get(RetrieveRequestParameter.COUNT));
        } catch (NumberFormatException e) {}

        return count;
    }

    public boolean hasOffset() {
        return containsKey(RetrieveRequestParameter.OFFSET);
    }

    public int getOffset() {
        int offset = -1;
        try {
            offset = Integer.parseInt((String) get(RetrieveRequestParameter.OFFSET));
        } catch (NumberFormatException e) {}

        return offset;
    }

    public static class Builder {

        private RetrieveRequest mRequest = new RetrieveRequest();

        public Builder() {}

        /* package */ Builder(String accessToken, String consumerKey, String url) {
            this();
            mRequest.put(RetrieveRequestParameter.ACCESS_TOKEN, accessToken);
            mRequest.put(RetrieveRequestParameter.CONSUMER_KEY, consumerKey);
        }

        /* package */ Builder setAccessToken(String accessToken) {
            mRequest.put(RetrieveRequestParameter.ACCESS_TOKEN, accessToken);
            return this;
        }

        /* package */ Builder setConsumerKey(String consumerKey) {
            mRequest.put(RetrieveRequestParameter.CONSUMER_KEY, consumerKey);
            return this;
        }

        public Builder setState(String state) {
            if (state.equals(RetrieveRequestParameter.State.ARCHIVE) ||
                    state.equals(RetrieveRequestParameter.State.UNREAD) ||
                    state.equals(RetrieveRequestParameter.State.ALL)) {
                mRequest.put(RetrieveRequestParameter.STATE, state);
            } else {
                throw new IllegalArgumentException();
            }
            return this;
        }

        public Builder setFavorited(boolean favorited) {
            int state = 0;
            if(favorited) {
                state = 1;
            }
            mRequest.put(RetrieveRequestParameter.FAVORITE, state);
            return this;
        }

        public Builder setTag(String tag) {
            mRequest.put(RetrieveRequestParameter.TAG, tag);
            return this;
        }

        public Builder setContentType(String contentType) {
            if (contentType.equals(RetrieveRequestParameter.ContentType.ARTICLE) ||
                    contentType.equals(RetrieveRequestParameter.ContentType.IMAGE) ||
                    contentType.equals(RetrieveRequestParameter.ContentType.VIDEO)) {
                mRequest.put(RetrieveRequestParameter.CONTENT_TYPE, contentType);
            } else {
                throw new IllegalArgumentException();
            }

            return this;
        }

        public Builder setSort(String sort) {
            if (sort.equals(RetrieveRequestParameter.Sort.NEWEST) ||
                    sort.equals(RetrieveRequestParameter.Sort.OLDEST) ||
                    sort.equals(RetrieveRequestParameter.Sort.SITE) ||
                    sort.equals(RetrieveRequestParameter.Sort.TITLE)) {
                mRequest.put(RetrieveRequestParameter.SORT, sort);
            } else {
                throw new IllegalArgumentException();
            }
            return this;
        }

        public Builder setDetailType(String type) {
            if (type.equals(RetrieveRequestParameter.DetailType.SIMPLE) ||
                    type.equals(RetrieveRequestParameter.DetailType.COMPLETE)) {
                mRequest.put(RetrieveRequestParameter.DETAIL_TYPE, type);
            } else {
                throw new IllegalArgumentException();
            }
            return this;
        }

        public Builder setSearch(String term) {
            mRequest.put(RetrieveRequestParameter.SEARCH, term);
            return this;
        }

        public Builder setDomain(String domain) {
            mRequest.put(RetrieveRequestParameter.DOMAIN, domain);
            return this;
        }

        public Builder setSince(long since) {
            mRequest.put(RetrieveRequestParameter.SINCE, since);
            return this;
        }

        public Builder setCount(int count) {
            mRequest.put(RetrieveRequestParameter.COUNT, count);
            return this;
        }

        public Builder setOffset(int offset) {
            mRequest.put(RetrieveRequestParameter.OFFSET, offset);
            return this;
        }

        public RetrieveRequest build() {
            return mRequest;
        }
    }
}




Java Source Code List

com.aokyu.dev.pocket.AccessToken.java
com.aokyu.dev.pocket.AddRequest.java
com.aokyu.dev.pocket.AddResponse.java
com.aokyu.dev.pocket.AuthCallbackActivity.java
com.aokyu.dev.pocket.AuthRequestParameter.java
com.aokyu.dev.pocket.AuthResponseParameter.java
com.aokyu.dev.pocket.AuthorizationCallback.java
com.aokyu.dev.pocket.ClientLimit.java
com.aokyu.dev.pocket.ConsumerKey.java
com.aokyu.dev.pocket.ModifyRequest.java
com.aokyu.dev.pocket.ModifyResponse.java
com.aokyu.dev.pocket.PocketClient.java
com.aokyu.dev.pocket.PocketServer.java
com.aokyu.dev.pocket.RateLimit.java
com.aokyu.dev.pocket.RequestToken.java
com.aokyu.dev.pocket.Request.java
com.aokyu.dev.pocket.Response.java
com.aokyu.dev.pocket.RetrieveRequestParameter.java
com.aokyu.dev.pocket.RetrieveRequest.java
com.aokyu.dev.pocket.RetrieveResponse.java
com.aokyu.dev.pocket.UserLimit.java
com.aokyu.dev.pocket.content.Image.java
com.aokyu.dev.pocket.content.MediaItem.java
com.aokyu.dev.pocket.content.Page.java
com.aokyu.dev.pocket.content.PocketItem.java
com.aokyu.dev.pocket.content.Video.java
com.aokyu.dev.pocket.error.ErrorCode.java
com.aokyu.dev.pocket.error.ErrorHandler.java
com.aokyu.dev.pocket.error.ErrorResponse.java
com.aokyu.dev.pocket.error.InvalidRequestException.java
com.aokyu.dev.pocket.error.PocketException.java
com.aokyu.dev.pocket.http.ContentType.java
com.aokyu.dev.pocket.http.HttpClient.java
com.aokyu.dev.pocket.http.HttpHeader.java
com.aokyu.dev.pocket.http.HttpHeaders.java
com.aokyu.dev.pocket.http.HttpMethod.java
com.aokyu.dev.pocket.http.HttpParameters.java
com.aokyu.dev.pocket.http.HttpRequest.java
com.aokyu.dev.pocket.http.HttpResponse.java
com.aokyu.dev.pocket.http.MessageBody.java
com.aokyu.dev.pocket.util.HttpUtils.java
com.aokyu.dev.pocket.util.JSONUtils.java
com.aokyu.dev.pocket.util.PocketUtils.java
com.hyperionics.PocketTest.AndyUtil.java
com.hyperionics.PocketTestBrowser.AndyUtil.java
com.hyperionics.PocketTestBrowser.Lt.java
com.hyperionics.PocketTestBrowser.PocketActivity.java
com.hyperionics.PocketTest.Lt.java
com.hyperionics.PocketTest.PocketActivity.java
com.hyperionics.PocketTest.SimpleBrowser.java