Exemple #1
0
        private IActionResult GetResponse(AppRequests requests, string requestName)
        {
            var authResult = _auth.Validate(Request);

            if (authResult.Status != ResponseStatus.Succeeded)
            {
                return(Unauthorized());
            }

            var req = new RequestParams(new AppActor(authResult.Content.Sub, _users.Get(authResult.Content.Sub).Roles),
                                        requestName, GetRawBodyString());

            var response = requests.Execute(req);

            return(new JsonHttpResponse(response));
        }
Exemple #2
0
    private void OnRequestsLoadComplete(FBResult result)
    {
        if (result.Error == null)
        {
//			Debug.Log(result.Text);

            Dictionary <string, object> JSON = ANMiniJSON.Json.Deserialize(result.Text) as Dictionary <string, object>;
            List <object> data = JSON["data"]  as List <object>;


            AppRequests.Clear();
            foreach (object row in data)
            {
                FBAppRequest request = new FBAppRequest();
                Dictionary <string, object> dataRow = row as Dictionary <string, object>;



                Dictionary <string, object> AppInfo = dataRow["application"]  as Dictionary <string, object>;
                request.ApplicationId = System.Convert.ToString(AppInfo["id"]);
                if (!request.ApplicationId.Equals(FB.AppId))
                {
                    break;
                }



                Dictionary <string, object> FromInfo = dataRow["from"]  as Dictionary <string, object>;
                request.FromId   = System.Convert.ToString(FromInfo["id"]);
                request.FromName = System.Convert.ToString(FromInfo["name"]);



                request.Id = System.Convert.ToString(dataRow["id"]);
                request.SetCreatedTime(System.Convert.ToString(dataRow["created_time"]));

                if (dataRow.ContainsKey("data"))
                {
                    request.Data = System.Convert.ToString(dataRow["data"]);
                }

                if (dataRow.ContainsKey("message"))
                {
                    request.Message = System.Convert.ToString(dataRow["message"]);
                }


                if (dataRow.ContainsKey("message"))
                {
                    request.Message = System.Convert.ToString(dataRow["message"]);
                }



                if (dataRow.ContainsKey("action_type"))
                {
                    string action_type = System.Convert.ToString(dataRow["action_type"]);
                    switch (action_type)
                    {
                    case "send":
                        request.ActionType = FBAppRequestActionType.Send;
                        break;

                    case "askfor":
                        request.ActionType = FBAppRequestActionType.AskFor;
                        break;

                    case "turn":
                        request.ActionType = FBAppRequestActionType.Turn;
                        break;
                    }
                }


                if (dataRow.ContainsKey("object"))
                {
                    FBObject obj = new FBObject();
                    Dictionary <string, object> objectData = dataRow["object"] as Dictionary <string, object>;

                    obj.Id    = System.Convert.ToString(objectData["id"]);
                    obj.Title = System.Convert.ToString(objectData["id"]);
                    obj.Type  = System.Convert.ToString(objectData["id"]);
                    obj.SetCreatedTime(System.Convert.ToString(objectData["created_time"]));

                    if (objectData.ContainsKey("image"))
                    {
                        List <object> images = objectData["image"] as List <object>;
                        Debug.Log(objectData["image"]);
                        foreach (object img in images)
                        {
                            Dictionary <string, object> imgData = img as Dictionary <string, object>;
                            obj.AddImageUrl(System.Convert.ToString(imgData["url"]));
                        }
                    }

                    request.Object = obj;
                }


                AppRequests.Add(request);
            }

            Debug.Log("SPFacebook: " + AppRequests.Count + "App request Loaded");
        }
        else
        {
            Debug.LogWarning("SPFacebook: App requests failed to load");
            Debug.LogWarning(result.Error.ToString());
        }


        OnAppRequestsLoaded(result);
    }