io.particle.android.sdk.cloud.exceptions.ParticleCloudException Java Examples

The following examples show how to use io.particle.android.sdk.cloud.exceptions.ParticleCloudException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ParticleCloud.java    From spark-sdk-android with Apache License 2.0 6 votes vote down vote up
@WorkerThread
void rename(String deviceId, String newName) throws ParticleCloudException {
    ParticleDevice particleDevice;
    synchronized (devices) {
        particleDevice = devices.get(deviceId);
    }
    DeviceState originalDeviceState = particleDevice.deviceState;

    DeviceState stateWithNewName = DeviceState.withNewName(originalDeviceState, newName);
    updateDeviceState(stateWithNewName, true);
    try {
        mainApi.nameDevice(originalDeviceState.deviceId, newName);
    } catch (RetrofitError e) {
        // oops, change the name back.
        updateDeviceState(originalDeviceState, true);
        throw new ParticleCloudException(e);
    }
}
 
Example #2
Source File: EventsDelegate.java    From spark-sdk-android with Apache License 2.0 6 votes vote down vote up
@WorkerThread
void unsubscribeFromEventWithID(long eventListenerID) throws ParticleCloudException {
    synchronized (eventReaders) {
        EventReader reader = eventReaders.get(eventListenerID);
        if (reader == null) {
            log.w("No event listener subscription found for ID '" + eventListenerID + "'!");
            return;
        }
        eventReaders.remove(eventListenerID);
        try {
            reader.stopListening();
        } catch (IOException e) {
            // handling the exception here instead of putting it in the method signature
            // is inconsistent, but SDK consumers aren't going to care about receiving
            // this exception, so just swallow it here.
            log.w("Error while trying to stop event listener", e);
        }
    }
}
 
Example #3
Source File: ParticleCloud.java    From spark-sdk-android with Apache License 2.0 6 votes vote down vote up
/**
 * Create new customer account on the Particle cloud and log in
 *
 * @param signUpInfo Required sign up information, must contain a valid email address and password
 * @param productId  Product id to use
 */
@WorkerThread
public void signUpAndLogInWithCustomer(SignUpInfo signUpInfo, Integer productId)
        throws ParticleCloudException {
    if (!all(signUpInfo.getUsername(), signUpInfo.getPassword(), productId)) {
        throw new IllegalArgumentException(
                "Email, password, and product id must all be specified");
    }

    signUpInfo.setGrantType("client_credentials");
    try {
        Responses.LogInResponse response = identityApi.signUpAndLogInWithCustomer(signUpInfo, productId);
        onLogIn(response, signUpInfo.getUsername(), signUpInfo.getPassword());
    } catch (RetrofitError error) {
        throw new ParticleLoginException(error);
    }
}
 
Example #4
Source File: ParticleCloud.java    From spark-sdk-android with Apache License 2.0 6 votes vote down vote up
@Override
public void accessTokenExpiredAt(final ParticleAccessToken accessToken, Date expirationDate) {
    // handle auto-renewal of expired access tokens by internal timer event
    String refreshToken = accessToken.getRefreshToken();
    if (refreshToken != null) {
        try {
            refreshAccessToken(refreshToken);
            return;
        } catch (ParticleCloudException e) {
            log.e("Error while trying to refresh token: ", e);
        }
    }

    ParticleAccessToken.removeSession();
    token = null;
}
 
Example #5
Source File: ParticleDevice.java    From spark-sdk-android with Apache License 2.0 6 votes vote down vote up
@WorkerThread
public float getCurrentDataUsage() throws ParticleCloudException {
    float maxUsage = 0;
    try {
        Response response = mainApi.getCurrentDataUsage(deviceState.lastIccid);
        JSONObject result = new JSONObject(new String(((TypedByteArray) response.getBody()).getBytes()));
        JSONArray usages = result.getJSONArray("usage_by_day");

        for (int i = 0; i < usages.length(); i++) {
            JSONObject usageElement = usages.getJSONObject(i);
            if (usageElement.has("mbs_used_cumulative")) {
                double usage = usageElement.getDouble("mbs_used_cumulative");
                if (usage > maxUsage) {
                    maxUsage = (float) usage;
                }
            }
        }
    } catch (JSONException | RetrofitError e) {
        throw new ParticleCloudException(e);
    }
    return maxUsage;
}
 
Example #6
Source File: EventsDelegate.java    From spark-sdk-android with Apache License 2.0 6 votes vote down vote up
@WorkerThread
void unsubscribeFromEventWithHandler(SimpleParticleEventHandler handler) throws ParticleCloudException {
    synchronized (eventReaders) {
        for (int i = 0; i < eventReaders.size(); i++) {
            EventReader reader = eventReaders.valueAt(i);

            if (reader.handler == handler) {
                eventReaders.remove(i);
                try {
                    reader.stopListening();
                } catch (IOException e) {
                    // handling the exception here instead of putting it in the method signature
                    // is inconsistent, but SDK consumers aren't going to care about receiving
                    // this exception, so just swallow it here.
                    log.w("Error while trying to stop event listener", e);
                }
                return;
            }
        }
    }
}
 
Example #7
Source File: ParticleCloud.java    From spark-sdk-android with Apache License 2.0 6 votes vote down vote up
/**
 * Create new customer account on the Particle cloud and log in
 *
 * @param signUpInfo Required sign up information, must contain a valid email address and password
 * @param orgSlug    Organization slug to use
 * @deprecated Use product id or product slug instead
 */
@WorkerThread
@Deprecated
public void signUpAndLogInWithCustomer(SignUpInfo signUpInfo, String orgSlug)
        throws ParticleCloudException {
    if (!all(signUpInfo.getUsername(), signUpInfo.getPassword(), orgSlug)) {
        throw new IllegalArgumentException(
                "Email, password, and organization must all be specified");
    }

    signUpInfo.setGrantType("client_credentials");
    try {
        Responses.LogInResponse response = identityApi.signUpAndLogInWithCustomer(signUpInfo, orgSlug);
        onLogIn(response, signUpInfo.getUsername(), signUpInfo.getPassword());
    } catch (RetrofitError error) {
        throw new ParticleCloudException(error);
    }
}
 
Example #8
Source File: ParticleDevice.java    From spark-sdk-android with Apache License 2.0 6 votes vote down vote up
/**
 * Subscribes to system events of current device. Events emitted to EventBus listener.
 *
 * @throws ParticleCloudException Failure to subscribe to system events.
 * @see <a href="https://github.com/greenrobot/EventBus">EventBus</a>
 */
@MainThread
public void subscribeToSystemEvents() throws ParticleCloudException {
    try {
        EventBus eventBus = EventBus.getDefault();
        subscriptions.add(subscribeToSystemEvent("spark/status", (eventName, particleEvent) ->
                sendUpdateStatusChange(eventBus, particleEvent.dataPayload)));
        subscriptions.add(subscribeToSystemEvent("spark/flash/status", (eventName, particleEvent) ->
                sendUpdateFlashChange(eventBus, particleEvent.dataPayload)));
        subscriptions.add(subscribeToSystemEvent("spark/device/app-hash", (eventName, particleEvent) ->
                sendSystemEventBroadcast(new DeviceStateChange(ParticleDevice.this,
                        ParticleDeviceState.APP_HASH_UPDATED), eventBus)));
        subscriptions.add(subscribeToSystemEvent("spark/status/safe-mode", (eventName, particleEvent) ->
                sendSystemEventBroadcast(new DeviceStateChange(ParticleDevice.this,
                        ParticleDeviceState.SAFE_MODE_UPDATER), eventBus)));
        subscriptions.add(subscribeToSystemEvent("spark/safe-mode-updater/updating", (eventName, particleEvent) ->
                sendSystemEventBroadcast(new DeviceStateChange(ParticleDevice.this,
                        ParticleDeviceState.ENTERED_SAFE_MODE), eventBus)));
    } catch (IOException e) {
        log.d("Failed to auto-subscribe to system events");
        throw new ParticleCloudException(e);
    }
}
 
Example #9
Source File: ParticleDevice.java    From spark-sdk-android with Apache License 2.0 6 votes vote down vote up
@WorkerThread
T getVariable(String variableName)
        throws ParticleCloudException, IOException, VariableDoesNotExistException {

    if (!device.deviceState.variables.containsKey(variableName)) {
        throw new VariableDoesNotExistException(variableName);
    }

    R reply;
    try {
        reply = callApi(variableName);
    } catch (RetrofitError e) {
        throw new ParticleCloudException(e);
    }

    if (!reply.coreInfo.connected) {
        // FIXME: we should be doing this "connected" check on _any_ reply that comes back
        // with a "coreInfo" block.
        device.cloud.onDeviceNotConnected(device.deviceState);
        throw new IOException("Device is not connected.");
    } else {
        return reply.result;
    }
}
 
Example #10
Source File: ParticleCloud.java    From spark-sdk-android with Apache License 2.0 6 votes vote down vote up
/**
 * Sign up with new account credentials to Particle cloud
 *
 * @param signUpInfo Required sign up information, must contain a valid email address and password
 */
@WorkerThread
public void signUpWithUser(SignUpInfo signUpInfo) throws ParticleCloudException {
    try {
        Response response = identityApi.signUp(signUpInfo);
        String bodyString = new String(((TypedByteArray) response.getBody()).getBytes());
        JSONObject obj = new JSONObject(bodyString);

        //workaround for sign up bug - invalid credentials bug
        if (obj.has("ok") && !obj.getBoolean("ok")) {
            JSONArray arrJson = obj.getJSONArray("errors");
            String[] arr = new String[arrJson.length()];

            for (int i = 0; i < arrJson.length(); i++) {
                arr[i] = arrJson.getString(i);
            }
            if (arr.length > 0) {
                throw new ParticleCloudException(new Exception(arr[0]));
            }
        }
    } catch (RetrofitError error) {
        throw new ParticleCloudException(error);
    } catch (JSONException ignore) {
        //ignore - who cares if we're not getting error response
    }
}
 
Example #11
Source File: GetReadyActivity.java    From particle-android with Apache License 2.0 6 votes vote down vote up
private void onGenerateClaimCodeFail(@NonNull ParticleCloudException error) {
    log.d("Generating claim code failed");
    ParticleCloudException.ResponseErrorData errorData = error.getResponseData();
    if (errorData != null && errorData.getHttpStatusCode() == 401) {
        onUnauthorizedError();
    } else {
        if (isFinishing()) {
            return;
        }
        String errorMsg = getString(R.string.get_ready_could_not_connect_to_cloud);
        if (error.getMessage() != null) {
            errorMsg = errorMsg + "\n\n" + error.getMessage();
        }
        new AlertDialog.Builder(GetReadyActivity.this)
                .setTitle(R.string.error)
                .setMessage(errorMsg)
                .setPositiveButton(R.string.ok, (dialog, which) -> dialog.dismiss())
                .show();
    }
}
 
Example #12
Source File: CheckIfDeviceClaimedStep.java    From spark-setup-android with Apache License 2.0 6 votes vote down vote up
@Override
protected void onRunStep() throws SetupStepException {
    List<ParticleDevice> devices;
    try {
        devices = sparkCloud.getDevices();
    } catch (ParticleCloudException e) {
        throw new SetupStepException(e);
    }

    log.d("Got devices back from the cloud...");
    for (ParticleDevice device : devices) {
        if (deviceBeingConfiguredId.equalsIgnoreCase(device.getID())) {
            log.d("Success, device " + device.getID() + " claimed!");
            needToClaimDevice = false;
            return;
        }
    }

    // device not found in the loop
    throw new SetupStepException("Device " + deviceBeingConfiguredId + " still not claimed.");
}
 
Example #13
Source File: SuccessActivity.java    From particle-android with Apache License 2.0 6 votes vote down vote up
private void finishSetup(Context context, String deviceName, boolean isSuccess) {
    ParticleUi.showParticleButtonProgress(SuccessActivity.this, R.id.action_done, true);
    Async.executeAsync(particleCloud, new Async.ApiWork<ParticleCloud, Void>() {
        @Override
        public Void callApi(@NonNull ParticleCloud cloud) throws ParticleCloudException, IOException {
            ParticleDevice device = particleCloud.getDevice(getIntent().getStringExtra(EXTRA_DEVICE_ID));
            setDeviceName(device, deviceName);
            return null;
        }

        @Override
        public void onSuccess(@NonNull Void result) {
            leaveActivity(context, isSuccess);
        }

        @Override
        public void onFailure(@NonNull ParticleCloudException e) {
            ParticleUi.showParticleButtonProgress(SuccessActivity.this, R.id.action_done, false);
            deviceNameView.setError(getString(R.string.device_naming_failure));
        }
    });
}
 
Example #14
Source File: CheckIfDeviceClaimedStep.java    From particle-android with Apache License 2.0 6 votes vote down vote up
@Override
protected void onRunStep() throws SetupStepException {
    List<ParticleDevice> devices;
    try {
        devices = sparkCloud.getDevices();
    } catch (ParticleCloudException e) {
        throw new SetupStepException(e);
    }

    log.d("Got devices back from the cloud...");
    for (ParticleDevice device : devices) {
        if (deviceBeingConfiguredId.equalsIgnoreCase(device.getId())) {
            log.d("Success, device " + device.getId() + " claimed!");
            needToClaimDevice = false;
            return;
        }
    }

    // device not found in the loop
    throw new SetupStepException("Device " + deviceBeingConfiguredId + " still not claimed.");
}
 
Example #15
Source File: SuccessActivity.java    From spark-setup-android with Apache License 2.0 6 votes vote down vote up
private void finishSetup(Context context, String deviceName, boolean isSuccess) {
    ParticleUi.showParticleButtonProgress(SuccessActivity.this, R.id.action_done, true);
    Async.executeAsync(particleCloud, new Async.ApiWork<ParticleCloud, Void>() {
        @Override
        public Void callApi(@NonNull ParticleCloud cloud) throws ParticleCloudException, IOException {
            ParticleDevice device = particleCloud.getDevice(getIntent().getStringExtra(EXTRA_DEVICE_ID));
            setDeviceName(device, deviceName);
            return null;
        }

        @Override
        public void onSuccess(@NonNull Void result) {
            leaveActivity(context, isSuccess);
        }

        @Override
        public void onFailure(@NonNull ParticleCloudException e) {
            ParticleUi.showParticleButtonProgress(SuccessActivity.this, R.id.action_done, false);
            deviceNameView.setError(getString(R.string.device_naming_failure));
        }
    });
}
 
Example #16
Source File: GetReadyActivity.java    From spark-setup-android with Apache License 2.0 6 votes vote down vote up
private void onGenerateClaimCodeFail(@NonNull ParticleCloudException error) {
    log.d("Generating claim code failed");
    ParticleCloudException.ResponseErrorData errorData = error.getResponseData();
    if (errorData != null && errorData.getHttpStatusCode() == 401) {
        onUnauthorizedError();
    } else {
        if (isFinishing()) {
            return;
        }

        // FIXME: we could just check the internet connection here ourselves...
        String errorMsg = getString(R.string.get_ready_could_not_connect_to_cloud);
        if (error.getMessage() != null) {
            errorMsg = errorMsg + "\n\n" + error.getMessage();
        }
        new AlertDialog.Builder(GetReadyActivity.this)
                .setTitle(R.string.error)
                .setMessage(errorMsg)
                .setPositiveButton(R.string.ok, (dialog, which) -> dialog.dismiss())
                .show();
    }
}
 
Example #17
Source File: CreateAccountActivity.java    From spark-setup-android with Apache License 2.0 5 votes vote down vote up
private void attemptLogin(final String username, final String password) {
    final ParticleCloud cloud = ParticleCloudSDK.getCloud();
    Async.executeAsync(cloud, new Async.ApiWork<ParticleCloud, Void>() {
        @Override
        public Void callApi(@NonNull ParticleCloud particleCloud) throws ParticleCloudException {
            particleCloud.logIn(username, password);
            return null;
        }

        @Override
        public void onSuccess(@NonNull Void result) {
            log.d("Logged in...");
            if (isFinishing()) {
                return;
            }
            onLoginSuccess(cloud);
        }

        @Override
        public void onFailure(@NonNull ParticleCloudException error) {
            log.w("onFailed(): " + error.getMessage());
            ParticleUi.showParticleButtonProgress(CreateAccountActivity.this,
                    R.id.action_create_account, false);
            passwordView.setError(error.getBestMessage());
            passwordView.requestFocus();
        }
    });

}
 
Example #18
Source File: ParticleCloud.java    From spark-sdk-android with Apache License 2.0 5 votes vote down vote up
@WorkerThread
public void requestPasswordResetForCustomer(String email, Integer productId) throws ParticleCloudException {
    try {
        identityApi.requestPasswordResetForCustomer(email, productId);
    } catch (RetrofitError error) {
        throw new ParticleCloudException(error);
    }
}
 
Example #19
Source File: CreateAccountActivity.java    From spark-setup-android with Apache License 2.0 5 votes vote down vote up
private void signUpTaskFailure(@NonNull ParticleCloudException error) {
    // FIXME: look at old Spark app for what we do here UI & workflow-wise
    log.d("onFailed()");
    ParticleUi.showParticleButtonProgress(CreateAccountActivity.this,
            R.id.action_create_account, false);

    String msg = getString(R.string.create_account_unknown_error);
    if (error.getKind() == ParticleCloudException.Kind.NETWORK) {
        msg = getString(R.string.create_account_error_communicating_with_server);

    } else if (error.getResponseData() != null) {

        if (error.getResponseData().getHttpStatusCode() == 401
                && (getResources().getBoolean(R.bool.organization) ||
                getResources().getBoolean(R.bool.productMode))) {
            msg = getString(R.string.create_account_account_already_exists_for_email_address);
        } else {
            msg = error.getServerErrorMsg();
        }
    }
    //TODO remove once sign up error code is fixed
    if (error.getCause() != null && error.getCause().getMessage().contains(emailView.getText().toString())) {
        msg = getString(R.string.create_account_account_already_exists_for_email_address);
    }

    Toaster.l(CreateAccountActivity.this, msg, Gravity.CENTER_VERTICAL);
    emailView.requestFocus();
}
 
Example #20
Source File: ParticleDevice.java    From spark-sdk-android with Apache License 2.0 5 votes vote down vote up
/**
 * Remove device from current logged in user account
 */
@WorkerThread
public void unclaim() throws ParticleCloudException {
    try {
        cloud.unclaimDevice(deviceState.deviceId);
    } catch (RetrofitError e) {
        throw new ParticleCloudException(e);
    }
}
 
Example #21
Source File: ParticleCloud.java    From spark-sdk-android with Apache License 2.0 5 votes vote down vote up
@WorkerThread
private ParticleDevice getDevice(String deviceID, boolean sendUpdate)
        throws ParticleCloudException {
    CompleteDevice deviceCloudModel;
    try {
        deviceCloudModel = mainApi.getDevice(deviceID);
    } catch (RetrofitError error) {
        throw new ParticleCloudException(error);
    }

    return getDevice(deviceCloudModel, sendUpdate);
}
 
Example #22
Source File: ParticleCloud.java    From spark-sdk-android with Apache License 2.0 5 votes vote down vote up
@WorkerThread
@Deprecated
public void requestPasswordResetForCustomer(String email, String organizationSlug) throws ParticleCloudException {
    try {
        log.w("Use product id instead of organization slug.");
        identityApi.requestPasswordResetForCustomer(email, organizationSlug);
    } catch (RetrofitError error) {
        throw new ParticleCloudException(error);
    }
}
 
Example #23
Source File: ParticleCloud.java    From spark-sdk-android with Apache License 2.0 5 votes vote down vote up
/**
 * Claim the specified device to the currently logged in user (without claim code mechanism)
 *
 * @param deviceID the deviceID
 */
@WorkerThread
public void claimDevice(String deviceID) throws ParticleCloudException {
    try {
        mainApi.claimDevice(deviceID);
    } catch (RetrofitError error) {
        throw new ParticleCloudException(error);
    }
}
 
Example #24
Source File: GetReadyActivity.java    From spark-setup-android with Apache License 2.0 5 votes vote down vote up
private ClaimCodeResponse generateClaimCode(Context ctx) throws ParticleCloudException {
    Resources res = ctx.getResources();
    if (res.getBoolean(R.bool.organization) && !res.getBoolean(R.bool.productMode)) {
        return sparkCloud.generateClaimCodeForOrg(res.getString(R.string.organization_slug),
                res.getString(R.string.product_slug));
    } else if (res.getBoolean(R.bool.productMode)) {
        int productId = res.getInteger(R.integer.product_id);
        if (productId == 0) {
            throw new ParticleCloudException(new Exception("Product id must be set when productMode is in use."));
        }
        return sparkCloud.generateClaimCode(productId);
    } else {
        return sparkCloud.generateClaimCode();
    }
}
 
Example #25
Source File: ParticleDevice.java    From spark-sdk-android with Apache License 2.0 5 votes vote down vote up
/**
 * Call a function on the device
 *
 * @param functionName Function name
 * @param args         Array of arguments to pass to the function on the device.
 *                     Arguments must not be more than MAX_PARTICLE_FUNCTION_ARG_LENGTH chars
 *                     in length. If any arguments are longer, a runtime exception will be thrown.
 * @return result code: a value of 1 indicates success
 */
@WorkerThread
public int callFunction(String functionName, @Nullable List<String> args)
        throws ParticleCloudException, IOException, FunctionDoesNotExistException {
    // TODO: check response of calling a non-existent function
    if (!deviceState.functions.contains(functionName)) {
        throw new FunctionDoesNotExistException(functionName);
    }

    // null is accepted here, but it won't be in the Retrofit API call later
    if (args == null) {
        args = list();
    }

    String argsString = ParticleInternalStringUtils.join(args, ',');
    Preconditions.checkArgument(argsString.length() < MAX_PARTICLE_FUNCTION_ARG_LENGTH,
            String.format("Arguments '%s' exceed max args length of %d",
                    argsString, MAX_PARTICLE_FUNCTION_ARG_LENGTH));

    Responses.CallFunctionResponse response;
    try {
        response = mainApi.callFunction(deviceState.deviceId, functionName,
                new FunctionArgs(argsString));
    } catch (RetrofitError e) {
        throw new ParticleCloudException(e);
    }

    if (!response.connected) {
        cloud.onDeviceNotConnected(deviceState);
        throw new IOException("Device is not connected.");
    } else {
        return response.returnValue;
    }
}
 
Example #26
Source File: ParticleCloud.java    From spark-sdk-android with Apache License 2.0 5 votes vote down vote up
@WorkerThread
public void requestPasswordReset(String email) throws ParticleCloudException {
    try {
        identityApi.requestPasswordReset(email);
    } catch (RetrofitError error) {
        throw new ParticleCloudException(error);
    }
}
 
Example #27
Source File: UnclaimHelper.java    From particle-android with Apache License 2.0 5 votes vote down vote up
private static void unclaim(final Activity activity, final ParticleDevice device) {
    try {
        Async.executeAsync(device, new Async.ApiWork<ParticleDevice, Void>() {

            @Override
            public Void callApi(@NonNull ParticleDevice sparkDevice)
                    throws ParticleCloudException, IOException {
                device.unclaim();
                return null;
            }

            @Override
            public void onSuccess(@NonNull Void aVoid) {
                // FIXME: what else should happen here?
                Toaster.s(activity, "Unclaimed " + device.getName());
            }

            @Override
            public void onFailure(@NonNull ParticleCloudException exception) {
                new AlertDialog.Builder(activity)
                        .setMessage("Error: unable to unclaim '" + device.getName() + "'")
                        .setPositiveButton(R.string.ok, (dialog, which) -> dialog.dismiss())
                        .show();
            }
        }).andIgnoreCallbacksIfActivityIsFinishing(activity);
    } catch (ParticleCloudException e) {
        new AlertDialog.Builder(activity)
                .setMessage("Error: unable to unclaim '" + device.getName() + "'")
                .setPositiveButton(R.string.ok, (dialog, which) -> dialog.dismiss())
                .show();
    }
}
 
Example #28
Source File: ParticleCloud.java    From spark-sdk-android with Apache License 2.0 5 votes vote down vote up
@WorkerThread
public Responses.ClaimCodeResponse generateClaimCode(Integer productId)
        throws ParticleCloudException {
    try {
        // Offer empty string to appease newer OkHttp versions which require a POST body,
        // even if it's empty or (as far as the endpoint cares) nonsense
        return mainApi.generateClaimCodeForOrg("okhttp_appeasement", productId);
    } catch (RetrofitError error) {
        throw new ParticleCloudException(error);
    }
}
 
Example #29
Source File: ParticleCloud.java    From spark-sdk-android with Apache License 2.0 5 votes vote down vote up
/**
 * Get a short-lived claiming token for transmitting to soon-to-be-claimed device in
 * soft AP setup process
 *
 * @return a claim code string set on success (48 random bytes, base64 encoded
 * to 64 ASCII characters)
 */
@WorkerThread
public Responses.ClaimCodeResponse generateClaimCode() throws ParticleCloudException {
    try {
        // Offer empty string to appease newer OkHttp versions which require a POST body,
        // even if it's empty or (as far as the endpoint cares) nonsense
        return mainApi.generateClaimCode("okhttp_appeasement");
    } catch (RetrofitError error) {
        throw new ParticleCloudException(error);
    }
}
 
Example #30
Source File: ParticleCloud.java    From spark-sdk-android with Apache License 2.0 5 votes vote down vote up
@WorkerThread
@Deprecated
public Responses.ClaimCodeResponse generateClaimCodeForOrg(String organizationSlug, String productSlug)
        throws ParticleCloudException {
    try {
        log.w("Use product id instead of organization slug.");
        // Offer empty string to appease newer OkHttp versions which require a POST body,
        // even if it's empty or (as far as the endpoint cares) nonsense
        return mainApi.generateClaimCodeForOrg("okhttp_appeasement", organizationSlug, productSlug);
    } catch (RetrofitError error) {
        throw new ParticleCloudException(error);
    }
}