All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.feedhenry.sdk.FHRemote Maven / Gradle / Ivy

There is a newer version: 4.0.0
Show newest version
/**
 * Copyright Red Hat, Inc, and individual contributors.
 *
 * 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.
 */
package com.feedhenry.sdk;

import android.content.Context;
import com.feedhenry.sdk.utils.FHLog;
import com.feedhenry.sdk.utils.StringUtils;
import cz.msebera.android.httpclient.Header;
import org.json.fh.JSONObject;

/**
 * The base class that implements {@link FHAct}.
 */
public abstract class FHRemote implements FHAct {

    public static final String PATH_PREFIX = "/box/srv/1.1/";

    protected static String LOG_TAG = "com.feedhenry.sdk.FHRemote";

    private final com.feedhenry.sdk2.FHHttpClient mHttpClient = new com.feedhenry.sdk2.FHHttpClient();
    
    protected FHActCallback mCallback;
    protected Context mContext;

    public FHRemote(Context context) {
        mContext = context;
    }

    @Override
    public void executeAsync() {
        executeAsync(mCallback);
    }

    @Override
    public void executeAsync(FHActCallback pCallback) {
        mHttpClient.post(getApiURl(), buildHeaders(null), getRequestArgs(), pCallback, false);
    }

    @Override
    public void execute(FHActCallback pCallback) {
        mHttpClient.post(getApiURl(), buildHeaders(null), getRequestArgs(), pCallback, true);
    }

    public void setCallback(FHActCallback pCallback) {
        mCallback = pCallback;
    }

    protected String getApiURl() {
        String apiUrl = StringUtils.removeTrailingSlash(AppProps.getInstance().getHost());
        return apiUrl + PATH_PREFIX + getPath();
    }

    protected abstract String getPath();

    protected abstract JSONObject getRequestArgs();

    protected abstract Header[] buildHeaders(Header[] pHeaders);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy