Beispiel #1
0
        public async Task <APIResult <Boolean, JsonError> > AsyncDeleteInventory(UserCredentials user)
        {
            try {
                string response = await rs.PerformAsyncDelete(inventoryEndpoint, user.GetAccessToken());

                // Return APIResult:Boolean in success case
                return(new APIResult <Boolean, JsonError>(true));
            } catch (WebException e) when(RetrieveHTTPCode(e) == (int)httpResponseCode.unauthorised)
            {
                // If access token doesn't match a user, refresh tokens and retry
                APIResult <ResponseAuthenticate, JsonError> refreshedTokens = await AsyncRefreshTokens(user);

                try {
                    string response = await rs.PerformAsyncDelete(inventoryEndpoint, refreshedTokens.GetSuccess().access);

                    // Return APIResult:Boolean in success case
                    return(new APIResult <Boolean, JsonError>(true));
                } catch (WebException f) {
                    // Retrieve error payload from WebException
                    JsonError error = JsonUtility.FromJson <JsonError>(retrieveErrorJson(f));

                    // Return APIResult:JsonError in error case
                    return(new APIResult <Boolean, JsonError>(error));
                }
            } catch (WebException e) {
                // Retrieve error payload from WebException
                JsonError error = JsonUtility.FromJson <JsonError>(retrieveErrorJson(e));

                // Return APIResult:JsonError in error case
                return(new APIResult <Boolean, JsonError>(error));
            }
        }
Beispiel #2
0
        public async Task <APIResult <string, JsonError> > AsyncGetItemSchema()
        {
            try {
                string response = await rs.PerformAsyncGet(itemSchemaEndpoint);

                // Return APIResult:string in success case
                return(new APIResult <string, JsonError>(response));
            } catch (WebException e) {
                JsonError error = new JsonError();
                error.error = e.Message;

                // Return APIResult:JsonError in failure case
                return(new APIResult <string, JsonError>(error));
            }
        }
Beispiel #3
0
        public async Task <APIResult <ResponseAuthenticate, JsonError> > AsyncRefreshTokens(UserCredentials user)
        {
            // Prepare JSON payload & local variables
            string json = JsonUtility.ToJson(new RefreshPayload(user.GetRefreshToken()));

            try {
                string response = await rs.PerformAsyncPost(refreshEndpoint, json);

                ResponseAuthenticate tokens = JsonUtility.FromJson <ResponseAuthenticate>(response);

                // Return APIResult:ResponseAuthenticate in success case
                return(new APIResult <ResponseAuthenticate, JsonError>(tokens));
            } catch (WebException e) {
                // Retrieve error payload from WebException
                JsonError error = JsonUtility.FromJson <JsonError>(retrieveErrorJson(e));

                // Return APIResult:JsonError in error case
                return(new APIResult <ResponseAuthenticate, JsonError>(error));
            }
        }
Beispiel #4
0
        public async Task <APIResult <UserCredentials, JsonError> > AsyncAuthenticateUser(UserCredentials user)
        {
            validateUsernamePassword(user.GetUsername(), user.GetPassword());

            // Prepare JSON payload & local variables
            string json = JsonUtility.ToJson(new PayloadAuthenticate(user));

            try {
                string response = await rs.PerformAsyncPost(authenticateEndpoint, json);

                ResponseAuthenticate tokens = JsonUtility.FromJson <ResponseAuthenticate>(response);

                // Return APIResult:UserCredentials in success case
                return(new APIResult <UserCredentials, JsonError>(
                           new UserCredentials(user.GetUsername(), user.GetPassword(), tokens.access, tokens.refresh)
                           ));
            } catch (WebException e) {
                // Retrieve error payload from WebException
                JsonError error = JsonUtility.FromJson <JsonError>(retrieveErrorJson(e));

                // Return APIResult:JsonError in error case
                return(new APIResult <UserCredentials, JsonError>(error));
            }
        }