// Path: src/com/Upwork/api/Routers/Organization/Users.java
// @ClassPreamble (
// 	author = "Maksym Novozhylov <mnovozhilov@upwork.com>",
// 	date = "6/4/2014",
// 	currentRevision = 1,
// 	lastModified = "10/13/2014",
// 	lastModifiedBy = "Maksym Novozhylov",
// 	reviewers = {"Yiota Tsakiri"}
// )
// public final class Users {
// 	
// 	final static String ENTRY_POINT = "api";
// 	
// 	private OAuthClient oClient = null;
// 
// 	public Users(OAuthClient client) {
// 		oClient = client;
// 		oClient.setEntryPoint(ENTRY_POINT);
// 	}
// 	
// 	/** 
//      * Get Auth User Info
//      *
//      * @throws	JSONException If error occurred
// 	 * @return	{@link JSONObject}
//      */
//     public JSONObject getMyInfo() throws JSONException {   
//         return oClient.get("/hr/v2/users/me");
//     }
// 	
// 	/** 
//      * Get Specific User Info
//      *
//      * @param   userReference User reference
//      * @throws	JSONException If error occurred
// 	 * @return	{@link JSONObject}
//      */
//     public JSONObject getSpecific(String userReference) throws JSONException {   
//         return oClient.get("/hr/v2/users/" + userReference);
//     }
// 
// }


import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
import android.widget.Button;
import android.widget.Toast;
import java.util.HashMap;
import java.util.Properties;
import com.Upwork.api.*;
import com.Upwork.api.Routers.Organization.Users;
import org.json.JSONException;
import org.json.JSONObject;
import oauth.signpost.OAuth;
    class UpworkRetrieveAccessTokenTask extends AsyncTask<String, Void, String> {
        @Override
        protected String doInBackground(String... params) {
            String verifier = params[0];

            HashMap<String, String> token = client.getAccessTokenSet(verifier);
            client.setTokenWithSecret(token.get("token"), token.get("secret"));

            // Save token/secret in preferences
            prefs.edit().putString("token", token.get("token"))
                        .putString("secret", token.get("secret"))
                        .commit();

            return "ok - token is: " + prefs.getString("token", null);
        }

        @Override
        protected void onPostExecute(String result) {
            super.onPostExecute(result);
            if (result != null) {
                Toast.makeText(MyActivity.this, result, Toast.LENGTH_LONG).show();
            }
        }
    }

    class GetMyUIdTask extends AsyncTask<Void, Void, String> {
        @Override
        protected String doInBackground(Void... params) {
            JSONObject json = null;
            String token = prefs.getString("token", null);
// Path: src/com/Upwork/api/Routers/Organization/Users.java
// @ClassPreamble (
// 	author = "Maksym Novozhylov <mnovozhilov@upwork.com>",
// 	date = "6/4/2014",
// 	currentRevision = 1,
// 	lastModified = "10/13/2014",
// 	lastModifiedBy = "Maksym Novozhylov",
// 	reviewers = {"Yiota Tsakiri"}
// )
// public final class Users {
// 	
// 	final static String ENTRY_POINT = "api";
// 	
// 	private OAuthClient oClient = null;
// 
// 	public Users(OAuthClient client) {
// 		oClient = client;
// 		oClient.setEntryPoint(ENTRY_POINT);
// 	}
// 	
// 	/** 
//      * Get Auth User Info
//      *
//      * @throws	JSONException If error occurred
// 	 * @return	{@link JSONObject}
//      */
//     public JSONObject getMyInfo() throws JSONException {   
//         return oClient.get("/hr/v2/users/me");
//     }
// 	
// 	/** 
//      * Get Specific User Info
//      *
//      * @param   userReference User reference
//      * @throws	JSONException If error occurred
// 	 * @return	{@link JSONObject}
//      */
//     public JSONObject getSpecific(String userReference) throws JSONException {   
//         return oClient.get("/hr/v2/users/" + userReference);
//     }
// 
// }


// Path: example-android/app/src/main/java/com/upwork/example_upworkapi/MyActivity.java
import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
import android.widget.Button;
import android.widget.Toast;
import java.util.HashMap;
import java.util.Properties;
import com.Upwork.api.*;
import com.Upwork.api.Routers.Organization.Users;
import org.json.JSONException;
import org.json.JSONObject;
import oauth.signpost.OAuth;

    class UpworkRetrieveAccessTokenTask extends AsyncTask<String, Void, String> {
        @Override
        protected String doInBackground(String... params) {
            String verifier = params[0];

            HashMap<String, String> token = client.getAccessTokenSet(verifier);
            client.setTokenWithSecret(token.get("token"), token.get("secret"));

            // Save token/secret in preferences
            prefs.edit().putString("token", token.get("token"))
                        .putString("secret", token.get("secret"))
                        .commit();

            return "ok - token is: " + prefs.getString("token", null);
        }

        @Override
        protected void onPostExecute(String result) {
            super.onPostExecute(result);
            if (result != null) {
                Toast.makeText(MyActivity.this, result, Toast.LENGTH_LONG).show();
            }
        }
    }

    class GetMyUIdTask extends AsyncTask<Void, Void, String> {
        @Override
        protected String doInBackground(Void... params) {
            JSONObject json = null;
            String token = prefs.getString("token", null);
            Users users = new Users(client);