Ejemplo n.º 1
0
        protected override void HTTPCallback(HTTPResponse res)
        {
            // network error
            if(res.error) {
                if(!keepRetrying && !callbackDelivered) {
                    failedCallback("Network error");
                }

                return;
            }

            if(res.dataLength != 0) {
                keepRetrying = false;

                if(!callbackDelivered) {
                    callbackDelivered = true;
                    callback(res);
                }

                return;
            }
            if(!keepRetrying && !callbackDelivered) {
                failedCallback("Error");
            }
        }
Ejemplo n.º 2
0
 private void HTTPCallback(HTTPResponse res)
 {
     if(res.error) {
     callback(false);
       } else {
     callback(true);
       }
 }
Ejemplo n.º 3
0
        private void failedCallback(string msg)
        {
            callbackDelivered = true;

              HTTPResponse res = new HTTPResponse();
              res.url = request.url;
              res.error = true;
              res.errorMsg = msg;

              callback(res);
        }
Ejemplo n.º 4
0
        private void HTTPCallback(HTTPResponse res)
        {
            //Utils.Log("HTTPCallback at " + Time.realtimeSinceStartup);

              // network error
              if(res.error) {
            if(!keepRetrying && !callbackDelivered) {
              failedCallback("Network error");
            }

            return;
              }

              EventJSON jsonResponse = new EventJSON(System.Text.Encoding.UTF8.GetString(res.data, 0, res.data.Length));

              // check that server response has status "ok"
              if(jsonResponse.hasInt("status")) {
            if(jsonResponse.getInt("status") == 200) {
              // event delivery successful
              keepRetrying = false;

              if(!callbackDelivered) {
            callbackDelivered = true;
            callback(res);
              }

              return;
            }
              }

              // if we didn't get status "ok", then whatever we got will be treated as error

              if(jsonResponse.hasBool("retryable")) {
            bool retry = jsonResponse.getBool("retryable");

            if(!retry) {
              // We have received an error and retrying has been explicitly forbidden
              keepRetrying = false;

              if(!callbackDelivered) {
            failedCallback("Retrying forbidden by remote server");
              }

              return;
            }
              }

              // We have received an error so if there are no more retries, deliver the callback
              if(!keepRetrying && !callbackDelivered) {
            failedCallback("Error");
              }
        }
Ejemplo n.º 5
0
  	private void handleResponse(HTTPResponse res) {
	    bool success = false;

    if (res.error) {
      Utils.LogError("UnityAdsEditor error: Failed to contact server: " + res.errorMsg);
    } else {
      string json = System.Text.Encoding.UTF8.GetString(res.data, 0, res.data.Length);
        
      bool validResponse = false;
        
      object parsedData = MiniJSON.Json.Deserialize(json);
      if(parsedData is Dictionary<string,object>) {
        Dictionary<string,object> parsedJson = (Dictionary<string,object>)parsedData;
        if(parsedJson.ContainsKey("status")) {
          string value = (string)parsedJson["status"];
          if(value.Equals("ok")) {
            validResponse = true;
          } else {
            if(parsedJson.ContainsKey("errorMessage")) {
                Utils.LogError("UnityAdsEditor error: Server returned error message: " + (string)parsedJson["errorMessage"]);
            }
          }
        } else {
            Utils.LogError("UnityAdsEditor error: JSON response does not have status field: " + json);
        }
      } else {
          Utils.LogError("UnityAdsEditor error: unable to parse JSON: " + json);
      }
        
      if(validResponse) {
        success = true;
      } else {
          Utils.LogError("UnityAdsEditor error: Failed to fetch campaigns");
      }
    }
    
    if(success) {
      UnityAds.SharedInstance.onFetchCompleted();
	    ready = true;
    } else {
      UnityAds.SharedInstance.onFetchFailed();
    }
  }
Ejemplo n.º 6
0
    public void execute(System.Action<HTTPResponse> callback) {
      if(Application.internetReachability == NetworkReachability.NotReachable) {
        HTTPResponse response = new HTTPResponse();
        response.url = url;
        response.error = true;
        response.errorMsg = "Internet not reachable";

        callback(response);

        return;
      }

      if(method == HTTPMethod.POST) {
        if(postData == null) {
          postData = new byte[0];
        }

        AsyncExec.runWithCallback<HTTPRequest,HTTPResponse>(executePost, this, callback);
      } else {
        AsyncExec.runWithCallback<HTTPRequest,HTTPResponse>(executeGet, this, callback);
      }
    }
Ejemplo n.º 7
0
        private HTTPResponse processWWW(WWW www)
        {
            HTTPResponse response = new HTTPResponse();

              if(!string.IsNullOrEmpty(www.error)) {
            response.error = true;
            response.errorMsg = www.error;
              } else {
            response.error = false;
            response.errorMsg = null;
            response.data = www.bytes;
            response.dataLength = www.bytes.Length;
            response.headers = new Dictionary<string,string>();
            response.etag = "";

            if(www.responseHeaders != null) {
              foreach(KeyValuePair<string,string> header in www.responseHeaders) {
              response.headers.Add(header.Key.ToUpper(), header.Value);
              }

              if(response.headers.ContainsKey("ETAG")) {
              response.etag = response.headers["ETAG"];
              }
            }
              }

              return response;
        }
 private void HTTPJsonCallback(HTTPResponse 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();
 }
        private void HTTPFileCallback(HTTPResponse pictureURLRequestResponse)
        {
            downloadedResourcesCount ++;
            if(pictureURLRequestResponse.dataLength != 0)
                System.IO.File.WriteAllBytes(ad.getLocalImageURL(imageOrientations[pictureURLRequestResponse.url], imageTypes[pictureURLRequestResponse.url]), pictureURLRequestResponse.data);

            if(downloadedResourcesCount == PictureAd.expectedResourcesCount) {
                _resourcesAvailable ();
                _operationCompleteDelegate();
            }
        }