// Path: src/com/pocketreddit/library/net/HttpHelper.java
// public class HttpHelper {
//     private static final String TAG = HttpHelper.class.getName();
//     private static final String SCHEME_SSL = "https";
//     private static final int SCHEME_PORT_SSL = 443;
// 
//     private static HttpHelper instance;
// 
//     private HttpHelper() {
//     }
// 
//     public static HttpHelper getInstance() {
//         if (instance == null)
//             instance = new HttpHelper();
// 
//         return instance;
//     }
// 
//     public JSONObject getJsonObjectFromGet(String uri, List<Cookie> cookies) throws NetException {
//         HttpClient client = buildHttpClient(cookies);
// 
//         try {
//             return getJsonObjectFromResponse(client.execute(new HttpGet(uri)));
//         } catch (Exception e) {
//             throw new NetException("Error while parsing GET response from " + uri
//                     + " into JSON object: " + e.getMessage(), e);
//         }
//     }
// 
//     private HttpClient buildHttpClient(List<Cookie> cookies) {
//         DefaultHttpClient client = new DefaultHttpClient();
// 
//         String userAgent = System.getProperty(Constants.SYSTEM_PROPERTY_USER_AGENT);
// 
//         if (userAgent != null)
//             client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, userAgent);
// 
//         if (cookies != null && !cookies.isEmpty()) {
//             client.setCookieStore(buildCookieStore(cookies));
//         }
// 
//         return client;
//     }
// 
//     private CookieStore buildCookieStore(List<Cookie> cookies) {
//         Cookie[] cookieArray = new Cookie[cookies.size()];
//         return buildCookieStore(cookies.toArray(cookieArray));
//     }
// 
//     private CookieStore buildCookieStore(Cookie... cookies) {
//         CookieStore cookieStore = new BasicCookieStore();
//         for (Cookie cookie : cookies) {
//             cookieStore.addCookie(cookie);
//         }
// 
//         return cookieStore;
//     }
// 
//     private JSONArray getJsonArrayFromResponse(HttpResponse response) throws IllegalStateException,
//             JSONException, IOException, UtilsException {
//         return new JSONArray(responseToString(response));
//     }
// 
//     private String responseToString(HttpResponse response) throws IOException,
//             IllegalStateException, UtilsException {
//         InputStream is = null;
//         try {
//             is = response.getEntity().getContent();
//             String content = StreamUtils.getInstance().convertStreamToString(is);
// 
//             String contentSnippet;
//             if (content.length() > 250) {
//                 contentSnippet = content.substring(0, 100) + "###SNIPPET###"
//                         + content.substring(content.length() - 100);
//             } else {
//                 contentSnippet = content;
//             }
// 
//             Log.v(TAG, "stream content: " + contentSnippet);
//             return content;
//         } finally {
//             if (is != null)
//                 is.close();
//         }
//     }
// 
//     private JSONObject getJsonObjectFromResponse(HttpResponse response)
//             throws IllegalStateException, IOException, JSONException, UtilsException {
//         return new JSONObject(responseToString(response));
//     }
// 
//     public JSONArray getJsonArrayFromGet(String uri, List<Cookie> cookies) throws NetException {
//         HttpClient client = buildHttpClient(cookies);
// 
//         try {
//             return getJsonArrayFromResponse(client.execute(new HttpGet(uri)));
//         } catch (Exception e) {
//             throw new NetException("Could not parse response into JSON array.", e);
//         }
//     }
// 
//     public JSONArray getJsonArrayFromGet(String uri) throws NetException {
//         return getJsonArrayFromGet(uri, null);
//     }
// 
//     public JSONObject getJsonObjectFromGet(String uri) throws NetException {
//         return getJsonObjectFromGet(uri, null);
//     }
// 
//     public JSONObject getJsonObjectFromPost(URI uri, List<NameValuePair> params)
//             throws NetException {
//         return getJsonObjectFromPost(uri, params, null);
//     }
// 
//     public JSONObject getJsonObjectFromPost(URI uri, List<NameValuePair> params,
//             List<Cookie> cookies) throws NetException {
//         HttpClient httpClient = buildHttpClient(cookies);
// 
//         if (SCHEME_SSL.equals(uri.getScheme())) {
//             HostnameVerifier hostnameVerifier = SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;
// 
//             SchemeRegistry registry = new SchemeRegistry();
//             SSLSocketFactory sslFactory = SSLSocketFactory.getSocketFactory();
//             sslFactory.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier);
//             registry.register(new Scheme(SCHEME_SSL, sslFactory, SCHEME_PORT_SSL));
//             SingleClientConnManager connectManager = new SingleClientConnManager(
//                     httpClient.getParams(), registry);
// 
//             httpClient = new DefaultHttpClient(connectManager, httpClient.getParams());
//             HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier);
//         }
// 
//         HttpPost post = new HttpPost(uri);
// 
//         try {
//             post.setEntity(new UrlEncodedFormEntity(params));
//             return getJsonObjectFromResponse(httpClient.execute(post));
//         } catch (Exception e) {
//             throw new NetException("Error while parsing POST response from " + uri
//                     + " into JSON object.", e);
//         }
//     }
// }


import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import android.util.Log;
import com.pocketreddit.library.net.HttpHelper;
package com.pocketreddit.library.authentication;





public class LiveAuthenticator implements Authenticator {
    private static final String TAG = LiveAuthenticator.class.getName();

    private static final String LOGIN_URI = "https://ssl.reddit.com/api/login";
    private static final String PARAM_USERNAME = "user";
    private static final String PARAM_PASSWORD = "passwd";

    private static final String PARAM_API_TYPE = "api_type";
    private static final String API_TYPE_JSON = "json";

    public LoginResult authenticate(String username, String password)
            throws AuthenticationException {
        try {
// Path: src/com/pocketreddit/library/net/HttpHelper.java
// public class HttpHelper {
//     private static final String TAG = HttpHelper.class.getName();
//     private static final String SCHEME_SSL = "https";
//     private static final int SCHEME_PORT_SSL = 443;
// 
//     private static HttpHelper instance;
// 
//     private HttpHelper() {
//     }
// 
//     public static HttpHelper getInstance() {
//         if (instance == null)
//             instance = new HttpHelper();
// 
//         return instance;
//     }
// 
//     public JSONObject getJsonObjectFromGet(String uri, List<Cookie> cookies) throws NetException {
//         HttpClient client = buildHttpClient(cookies);
// 
//         try {
//             return getJsonObjectFromResponse(client.execute(new HttpGet(uri)));
//         } catch (Exception e) {
//             throw new NetException("Error while parsing GET response from " + uri
//                     + " into JSON object: " + e.getMessage(), e);
//         }
//     }
// 
//     private HttpClient buildHttpClient(List<Cookie> cookies) {
//         DefaultHttpClient client = new DefaultHttpClient();
// 
//         String userAgent = System.getProperty(Constants.SYSTEM_PROPERTY_USER_AGENT);
// 
//         if (userAgent != null)
//             client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, userAgent);
// 
//         if (cookies != null && !cookies.isEmpty()) {
//             client.setCookieStore(buildCookieStore(cookies));
//         }
// 
//         return client;
//     }
// 
//     private CookieStore buildCookieStore(List<Cookie> cookies) {
//         Cookie[] cookieArray = new Cookie[cookies.size()];
//         return buildCookieStore(cookies.toArray(cookieArray));
//     }
// 
//     private CookieStore buildCookieStore(Cookie... cookies) {
//         CookieStore cookieStore = new BasicCookieStore();
//         for (Cookie cookie : cookies) {
//             cookieStore.addCookie(cookie);
//         }
// 
//         return cookieStore;
//     }
// 
//     private JSONArray getJsonArrayFromResponse(HttpResponse response) throws IllegalStateException,
//             JSONException, IOException, UtilsException {
//         return new JSONArray(responseToString(response));
//     }
// 
//     private String responseToString(HttpResponse response) throws IOException,
//             IllegalStateException, UtilsException {
//         InputStream is = null;
//         try {
//             is = response.getEntity().getContent();
//             String content = StreamUtils.getInstance().convertStreamToString(is);
// 
//             String contentSnippet;
//             if (content.length() > 250) {
//                 contentSnippet = content.substring(0, 100) + "###SNIPPET###"
//                         + content.substring(content.length() - 100);
//             } else {
//                 contentSnippet = content;
//             }
// 
//             Log.v(TAG, "stream content: " + contentSnippet);
//             return content;
//         } finally {
//             if (is != null)
//                 is.close();
//         }
//     }
// 
//     private JSONObject getJsonObjectFromResponse(HttpResponse response)
//             throws IllegalStateException, IOException, JSONException, UtilsException {
//         return new JSONObject(responseToString(response));
//     }
// 
//     public JSONArray getJsonArrayFromGet(String uri, List<Cookie> cookies) throws NetException {
//         HttpClient client = buildHttpClient(cookies);
// 
//         try {
//             return getJsonArrayFromResponse(client.execute(new HttpGet(uri)));
//         } catch (Exception e) {
//             throw new NetException("Could not parse response into JSON array.", e);
//         }
//     }
// 
//     public JSONArray getJsonArrayFromGet(String uri) throws NetException {
//         return getJsonArrayFromGet(uri, null);
//     }
// 
//     public JSONObject getJsonObjectFromGet(String uri) throws NetException {
//         return getJsonObjectFromGet(uri, null);
//     }
// 
//     public JSONObject getJsonObjectFromPost(URI uri, List<NameValuePair> params)
//             throws NetException {
//         return getJsonObjectFromPost(uri, params, null);
//     }
// 
//     public JSONObject getJsonObjectFromPost(URI uri, List<NameValuePair> params,
//             List<Cookie> cookies) throws NetException {
//         HttpClient httpClient = buildHttpClient(cookies);
// 
//         if (SCHEME_SSL.equals(uri.getScheme())) {
//             HostnameVerifier hostnameVerifier = SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;
// 
//             SchemeRegistry registry = new SchemeRegistry();
//             SSLSocketFactory sslFactory = SSLSocketFactory.getSocketFactory();
//             sslFactory.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier);
//             registry.register(new Scheme(SCHEME_SSL, sslFactory, SCHEME_PORT_SSL));
//             SingleClientConnManager connectManager = new SingleClientConnManager(
//                     httpClient.getParams(), registry);
// 
//             httpClient = new DefaultHttpClient(connectManager, httpClient.getParams());
//             HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier);
//         }
// 
//         HttpPost post = new HttpPost(uri);
// 
//         try {
//             post.setEntity(new UrlEncodedFormEntity(params));
//             return getJsonObjectFromResponse(httpClient.execute(post));
//         } catch (Exception e) {
//             throw new NetException("Error while parsing POST response from " + uri
//                     + " into JSON object.", e);
//         }
//     }
// }


// Path: src/com/pocketreddit/library/authentication/LiveAuthenticator.java
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import android.util.Log;
import com.pocketreddit.library.net.HttpHelper;

package com.pocketreddit.library.authentication;





public class LiveAuthenticator implements Authenticator {
    private static final String TAG = LiveAuthenticator.class.getName();

    private static final String LOGIN_URI = "https://ssl.reddit.com/api/login";
    private static final String PARAM_USERNAME = "user";
    private static final String PARAM_PASSWORD = "passwd";

    private static final String PARAM_API_TYPE = "api_type";
    private static final String API_TYPE_JSON = "json";

    public LoginResult authenticate(String username, String password)
            throws AuthenticationException {
        try {
            return new LoginResult(HttpHelper.getInstance().getJsonObjectFromPost(