Пример #1
0
    public HTTPRequest getClone() {
      HTTPRequest clone;

      if(method == HTTPMethod.GET) {
        clone = new HTTPRequest(url);
      } else { // HTTPMethod.POST
        clone = new HTTPRequest("POST", url);
      }

      if(postData != null) {
        if(postData.Length > 0) {
          clone.setPayload(postData);
        }
      }

      if(headers != null) {
        if(headers.Count > 0) {
          foreach(KeyValuePair<string, string> pair in headers) {
            clone.addHeader((string)pair.Key, (string)pair.Value);
          }
        }
      }

      return clone;
    }
 public void downloadJson()
 {
     string requestURLString = requestURL();
     HTTPRequest jsonRequest = new HTTPRequest ("POST", requestURLString);
     jsonRequest.addHeader ("Content-Type", "application/json");
     string jsonInfo = jsonPayload();
     jsonRequest.setPayload (jsonInfo);
     HTTPManager.sendRequest(jsonRequest, HTTPJsonCallback, retryDelays, 20 * 60);
 }
Пример #3
0
    public void execute(System.Action<bool> eventCallback) {
      callback = eventCallback;

      HTTPRequest req = new HTTPRequest("POST", url);
      req.addHeader("Content-Type", "application/json");
      req.setPayload(jsonData);

      HTTPManager.sendRequest(req, HTTPCallback, retryDelayTable, deadlineDelay);
    }
Пример #4
0
    // convenience method for generating simple retry strategy
    public static void sendRequest(HTTPRequest request, System.Action<HTTPResponse> callback, int retries, int delay, int maxDelay) {
      int[] delays = new int[retries];

      for(int i = 0; i < retries; i++) {
        delays[i] = delay;
      }

      sendRequest(request, callback, delays, maxDelay);
    }
Пример #5
0
    public RetryRequest(int[] delays, int maxDelay, HTTPRequest req) {
      retryPosition = 0;
      retryDelayTable = delays;

      if(maxDelay > 0) {
        deadlineDelay = maxDelay;
        useDeadline = true;
      }

      request = req;
    }
Пример #6
0
    public override void init (string gameId, bool testModeEnabled, bool debugModeEnabled, string gameObjectName) {
	    if(initialized) return;
    	initialized = true;

      Utils.LogDebug ("UnityEditor: init(), gameId=" + gameId + ", testModeEnabled=" + testModeEnabled + ", gameObjectName=" + gameObjectName + ", debugModeEnabled=" + debugModeEnabled);

    	string url = "https://impact.applifier.com/mobile/campaigns?platform=editor&gameId=" + WWW.EscapeURL(gameId) + "&unityVersion=" + WWW.EscapeURL(Application.unityVersion);
    	HTTPRequest req = new HTTPRequest(url);
    	req.execute(handleResponse);

  	}
		public void downloadJson() {
			string requestURLString = requestURL();
			HTTPRequest jsonRequest = new HTTPRequest ("POST", requestURLString);
			jsonRequest.addHeader ("Content-Type", "application/json");
			string jsonInfo = jsonPayload();
			jsonRequest.setPayload (jsonInfo);
			jsonRequest.execute(response => {
        if(response.dataLength == 0) return;
        string jsonString = System.Text.Encoding.UTF8.GetString(response.data, 0, response.dataLength);
				EventManager.sendAdplanEvent(Engine.Instance.AppId);
				_jsonAvailable(jsonString);
				_operationCompleteDelegate();
			});
		}
		void executeRequestForResource(PictureAd ad, ImageOrientation imageOrientation, ImageType imageType) {
			string filePath = ad.getLocalImageURL(imageOrientation, imageType);
			if (System.IO.File.Exists(filePath)) {
				downloadedResourcesCount++;
				if(downloadedResourcesCount == PictureAd.expectedResourcesCount) {
					_resourcesAvailable ();
					_operationCompleteDelegate();
				}
				return;
			}
			string url = ad.getRemoteImageURL(imageOrientation, imageType);
			HTTPRequest pictureURLRequest = new HTTPRequest(url);
			pictureURLRequest.execute(pictureURLRequestResponse => {
				downloadedResourcesCount ++;
				if(pictureURLRequestResponse.dataLength != 0)
					System.IO.File.WriteAllBytes(ad.getLocalImageURL(imageOrientation, imageType), pictureURLRequestResponse.data);
				
				if(downloadedResourcesCount == PictureAd.expectedResourcesCount) {
					_resourcesAvailable ();
					_operationCompleteDelegate();
				}
			});
		}
Пример #9
0
    // request: HTTP request to be sent and retried
    // callback: callback method to call with server response (or failure)
    // delays: table with retry delays in seconds, allows exponential retry strategy e.g. [10, 20, 40, 80, 160, 320] means six retries with increasing intervals
    // maxDelay: maximum amount of seconds until callback is sent and all pending retries are considered timed out
    public static void sendRequest(HTTPRequest request, System.Action<HTTPResponse> callback, int[] delays, int maxDelay) {
      RetryRequest req = new RetryRequest(delays, maxDelay, request);

      req.execute(callback);
    }
Пример #10
0
        private IEnumerator executePost(HTTPRequest req, System.Action<HTTPResponse> callback)
        {
            WWW www = null;

              if(networkLogging) {
            printUp("POST", req.url);
              }

              Type wwwType = typeof(UnityEngine.WWW);
              ConstructorInfo wwwConstructor = wwwType.GetConstructor(new Type[] {typeof(string), typeof(byte[]), typeof(Dictionary<string, string>)});
              ConstructorInfo wwwConstructorOld = wwwType.GetConstructor(new Type[] {typeof(string), typeof(byte[]), typeof(Hashtable)});
              if(wwwConstructor == null && wwwConstructorOld != null) {
            Hashtable tempHeaders = new Hashtable(req.headers);
            www = (WWW)wwwConstructorOld.Invoke(new object[] {req.url, req.postData, tempHeaders});
              } else {
            www = (WWW)wwwConstructor.Invoke(new object[] {req.url, req.postData, req.headers});
              }

              yield return www;

              HTTPResponse response = processWWW(www);
              response.url = req.url;

              if(networkLogging) {
            printDown(req.url, www.bytes);
              }

              callback(response);
        }
Пример #11
0
        private IEnumerator executeGet(HTTPRequest req, System.Action<HTTPResponse> callback)
        {
            if(networkLogging) {
            printUp("GET", req.url);
              }

              WWW www = new WWW(req.url);

              yield return www;

              HTTPResponse response = processWWW(www);
              response.url = req.url;

              if(networkLogging) {
            printDown(req.url, www.bytes);
              }

              callback(response);
        }
    void Update() {
			if(!adIsShowing)
				return;
			float distinct = currentTime - previousTime;
			increase = distinct/animationDuration;
			if(!_isClosed)
				showAnimation ();
			else
				hideAnimation ();
      
      if(Input.GetMouseButtonDown(0)) {
        if(mouseInRect(texturesRects[screenOrientation][ImageType.CloseActiveArea])) {
          EventManager.sendCloseEvent(Engine.Instance.AppId, _ad.id, false);
          _isClosed = true;
          manager.pictureAdClosed();
          return;
       	}

        if(mouseInRect(texturesRects[screenOrientation][ImageType.Base])) {
          EventManager.sendClickEvent(Engine.Instance.AppId, _ad.id);
          HTTPRequest request = new HTTPRequest("POST", _ad.clickActionUrl);
          request.addHeader("Content-Type", "application/json");
          request.setPayload(DeviceInfo.getJson());
          request.execute((HTTPResponse response) => {
            if(response != null && response.data != null) {
              string jsonString = System.Text.Encoding.UTF8.GetString(response.data, 0, response.dataLength);
              object jsonObject = MiniJSON.Json.Deserialize(jsonString);
              if(jsonObject != null && jsonObject is Dictionary<string, object>) {
                Dictionary<string, object> json = (Dictionary<string, object>)jsonObject;
                string redirectLocation = (string)json["clickUrl"];
                if(redirectLocation != null) {
                  Application.OpenURL(redirectLocation);
                }
              }
            }
          });
          return;
        }
      }
			previousTime = currentTime;
			currentTime = Time.realtimeSinceStartup;
    }
 void executeRequestForResource(PictureAd ad, ImageOrientation imageOrientation, ImageType imageType)
 {
     string filePath = ad.getLocalImageURL(imageOrientation, imageType);
     if (System.IO.File.Exists(filePath)) {
         downloadedResourcesCount++;
         if(downloadedResourcesCount == PictureAd.expectedResourcesCount) {
             _resourcesAvailable ();
             _operationCompleteDelegate();
         }
         return;
     }
     string url = ad.getRemoteImageURL(imageOrientation, imageType);
     HTTPRequest pictureURLRequest = new HTTPRequest(url);
     imageTypes[url] = imageType;
     imageOrientations[url] = imageOrientation;
     HTTPManager.sendFileRequest(pictureURLRequest, HTTPFileCallback, retryDelays, 20 * 60);
 }
Пример #14
0
 public RetryFileRequest(int[] delays, int maxDelay, HTTPRequest req) : base(delays, maxDelay, req)
 {
 }
Пример #15
0
    private IEnumerator executeGet(HTTPRequest req, System.Action<HTTPResponse> callback) {
      WWW www = new WWW(req.url);

      yield return www;

      HTTPResponse response = processWWW(www);
      response.url = req.url;

      callback(response);
    }
        // request: HTTP request to be sent and retried
        // callback: callback method to call with server response (or failure)
        // delays: table with retry delays in seconds, allows exponential retry strategy e.g. [10, 20, 40, 80, 160, 320] means six retries with increasing intervals
        // maxDelay: maximum amount of seconds until callback is sent and all pending retries are considered timed out
        public static void sendRequest(HTTPRequest request, System.Action <HTTPResponse> callback, int[] delays, int maxDelay)
        {
            RetryRequest req = new RetryRequest(delays, maxDelay, request);

            req.execute(callback);
        }
Пример #17
0
 public RetryFileRequest(int[] delays, int maxDelay, HTTPRequest req)
     : base(delays, maxDelay, req)
 {
 }