예제 #1
0
        private void SendRequestInternal(string postData, Enumerators.GoogleCloudRequestType cloudRequestType)
        {
            string uri = string.Empty;

            NetworkEnumerators.RequestType requestType = NetworkEnumerators.RequestType.POST;

            switch (cloudRequestType)
            {
            case Enumerators.GoogleCloudRequestType.TRANSLATE:
                uri += Constants.POST_TRANSLATE_REQUEST_URL;
                break;

            case Enumerators.GoogleCloudRequestType.DETECT_LANGUAGE:
                uri += Constants.POST_DETECT_REQUEST_URL;
                break;

            case Enumerators.GoogleCloudRequestType.GET_LANGUAGES:
                uri += Constants.GET_LANGUAGES_REQUEST_URL;
                //   requestType = NetworkEnumerators.RequestType.GET; // on offical Google page it looks like GET request but it works correctly only with POST request
                break;

            default: break;
            }

            if (!_gcTranslation.isUseAPIKeyFromPrefab)
            {
                uri += Constants.API_KEY_PARAM + Constants.GC_API_KEY;
            }
            else
            {
                uri += Constants.API_KEY_PARAM + _gcTranslation.apiKey;
            }

            _networking.SendRequest(uri, postData, requestType, new object[] { cloudRequestType });
        }
예제 #2
0
        public NetworkRequest(string uri, string data, long index, NetworkEnumerators.RequestType type, object[] param = null, bool checkCeritifcates = false)
        {
            requestType    = type;
            netPacketIndex = index;
            parameters     = param;

            request = new NetworkMethod(uri, data, checkCeritifcates, type, NetworkConstants.NETWORK_METHOD);
        }
예제 #3
0
 public NetworkResponse(string resp, string err, long index, NetworkEnumerators.RequestType type, object[] param)
 {
     requestType    = type;
     netPacketIndex = index;
     response       = resp;
     error          = err;
     parameters     = param;
 }
예제 #4
0
 public NetworkResponse(string resp, string err, long index, NetworkEnumerators.RequestType type, object[] param)
 {
     RequestType = type;
     RequestId   = index;
     Response    = resp;
     Error       = err;
     Parameters  = param;
 }
예제 #5
0
        public long SendRequest(string uri, string data, NetworkEnumerators.RequestType requestType, object[] param = null, bool checkCertificates = false)
        {
            long netIndex = _packetIndex++;

            NetworkRequest netRequest = new NetworkRequest(uri, data, netIndex, requestType, param, checkCertificates);

            _networkRequests.Add(netRequest);

            netRequest.Send();

            return(netIndex);
        }
예제 #6
0
        public NetworkMethod(string uri, string data, bool checkCeritifcates, NetworkEnumerators.RequestType type, NetworkEnumerators.NetworkMethod method)
        {
            _uri              = uri;
            _data             = data;
            _requestType      = type;
            _checkCertificate = checkCeritifcates;
            _method           = method;

            switch (method)
            {
            case NetworkEnumerators.NetworkMethod.WEB_REQUEST:
            {
                byte[] bytes = Encoding.UTF8.GetBytes(_data);

                if (_requestType == NetworkEnumerators.RequestType.GET)
                {
                    _webRequest = new UnityWebRequest(uri, UnityWebRequest.kHttpVerbGET);
                }
                else
                {
                    _webRequest = new UnityWebRequest(uri, UnityWebRequest.kHttpVerbPOST);
                }

                if (!string.IsNullOrEmpty(data))
                {
                    _webRequest.uploadHandler = new UploadHandlerRaw(bytes);
                }

                _webRequest.downloadHandler = new DownloadHandlerBuffer();
                _webRequest.SetRequestHeader("Content-Type", "application/json");
                _webRequest.chunkedTransfer = false;

                if (checkCeritifcates)
                {
#if UNITY_ANDROID
                    _webRequest.SetRequestHeader("X-Android-Package", NetworkConstants.PACKAGE_NAME);
                    _webRequest.SetRequestHeader("X-Android-Cert", NetworkConstants.KEY_SIGNATURE);
#elif UNITY_IOS
                    // need to check are they correct keys
                    // _webRequest.SetRequestHeader("X-IOS-Package", NetworkConstants.PACKAGE_NAME);
                    //  _webRequest.SetRequestHeader("X-IOS-Cert", NetworkConstants.KEY_SIGNATURE);
#endif
                }
            }
            break;

            default: break;
            }
        }
예제 #7
0
        public NetworkMethod(string uri, string data, bool checkCeritifcates, NetworkEnumerators.RequestType type, NetworkEnumerators.NetworkMethod method)
        {
            _uri              = uri;
            _data             = data;
            _requestType      = type;
            _checkCertificate = checkCeritifcates;
            _method           = method;

            switch (method)
            {
            case NetworkEnumerators.NetworkMethod.WEB_REQUEST:
            {
                byte[] bytes = Encoding.UTF8.GetBytes(_data);

                switch (_requestType)
                {
                case NetworkEnumerators.RequestType.GET:
                    _webRequest = new UnityWebRequest(uri, UnityWebRequest.kHttpVerbGET);
                    break;

                case NetworkEnumerators.RequestType.DELETE:
                    _webRequest = new UnityWebRequest(uri, UnityWebRequest.kHttpVerbDELETE);
                    break;

                case NetworkEnumerators.RequestType.POST:
                    _webRequest = new UnityWebRequest(uri, UnityWebRequest.kHttpVerbPOST);
                    break;

                case NetworkEnumerators.RequestType.CREATE:
                    _webRequest = new UnityWebRequest(uri, UnityWebRequest.kHttpVerbCREATE);
                    break;

                case NetworkEnumerators.RequestType.PATCH:
                    _webRequest = new UnityWebRequest(uri, "PATCH");
                    break;

                case NetworkEnumerators.RequestType.PUT:
                    _webRequest = new UnityWebRequest(uri, UnityWebRequest.kHttpVerbPUT);
                    break;
                }

                if (!string.IsNullOrEmpty(data))
                {
                    _webRequest.uploadHandler = new UploadHandlerRaw(bytes);
                }

                _webRequest.downloadHandler = new DownloadHandlerBuffer();
                _webRequest.SetRequestHeader("Content-Type", "application/json");

                if (checkCeritifcates)
                {
#if UNITY_ANDROID
                    _webRequest.SetRequestHeader("X-Android-Package", NetworkConstants.PACKAGE_NAME);
                    _webRequest.SetRequestHeader("X-Android-Cert", NetworkConstants.KEY_SIGNATURE);
#endif
                }
            }
            break;

            default: break;
            }
        }