All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.plenigo.sdk.services.MobileService Maven / Gradle / Ivy

There is a newer version: 1.7.2
Show newest version
package com.plenigo.sdk.services;

import com.plenigo.sdk.PlenigoException;
import com.plenigo.sdk.PlenigoManager;
import com.plenigo.sdk.internal.ApiParams;
import com.plenigo.sdk.internal.ApiResults;
import com.plenigo.sdk.internal.ApiURLs;
import com.plenigo.sdk.internal.util.HttpConfig;
import com.plenigo.sdk.internal.util.JWT;
import com.plenigo.sdk.internal.util.SdkUtils;
import com.plenigo.sdk.models.MobileSecretInfo;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 

* This contains the services related to mobile secret handling with plenigo, *

*

* Thread safety: This class is thread safe and can be injected. *

*/ public final class MobileService { public static final int MIN_MOBILE_SECRET_SIZE = 6; public static final int MAX_MOBILE_SECRET_SIZE = 40; /** * Default constructor. */ private MobileService() { } /** * Returns the customer id given the mobile secret. * * @param email the email address * @param mobileSecret the mobile secret * * @return the mobile secret * * @throws PlenigoException if any error occurs */ public static String verifyMobileSecret(String email, String mobileSecret) throws PlenigoException { Map body = new LinkedHashMap(); body.put(ApiParams.EMAIL, email); body.put(ApiParams.MOBILE_SECRET, mobileSecret); Map response = HttpConfig.get().getClient().get(PlenigoManager.get().getUrl(), ApiURLs.MOBILE_SECRET_VERIFY, ApiURLs.MOBILE_SECRET_VERIFY, SdkUtils.buildUrlQueryString(body), JWT.generateJWTTokenHeader(PlenigoManager.get().getCompanyId(), PlenigoManager.get().getSecret())); return SdkUtils.getValueIfNotNull(response, ApiResults.CUST_ID); } /** * Returns the mobile secret. * * @param customerId customer id * * @return the mobile secret info * * @throws PlenigoException if any error occurs */ public static MobileSecretInfo getMobileSecret(String customerId) throws PlenigoException { Map body = new LinkedHashMap(); Map response = HttpConfig.get().getClient().get(PlenigoManager.get().getUrl(), ApiURLs.MOBILE_SECRET_URL, String.format(ApiURLs.MOBILE_SECRET_URL, customerId), SdkUtils.buildUrlQueryString(body), JWT.generateJWTTokenHeader(PlenigoManager.get().getCompanyId(), PlenigoManager.get().getSecret())); return buildMobileSecretInfo(response); } /** * Creates a mobile secret for a specific customer. * * @param customerId customer id * @param mobileSecretSize mobile secret size * * @return the mobile secret info * * @throws PlenigoException if any error occurs */ public static MobileSecretInfo createMobileSecret(String customerId, int mobileSecretSize) throws PlenigoException { if (mobileSecretSize < MIN_MOBILE_SECRET_SIZE) { mobileSecretSize = MIN_MOBILE_SECRET_SIZE; } if (mobileSecretSize > MAX_MOBILE_SECRET_SIZE) { mobileSecretSize = MAX_MOBILE_SECRET_SIZE; } Map body = new LinkedHashMap(); body.put(ApiParams.MOBILE_SECRET_SIZE, String.valueOf(mobileSecretSize)); Map response = HttpConfig.get().getClient().post(PlenigoManager.get().getUrl(), ApiURLs.MOBILE_SECRET_URL, String.format(ApiURLs.MOBILE_SECRET_URL, customerId), null, body, JWT.generateJWTTokenHeader(PlenigoManager.get().getCompanyId(), PlenigoManager.get().getSecret())); return buildMobileSecretInfo(response); } /** * Builds the mobile secret info object. * * @param response the json response as a map * * @return mobile secret info object */ private static MobileSecretInfo buildMobileSecretInfo(Map response) { String customerId = SdkUtils.getValueIfNotNull(response, ApiResults.EMAIL); String mobileAppSecret = SdkUtils.getValueIfNotNull(response, ApiResults.MOBILE_APP_SECRET); return new MobileSecretInfo(customerId, mobileAppSecret); } /** * Deletes a mobile secret. * * @param customerId customer id * * @return true if it the request was successful, false otherwise * * @throws PlenigoException if any error occurs */ public static boolean deleteMobileSecret(String customerId) throws PlenigoException { HttpConfig.get().getClient().delete(PlenigoManager.get().getUrl(), ApiURLs.MOBILE_SECRET_URL, String.format(ApiURLs.MOBILE_SECRET_URL, customerId), null, JWT.generateJWTTokenHeader(PlenigoManager.get().getCompanyId(), PlenigoManager.get().getSecret())); return true; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy