Android Open Source - savemypics C Snapfish User






From Project

Back to project page savemypics.

License

The source code is released under:

Copyright (c) 2014, KB Sriram All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. R...

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

package org.savemypics.plugin.snapfish;
/*  w  ww . j a  va2s.c  o  m*/
import java.io.IOException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import org.json.JSONException;
import org.json.JSONObject;
import org.savemypics.plugin.CIOUtils;
import org.savemypics.plugin.CPlugin;

public final class CSnapfishUser
{
    public final static class AppCredentials
    {
        public AppCredentials(String aid, String asecret)
        {
            m_aid = aid;
            m_asecret = asecret;
        }
        private final String m_aid;
        private final String m_asecret;
    }

    public final static CPlugin.Tokens login
        (AppCredentials acred, String email, String pass)
        throws IOException, CPlugin.AuthorizationException
    {
        Map<String,String> params = new HashMap<String,String>();
        params.put("grant_type", "password");
        params.put("username", email);
        params.put("password", pass);
        addAppParams(params, acred);
        return handleRefresh(params);
    }

    public final static CPlugin.Tokens refresh
        (AppCredentials acred, String refresh)
        throws IOException, CPlugin.AuthorizationException
    {
        Map<String,String> params = new HashMap<String,String>();
        String rtok;
        try {
            rtok = (new JSONObject(refresh)).getString("refresh_token");
        }
        catch (JSONException jse) {
            throw CIOUtils.asAuthorizationException(refresh, jse);
        }

        params.put("grant_type", "refresh_token");
        params.put("refresh_token", rtok);
        addAppParams(params, acred);
        return handleRefresh(params);
    }

    private final static CPlugin.Tokens handleRefresh
        (Map<String,String> params)
        throws IOException, CPlugin.AuthorizationException
    {
        JSONObject refresh = CSnapfishUtils.doOAuthPost
            (new URL(TOKEN_URL), null, params,
             "application/x-www-form-urlencoded");
        // Stringify the json and use that as the 'permanent' token.
        // Copy just the necessary bits of the response and use that
        // as the 'temporary' token
        try {
            JSONObject access = new JSONObject();
            copyString("access_token", refresh, access);
            copyString("upload_end_point", refresh, access);
            copyString("rest_end_point", refresh, access);
            return new CPlugin.Tokens(refresh.toString(), access.toString());
        }
        catch (JSONException jse) {
            // This is unexpected. But treat it as a transient
            // failure for the moment until proved otherwise.
            throw CIOUtils.asIOException(refresh.toString(), jse);
        }
    }

    private static void addAppParams
        (Map<String,String> params, AppCredentials acred)
    {
        params.put("client_id", acred.m_aid);
        params.put("client_secret", acred.m_asecret);
    }

    private final static void copyString
        (String k, JSONObject src, JSONObject dest)
        throws JSONException
    { dest.put(k, src.getString(k)); }

    private final static String TOKEN_URL =
        "https://openapi.snapfish.com/services/access_token/v2";
}




Java Source Code List

android.util.Base64.java
org.savemypics.android.activity.AActivity.java
org.savemypics.android.activity.ABaseSettingsActivity.java
org.savemypics.android.activity.CAccountInfoListAdapter.java
org.savemypics.android.activity.CFlickrSettingsActivity.java
org.savemypics.android.activity.CSnapfishSettingsActivity.java
org.savemypics.android.activity.CStartActivity.java
org.savemypics.android.authenticator.AAuthenticatorActivity.java
org.savemypics.android.authenticator.CAuthenticationService.java
org.savemypics.android.authenticator.CAuthenticator.java
org.savemypics.android.authenticator.CFlickrLoginHookActivity.java
org.savemypics.android.authenticator.CFlickrWebActivity.java
org.savemypics.android.authenticator.CSelectProviderActivity.java
org.savemypics.android.authenticator.CSnapfishLoginActivity.java
org.savemypics.android.db.CAccount.java
org.savemypics.android.db.CDb.java
org.savemypics.android.db.CLocalImage.java
org.savemypics.android.db.CMap.java
org.savemypics.android.db.CRemoteImage.java
org.savemypics.android.event.AEvent.java
org.savemypics.android.event.CEventBus.java
org.savemypics.android.event.CExceptionEvent.java
org.savemypics.android.glue.ABaseGlue.java
org.savemypics.android.glue.CFlickrGlue.java
org.savemypics.android.glue.CSnapfishGlue.java
org.savemypics.android.receiver.CNetworkChangeReceiver.java
org.savemypics.android.service.CTaskQueue.java
org.savemypics.android.sync.CMediaUtils.java
org.savemypics.android.sync.CSyncAdapter.java
org.savemypics.android.sync.CSyncService.java
org.savemypics.android.sync.CSyncUtils.java
org.savemypics.android.util.CBitmapUtils.java
org.savemypics.android.util.CFileCache.java
org.savemypics.android.util.CLruCache.java
org.savemypics.android.util.CUtils.java
org.savemypics.android.util.CUtils.java
org.savemypics.android.view.CMaximumWidthLayout.java
org.savemypics.android.view.CModularLayout.java
org.savemypics.android.view.CRefreshButton.java
org.savemypics.android.view.CRoundedBitmapView.java
org.savemypics.android.view.CStatusCounterView.java
org.savemypics.plugin.CIOUtils.java
org.savemypics.plugin.CPlugin.java
org.savemypics.plugin.flickr.CFlickrAlbum.java
org.savemypics.plugin.flickr.CFlickrUtils.java
org.savemypics.plugin.snapfish.CSnapfishAlbum.java
org.savemypics.plugin.snapfish.CSnapfishFeed.java
org.savemypics.plugin.snapfish.CSnapfishUser.java
org.savemypics.plugin.snapfish.CSnapfishUtils.java