@Test public void smartcarAuth_receiveResponse() { String clientId = "client123"; String redirectUri = "scclient123: String[] scope = {"read_odometer", "read_vin"}; new SmartcarAuth(clientId, redirectUri, scope, new SmartcarCallback() { @Override public void handleResponse(SmartcarResponse smartcarResponse) { assertEquals(smartcarResponse.getCode(), "testcode123"); } }); SmartcarAuth.receiveResponse(Uri.parse(redirectUri + "?code=testcode123")); }
protected static void receiveResponse(Uri uri) { if (uri != null && uri.toString().startsWith(redirectUri)) { String queryState = uri.getQueryParameter("state"); String queryErrorDescription = uri.getQueryParameter("error_description"); String queryCode = uri.getQueryParameter("code"); String queryError = uri.getQueryParameter("error"); String queryVin = uri.getQueryParameter("vin"); boolean receivedCode = queryCode != null; boolean receivedError = queryError != null && queryVin == null; boolean receivedErrorWithVehicle = queryError != null && queryVin != null; SmartcarResponse.Builder responseBuilder = new SmartcarResponse.Builder(); if (receivedCode) { SmartcarResponse smartcarResponse = responseBuilder .code(queryCode) .errorDescription(queryErrorDescription) .state(queryState) .build(); callback.handleResponse(smartcarResponse); } else if (receivedError) { SmartcarResponse smartcarResponse = responseBuilder .error(queryError) .errorDescription(queryErrorDescription) .state(queryState) .build(); callback.handleResponse(smartcarResponse); } else if (receivedErrorWithVehicle) { String make = uri.getQueryParameter("make"); String model = uri.getQueryParameter("model"); int year = Integer.parseInt(uri.getQueryParameter("year")); VehicleInfo responseVehicle = new VehicleInfo.Builder() .vin(queryVin) .make(make) .model(model) .year(year) .build(); SmartcarResponse smartcarResponse = responseBuilder .error(queryError) .errorDescription(queryErrorDescription) .state(queryState) .vehicleInfo(responseVehicle) .build(); callback.handleResponse(smartcarResponse); } else { SmartcarResponse smartcarResponse = responseBuilder .errorDescription("Unable to fetch code. Please try again") .state(queryState) .build(); callback.handleResponse(smartcarResponse); } } }
SmartcarAuth { protected static void receiveResponse(Uri uri) { if (uri != null && uri.toString().startsWith(redirectUri)) { String queryState = uri.getQueryParameter("state"); String queryErrorDescription = uri.getQueryParameter("error_description"); String queryCode = uri.getQueryParameter("code"); String queryError = uri.getQueryParameter("error"); String queryVin = uri.getQueryParameter("vin"); boolean receivedCode = queryCode != null; boolean receivedError = queryError != null && queryVin == null; boolean receivedErrorWithVehicle = queryError != null && queryVin != null; SmartcarResponse.Builder responseBuilder = new SmartcarResponse.Builder(); if (receivedCode) { SmartcarResponse smartcarResponse = responseBuilder .code(queryCode) .errorDescription(queryErrorDescription) .state(queryState) .build(); callback.handleResponse(smartcarResponse); } else if (receivedError) { SmartcarResponse smartcarResponse = responseBuilder .error(queryError) .errorDescription(queryErrorDescription) .state(queryState) .build(); callback.handleResponse(smartcarResponse); } else if (receivedErrorWithVehicle) { String make = uri.getQueryParameter("make"); String model = uri.getQueryParameter("model"); int year = Integer.parseInt(uri.getQueryParameter("year")); VehicleInfo responseVehicle = new VehicleInfo.Builder() .vin(queryVin) .make(make) .model(model) .year(year) .build(); SmartcarResponse smartcarResponse = responseBuilder .error(queryError) .errorDescription(queryErrorDescription) .state(queryState) .vehicleInfo(responseVehicle) .build(); callback.handleResponse(smartcarResponse); } else { SmartcarResponse smartcarResponse = responseBuilder .errorDescription("Unable to fetch code. Please try again") .state(queryState) .build(); callback.handleResponse(smartcarResponse); } } } }
SmartcarAuth { protected static void receiveResponse(Uri uri) { if (uri != null && uri.toString().startsWith(redirectUri)) { String queryState = uri.getQueryParameter("state"); String queryErrorDescription = uri.getQueryParameter("error_description"); String queryCode = uri.getQueryParameter("code"); String queryError = uri.getQueryParameter("error"); String queryVin = uri.getQueryParameter("vin"); boolean receivedCode = queryCode != null; boolean receivedError = queryError != null && queryVin == null; boolean receivedErrorWithVehicle = queryError != null && queryVin != null; SmartcarResponse.Builder responseBuilder = new SmartcarResponse.Builder(); if (receivedCode) { SmartcarResponse smartcarResponse = responseBuilder .code(queryCode) .errorDescription(queryErrorDescription) .state(queryState) .build(); callback.handleResponse(smartcarResponse); } else if (receivedError) { SmartcarResponse smartcarResponse = responseBuilder .error(queryError) .errorDescription(queryErrorDescription) .state(queryState) .build(); callback.handleResponse(smartcarResponse); } else if (receivedErrorWithVehicle) { String make = uri.getQueryParameter("make"); String model = uri.getQueryParameter("model"); int year = Integer.parseInt(uri.getQueryParameter("year")); VehicleInfo responseVehicle = new VehicleInfo.Builder() .vin(queryVin) .make(make) .model(model) .year(year) .build(); SmartcarResponse smartcarResponse = responseBuilder .error(queryError) .errorDescription(queryErrorDescription) .state(queryState) .vehicleInfo(responseVehicle) .build(); callback.handleResponse(smartcarResponse); } else { SmartcarResponse smartcarResponse = responseBuilder .errorDescription("Unable to fetch code. Please try again") .state(queryState) .build(); callback.handleResponse(smartcarResponse); } } } SmartcarAuth(String clientId, String redirectUri, String[] scope,
                        SmartcarCallback callback);  SmartcarAuth(String clientId, String redirectUri, String[] scope, boolean testMode,
                        SmartcarCallback callback); }
SmartcarAuth { protected static void receiveResponse(Uri uri) { if (uri != null && uri.toString().startsWith(redirectUri)) { String queryState = uri.getQueryParameter("state"); String queryErrorDescription = uri.getQueryParameter("error_description"); String queryCode = uri.getQueryParameter("code"); String queryError = uri.getQueryParameter("error"); String queryVin = uri.getQueryParameter("vin"); boolean receivedCode = queryCode != null; boolean receivedError = queryError != null && queryVin == null; boolean receivedErrorWithVehicle = queryError != null && queryVin != null; SmartcarResponse.Builder responseBuilder = new SmartcarResponse.Builder(); if (receivedCode) { SmartcarResponse smartcarResponse = responseBuilder .code(queryCode) .errorDescription(queryErrorDescription) .state(queryState) .build(); callback.handleResponse(smartcarResponse); } else if (receivedError) { SmartcarResponse smartcarResponse = responseBuilder .error(queryError) .errorDescription(queryErrorDescription) .state(queryState) .build(); callback.handleResponse(smartcarResponse); } else if (receivedErrorWithVehicle) { String make = uri.getQueryParameter("make"); String model = uri.getQueryParameter("model"); int year = Integer.parseInt(uri.getQueryParameter("year")); VehicleInfo responseVehicle = new VehicleInfo.Builder() .vin(queryVin) .make(make) .model(model) .year(year) .build(); SmartcarResponse smartcarResponse = responseBuilder .error(queryError) .errorDescription(queryErrorDescription) .state(queryState) .vehicleInfo(responseVehicle) .build(); callback.handleResponse(smartcarResponse); } else { SmartcarResponse smartcarResponse = responseBuilder .errorDescription("Unable to fetch code. Please try again") .state(queryState) .build(); callback.handleResponse(smartcarResponse); } } } SmartcarAuth(String clientId, String redirectUri, String[] scope,
                        SmartcarCallback callback);  SmartcarAuth(String clientId, String redirectUri, String[] scope, boolean testMode,
                        SmartcarCallback callback); AuthUrlBuilder authUrlBuilder(); void addClickHandler(final Context context, final View view); void addClickHandler(final Context context, final View view, final String authUrl); void launchAuthFlow(final Context context); void launchAuthFlow(final Context context, final String authUrl); }
SmartcarAuth { protected static void receiveResponse(Uri uri) { if (uri != null && uri.toString().startsWith(redirectUri)) { String queryState = uri.getQueryParameter("state"); String queryErrorDescription = uri.getQueryParameter("error_description"); String queryCode = uri.getQueryParameter("code"); String queryError = uri.getQueryParameter("error"); String queryVin = uri.getQueryParameter("vin"); boolean receivedCode = queryCode != null; boolean receivedError = queryError != null && queryVin == null; boolean receivedErrorWithVehicle = queryError != null && queryVin != null; SmartcarResponse.Builder responseBuilder = new SmartcarResponse.Builder(); if (receivedCode) { SmartcarResponse smartcarResponse = responseBuilder .code(queryCode) .errorDescription(queryErrorDescription) .state(queryState) .build(); callback.handleResponse(smartcarResponse); } else if (receivedError) { SmartcarResponse smartcarResponse = responseBuilder .error(queryError) .errorDescription(queryErrorDescription) .state(queryState) .build(); callback.handleResponse(smartcarResponse); } else if (receivedErrorWithVehicle) { String make = uri.getQueryParameter("make"); String model = uri.getQueryParameter("model"); int year = Integer.parseInt(uri.getQueryParameter("year")); VehicleInfo responseVehicle = new VehicleInfo.Builder() .vin(queryVin) .make(make) .model(model) .year(year) .build(); SmartcarResponse smartcarResponse = responseBuilder .error(queryError) .errorDescription(queryErrorDescription) .state(queryState) .vehicleInfo(responseVehicle) .build(); callback.handleResponse(smartcarResponse); } else { SmartcarResponse smartcarResponse = responseBuilder .errorDescription("Unable to fetch code. Please try again") .state(queryState) .build(); callback.handleResponse(smartcarResponse); } } } SmartcarAuth(String clientId, String redirectUri, String[] scope,
                        SmartcarCallback callback);  SmartcarAuth(String clientId, String redirectUri, String[] scope, boolean testMode,
                        SmartcarCallback callback); AuthUrlBuilder authUrlBuilder(); void addClickHandler(final Context context, final View view); void addClickHandler(final Context context, final View view, final String authUrl); void launchAuthFlow(final Context context); void launchAuthFlow(final Context context, final String authUrl);  }