Пример #1
0
        public void PullRecordsAsync(PullRecordsRequest request, CloudSaveCallback <PullRecordsResponse> callback)
        {
            if (Logger.LoggingConfig.LogHttpOption == LogHttpOption.Always)
            {
                _logger.DebugFormat("INTERNAL LOG - Pull request is : {0}", JsonUtility.ToJson(request));
            }

            _credentialProvider.GetOrRefreshCredentialAsync((err, credential) =>
            {
                if (err != null)
                {
                    var exception = err as Exception;
                    callback(
                        exception != null
                            ? new CredentialException("Failed to GetOrRefresh credential.", exception)
                            : new CredentialException(err.ToString()), null);
                    return;
                }

                SuperAgent.Get(Endpoints.CloudSaveEndpoint + "/identities/" + request.IdentityId + "/datasets/" +
                               request.DatasetName + "/records")
                .Query("syncCount", request.OldSyncRevisions)
                .Set("Authorization", "Bearer " + credential.token)
                .End((agentErr, response) =>
                {
                    if (agentErr != null)
                    {
                        callback(agentErr, null);
                        return;
                    }

                    // todo:
                    // call _credentialProvider.Logout() in case of invalid token.

                    var jsonStr = Encoding.UTF8.GetString(response.Body);

                    if (Logger.LoggingConfig.LogHttpOption == LogHttpOption.Always)
                    {
                        _logger.DebugFormat("Pull response is : {0}", jsonStr);
                    }

                    var pullRecordsResponse = JsonUtility.FromJson <PullRecordsResponse>(jsonStr);

                    callback(null, pullRecordsResponse);
                });
            });
        }