Example #1
0
        public virtual void GetProductUpdateDetail(IEnumerable <string> productIds, Action <Dictionary <string, object> > doneCallbackAction)
        {
            if (productIds?.Any() != true)
            {
                doneCallbackAction?.Invoke(new Dictionary <string, object>());
                return;
            }

            var localInfos = new List <AssetStoreLocalInfo>();

            foreach (var productId in productIds)
            {
                var localInfo = m_AssetStoreCache.GetLocalInfo(productId);
                if (localInfo?.updateInfoFetched == false)
                {
                    localInfos.Add(localInfo);
                }
            }
            var localInfosJsonData = Json.Serialize(localInfos.Select(info => info?.ToDictionary() ?? new Dictionary <string, string>()).ToList());

            HandleHttpRequest(() => m_HttpClientFactory.PostASyncHTTPClient($"{host}{k_UpdateInfoUri}", localInfosJsonData),
                              result =>
            {
                var ret = result["result"] as Dictionary <string, object>;
                doneCallbackAction?.Invoke(ret);
            },
                              error =>
            {
                var ret = new Dictionary <string, object>
                {
                    ["errorMessage"] = error.message,
                    ["errorCode"]    = error.operationErrorCode
                };
                doneCallbackAction?.Invoke(ret);
            });
        }
Example #2
0
        private void GetAccessToken(Action <AccessToken> doneCallback, string authCode = null, string refreshToken = null)
        {
            m_OnAccessTokenFetched += doneCallback;

            if (m_AccessTokenRequest != null)
            {
                return;
            }

            if (string.IsNullOrEmpty(secret))
            {
                OnGetAccessTokenError(L10n.Tr("Error while getting access token: invalid configuration from Unity Connect"));
                return;
            }

            var authorization = string.Empty;

            if (!string.IsNullOrEmpty(authCode))
            {
                authorization = $"grant_type=authorization_code&code={authCode}";
            }
            else if (!string.IsNullOrEmpty(refreshToken))
            {
                authorization = $"grant_type=refresh_token&refresh_token={refreshToken}";
            }
            else
            {
                return;
            }

            m_AccessTokenRequest = m_HttpClientFactory.PostASyncHTTPClient($"{host}{k_OAuthUri}", $"{authorization}&client_id={k_ServiceId}&client_secret={secret}");
            m_AccessTokenRequest.header["Content-Type"] = "application/x-www-form-urlencoded";
            m_AccessTokenRequest.doneCallback           = httpClient =>
            {
                m_AccessTokenRequest = null;
                m_AccessToken        = null;

                var response = AssetStoreUtils.ParseResponseAsDictionary(httpClient);
                if (response != null)
                {
                    if (response.ContainsKey("errorMessage"))
                    {
                        OnGetAccessTokenError(string.Format(L10n.Tr("Error while getting access token: {0}"), response.GetString("errorMessage")));
                        return;
                    }

                    var accessToken = new AccessToken(response);
                    if (accessToken.IsValid())
                    {
                        m_AccessToken = accessToken;
                        m_OnAccessTokenFetched?.Invoke(m_AccessToken);
                        m_OnAccessTokenFetched = null;
                    }
                    else
                    {
                        OnGetAccessTokenError(L10n.Tr("Access token invalid"));
                    }
                }
            };
            m_AccessTokenRequest.Begin();
        }