Ejemplo n.º 1
0
        /// <summary>
        /// Facebook API Request
        /// </summary>
        /// <param name="appId"></param>
        /// <param name="appSecret"></param>
        /// <param name="installed"></param>
        /// <returns></returns>
        ///
        internal FacebookTestUserResultModel FacebookTestUserRequest(string appId, string appSecret, bool installed)
        {
            FacebookTestUserResultModel result = new FacebookTestUserResultModel();

            try
            {
                string url  = string.Format("https://graph.facebook.com/{0}/accounts/test-users", appId);
                var    data = new FacebookTestUser
                {
                    AppId     = appId,
                    AppSecret = appSecret,
                    Installed = installed
                };

                string postData = string.Format("installed={0}&access_token={1}|{2}", data.Installed, data.AppId, data.AppSecret);

                result = HttpRequestExtensions.TryPostJson <FacebookTestUserResultModel>(url, postData, 300000);
                if (result == null)
                {
                    result = HttpRequestExtensions.TryPostJson <FacebookTestUserResultModel>(url, postData, 300000);
                }
            }
            catch (Exception exception)
            {
                Logger.Error(exception.Message + "Failed to create Facebook user");
                result = null;
            }
            return(result);
        }
Ejemplo n.º 2
0
        public void http_client()
        {
            var j = new JsonParser();
            //string url = "https://fapi-real.etoro.com/instruments.json";
            string url = "https://fapi-real.etoro.com/instruments/1";

            //string dbapiResult = HttpRequestExtensions.GetHTTPrequest(url);

            j.AddKeyToMemory(Constants.Memory, HttpRequestExtensions.GetHTTPrequest(url));


            string line = @"$$instrumentData j= InstrumentName";

            j.VariableFunctions(line);

            string str = j.replaceVariable("$$instrumentData");


            j.VariableFunctions("$$DataSource = " + str);

            str = j.replaceVariable("$$memory");

            line = @"$$instrumentData j= InstrumentName ==> $$DataSource";
            j.VariableFunctions(line);
            str = j.replaceVariable("$$instrumentData");
        }
Ejemplo n.º 3
0
        public void http_client_adv()
        {
            var j = new JsonParser();

            string url      = "https://openbookmobile.etoro.com/api/login";
            string header   = @"Content-Type::application/x-www-form-urlencoded; charset=utf-8,, User-Agent::OpenBook/2.1 (iPad Simulator; iOS 7.1; Scale/2.00)";
            string mode     = "POST";
            string postdata = @"username=socialalert15&Password=123456m&appName=iOS&ver=2.1";
            string str      = "m=" + mode + " h=" + header + " u=" + url + " p=" + postdata;


            //string dbapiResult = HttpRequestExtensions.GetHTTPrequest(url);

            j.AddKeyToMemory(Constants.Memory, HttpRequestExtensions.GetHTTPrequestPost(str));

            string line = @"$$Token j= Token";

            j.VariableFunctions(line);

            str  = j.replaceVariable("$$Token");
            line = "https://openbookmobile.etoro.com/api/market?username=socialalert15&symbol=GOOG&appName=iOS&ver=2.1&period=180&code=en-gb&token=$$Token";
            j.AddKeyToMemory(Constants.Memory, HttpRequestExtensions.GetHTTPrequest(line));
            line = @"$$MarketValue j= MarketValue";
            j.VariableFunctions(line);
            str = j.replaceVariable("$$MarketValue");

            line = @"$$StockSummary j= StockSummary";
            j.VariableFunctions(line);
            str = j.replaceVariable("$$StockSummary");
        }
Ejemplo n.º 4
0
        // get feed from user wall

        internal List <StreamsApiResultModel.GetStreamRequestModel> GetStream(string username, string actionName, string messageID)
        {
            List <StreamsApiResultModel.GetStreamRequestModel> result = new List <StreamsApiResultModel.GetStreamRequestModel>();

            try
            {
                JsonParser jp  = new JsonParser();
                string     url = string.Format("http://{0}/api/streams", jp.ReadJson("TestingEnvironment"));
                //authorization = HttpUtility.UrlEncode(authorization);
                //string headers = string.Format("{0}", authorization);

                url = url + string.Format("/?actionName={0}", actionName + username);

                result = HttpRequestExtensions.TryGetJson <List <StreamsApiResultModel.GetStreamRequestModel> >(url, 1000);

                if (result == null)
                {
                    Logger.Error("Failed to Get message on userwall");
                }
            }

            catch (Exception ex)
            {
                Logger.Error("Failed to get message on user wall");
            }

            return(result);
        }
Ejemplo n.º 5
0
        // like a message
        internal StreamsApiResultModel.LikeMessageRequestModel LikePost(string actionName, string authorization, string messageID)
        {
            StreamsApiResultModel.LikeMessageRequestModel result = new StreamsApiResultModel.LikeMessageRequestModel();

            try
            {
                JsonParser jp  = new JsonParser();
                string     url = string.Format("http://{0}/api/streams", jp.ReadJson("TestingEnvironment"));
                authorization = HttpUtility.UrlEncode(authorization);
                string headers = string.Format("{0}", authorization);

                string postData = string.Format("actionName={0}", actionName + messageID);

                result = HttpRequestExtensions.TryPostJson <StreamsApiResultModel.LikeMessageRequestModel>(url, headers, postData, 1000);

                if (result == null)
                {
                    Logger.Error("Failed to like message on " + messageID);
                }
            }

            catch (Exception ex)
            {
                Logger.Error(ex.Message + "Failed to like message on " + messageID);
                result = null;
            }

            return(result);
        }
Ejemplo n.º 6
0
        internal FacebookTestUserListResultModel FacebookTestUserListRequest(string appId, string appSecret, int count)
        {
            FacebookTestUserListResultModel result = new FacebookTestUserListResultModel();

            try
            {
                string url = string.Format("https://graph.facebook.com/{0}/accounts", appId);

                string postData = string.Format("type=test-users&access_token={0}|{1}&limit={2}", appId, appSecret, count);

                result = HttpRequestExtensions.TryGetJson <FacebookTestUserListResultModel>(url + "?" + postData, 300000);
                if (result == null)
                {
                    result = HttpRequestExtensions.TryGetJson <FacebookTestUserListResultModel>(url + "?" + postData, 300000);
                }
            }
            catch (Exception exception)
            {
                LogObject logException = new LogObject();
                logException.Description = exception.Message + "Failed to get  Facebook users list ";
                logException.StatusTag   = Constants.ERROR;
                logException.Exception   = exception;
                logger.Print(logException);


                result = null;
            }
            return(result);
        }
Ejemplo n.º 7
0
        internal bool FacebookTestUserFriendRequest(string testUser1Id, string testUser2Id, string testUser1AccessToken, string testUser2AccessToken)
        {
            bool result;

            try
            {
                string url      = string.Format("https://graph.facebook.com/{0}/friends/{1}", testUser1Id, testUser2Id);
                string postData = string.Format("access_token={0}", testUser1AccessToken);

                result = HttpRequestExtensions.TryPostJson <bool>(url, postData, 300000);

                if (result)
                {
                    url      = string.Format("https://graph.facebook.com/{1}/friends/{0}", testUser1Id, testUser2Id);
                    postData = string.Format("access_token={0}", testUser2AccessToken);

                    result = HttpRequestExtensions.TryPostJson <bool>(url, postData);
                    if (!result)
                    {
                        //retry
                        result = HttpRequestExtensions.TryPostJson <bool>(url, postData);
                    }
                }
                else
                {
                    //retry
                    url      = string.Format("https://graph.facebook.com/{1}/friends/{0}", testUser1Id, testUser2Id);
                    postData = string.Format("access_token={0}", testUser2AccessToken);

                    result = HttpRequestExtensions.TryPostJson <bool>(url, postData);
                    if (!result)
                    {
                        //retry
                        result = HttpRequestExtensions.TryPostJson <bool>(url, postData);
                    }
                }
            }
            catch (Exception exception)
            {
                LogObject logException = new LogObject();
                logException.Description = exception.Message + "Failed to create Facebook friends connection ";
                logException.StatusTag   = Constants.ERROR;
                logException.Exception   = exception;

                logger.Print(logException);

                result = false;
            }
            return(result);
        }
Ejemplo n.º 8
0
        // post a new message
        internal StreamsApiResultModel.PostMessageResultModel PostMessageRequest(string actionName, string autorization, string ownerUser, string messageBody)
        {
            StreamsApiResultModel.PostMessageResultModel result = new StreamsApiResultModel.PostMessageResultModel();
            try
            {
                JsonParser jsonParser = new JsonParser();
                string     url        = string.Format("http://{0}/api/streams", jsonParser.ReadJson("TestingEnvironment"));
                autorization = HttpUtility.UrlEncode(autorization);
                string headers = string.Format("{0}", autorization);

                string postData = string.Format("actionName={0}&ownerUser={1}&messageBody={2}", actionName, ownerUser, messageBody);

                result = HttpRequestExtensions.TryPostJson <StreamsApiResultModel.PostMessageResultModel>(url, headers, postData, 1000);
            }
            catch (Exception exception)
            {
                Logger.Error(exception.Message + "Failed to post message on " + ownerUser);
                result = null;
            }
            return(result);
        }