jp.co.rakuten.rakutenvideoplayer.api.Api_PermitOauth.java Source code

Java tutorial

Introduction

Here is the source code for jp.co.rakuten.rakutenvideoplayer.api.Api_PermitOauth.java

Source

package jp.co.rakuten.rakutenvideoplayer.api;

import java.io.Reader;
import java.util.List;

import jp.co.rakuten.rakutenvideoplayer.connection.ServerConnection;
import jp.co.rakuten.rakutenvideoplayer.interfaceproject.UpdateData;
import jp.co.rakuten.rakutenvideoplayer.model.Model_LicenseCode;
import jp.co.rakuten.rakutenvideoplayer.model.play.PlayModel;
import jp.co.rakuten.rakutenvideoplayer.util.APIExceptionUtil;
import jp.co.rakuten.rakutenvideoplayer.util.Constant;
import jp.co.rakuten.rakutenvideoplayer.util.Constant.API;
import jp.co.rakuten.rakutenvideoplayer.util.DLog;

import org.apache.http.NameValuePair;

import android.os.AsyncTask;

/**
 * 
 * @author nguyenvantu
 *
 */
public class Api_PermitOauth extends AsyncTask<List<NameValuePair>, String, Model_LicenseCode> {
    private String API_NAME = "/oauth/code.json";
    private UpdateData context;
    private API ERROR = API.NO_ERROR;
    private int type = Constant.GET;

    public Api_PermitOauth(UpdateData context) {
        this.context = context;
    }

    @Override
    protected Model_LicenseCode doInBackground(List<NameValuePair>... params) {
        // TODO Auto-generated method stub
        ServerConnection connect = new ServerConnection(Constant.URL, API_NAME, params[0], type);
        Reader json_con;
        Model_LicenseCode model = null;
        try {

            json_con = connect.connect();
            Parser parser = new Parser(API.PERMITOAUTH);
            if (json_con != null) {
                model = (Model_LicenseCode) parser.getModel(json_con);

            }
        } catch (Exception e) {

            e.printStackTrace();
            ERROR = APIExceptionUtil.detectAPIError(e);
        }

        return model;

    }

    @Override
    protected void onPostExecute(Model_LicenseCode result) {
        // TODO Auto-generated method stub
        if (context != null) {
            if (ERROR.equals(API.NO_ERROR)) {
                context.receiveData(result, Constant.API.PERMITOAUTH);
                if (result == null) {
                    DLog.e("KOP", "null");
                }
            } else {
                context.receiveData(result, ERROR);
            }
        }
        super.onPostExecute(result);
    }

}