Esempio n. 1
0
 /// <summary>
 /// Returns authenticated user's liked media.
 /// </summary>
 /// <exception cref="Exceptions.InstagramAPICallException">Application authorization error.</exception>
 public List <IMedia> GetUserLikedMedia(int count = 0)
 {
     try
     {
         if (count != 0)
         {
             return(mediaJsonController
                    .MapJsonToMedias(UserEndPoint.APICall("self/media/liked",
                                                          new Dictionary <string, string>()
             {
                 { "count", count.ToString() }
             })));
         }
         else
         {
             return(mediaJsonController
                    .MapJsonToMedias(UserEndPoint.APICall("self/media/liked")));
         }
     }
     catch (Exceptions.InstagramAPICallException e)
     {
         throw new Exceptions.InstagramAPICallException(e.ToString());
     }
     catch (Exception)
     {
         return(null);
     }
 }
Esempio n. 2
0
        public static async Task <StatusCodeResult> Send(string text, int userID, bool start = false)
        {
            userEndpoint = Zulip.zclient.GetUserEndPoint();
            var name   = "user_" + userID;
            var email  = name + "@healthapp.my.to";
            var _users = await userEndpoint.GetUsers();

            var _user = _users.FirstOrDefault(x => x.Email == email);;

            if (start)
            {
                if (_user == null)
                {                                                          //пароль нужен сильный
                    await userEndpoint.CreateUser(new ZulipAPI.User(email, "password51651651651651651", name, name));

                    _users = await userEndpoint.GetUsers();

                    _user = _users.FirstOrDefault(x => x.Email == email);
                }
            }

            try
            {
                var client          = await new ZulipServer(AppInfo.ZulipServerURL).LoginAsync(_user.Email, "password51651651651651651");
                var messageEndpoint = client.GetMessageEndPoint();
                await messageEndpoint.SendStreamMessage("Medical things", "test-topic", text);
            }
            catch (Exception ex)
            {
                return(new StatusCodeResult(StatusCodes.Status500InternalServerError));
            }
            return(new StatusCodeResult(StatusCodes.Status200OK));
        }
Esempio n. 3
0
 public async Task Setup()
 {
     if (File.Exists(".zuliprc"))
     {
         zclient      = ZulipServer.Login(".zuliprc");
         userEndpoint = zclient.GetUserEndPoint();
         await RefreshData();
     }
 }
Esempio n. 4
0
        private async void btnTestConnection_Click(object sender, System.EventArgs e)
        {
            await Program.GetZulipClient();

            userEndPoint = Program.client?.GetUserEndPoint();
            try {
                var users = await userEndPoint.GetUsers();

                dgvUsers.DataSource = users;
            } catch (System.Exception ex) {
                MessageBox.Show(ex.ToString());
            }
        }
Esempio n. 5
0
        private void InitControls()
        {
            msgEndPoint    = msgEndPoint ?? Program.client.GetMessageEndPoint();
            userEndPoint   = userEndPoint ?? Program.client.GetUserEndPoint();
            streamEndPoint = streamEndPoint ?? Program.client.GetStreamEndPoint();

            txtPrivateMsg.Text     = $"new private message sent via .NET client at {DateTime.Now}";
            txtStreamMsg.Text      = $"new stream message sent via .NET client at {DateTime.Now}";
            txtStreamTopic.Text    = "API Test";
            lblPMResponse.Text     = "";
            lblStreamResponse.Text = "";

            toolTip1.SetToolTip(this.numAnchor, "Is the message id from which you want to get x messages before and y messages after.\r\nIf you set Anchor really high (by default) it will automatically use the highest message id available; the most recent one.");
            toolTip1.SetToolTip(this.numBefore, "Number of messages to be retrieve before the anchor message.\r\nIf Anchor is beyond the most recent message, this will retrieve that number of messages.\r\nAfter will have no effect");
            toolTip1.SetToolTip(this.numAfter, "Only useful if you set Anchor to an actcual message id and then get messages after that point,\r\nie. going back to an old topic's first message, then using this to get messages after that.");
        }
Esempio n. 6
0
 /// <summary>
 /// Returns the profile of the user with id "id".
 /// </summary>
 /// <exception cref="Exceptions.InstagramAPICallException">Application authorization error.</exception>
 public Models.IUser GetUserProfile(long id)
 {
     try
     {
         return(userJsonController
                .MapJsonToUser(UserEndPoint.APICall(id.ToString())));
     }
     catch (Exceptions.InstagramAPICallException e)
     {
         throw new Exceptions.InstagramAPICallException(e.ToString());
     }
     catch (Exception)
     {
         return(null);
     }
 }
Esempio n. 7
0
 /// <summary>
 /// Make the api call to get authenticated user.
 /// If api call is incorrect returns null.
 /// </summary>
 /// <returns>Authenticated User</returns>
 /// <exception cref="Exceptions.InstagramAPICallException">Application authorization error.</exception>
 public Models.IUser GetAuthenticatedUser()
 {
     try
     {
         return(userJsonController
                .MapJsonToUser(UserEndPoint.APICall("self")));
     }
     catch (Exceptions.InstagramAPICallException e)
     {
         throw new Exceptions.InstagramAPICallException(e.ToString());
     }
     catch (Exception)
     {
         return(null);
     }
 }
Esempio n. 8
0
        private async void LnkGetUsers_Click(object sender, System.EventArgs e)
        {
            await Program.GetZulipClient();

            FillingDataSource = true;
            try {
                userEndPoint = userEndPoint ?? Program.client.GetUserEndPoint();
                _users       = await userEndPoint.GetUsers();

                cboUsers.DisplayMember = nameof(User.FullName);
                cboUsers.ValueMember   = nameof(User.Email);
                cboUsers.DataSource    = _users;
            } catch (System.Exception ex) {
                MessageBox.Show(ex.ToString());
            }
            FillingDataSource = false;
        }
Esempio n. 9
0
 /// <summary>
 /// Returns a list with recent media of specified user.
 /// </summary>
 /// <exception cref="Exceptions.InstagramAPICallException">Application authorization error.</exception>
 public List <Models.IMedia> GetUserRecentMedia(IUsersQueryParameters parameter = null)
 {
     try
     {
         // Some parameters specified
         if (parameter != null)
         {
             // With only count
             if (parameter.Count != null)
             {
                 return(mediaJsonController
                        .MapJsonToMedias(UserEndPoint.APICall(parameter.Id.ToString() + "/media/recent",
                                                              new Dictionary <string, string>()
                 {
                     { "count", parameter.Count.Value.ToString() }
                 })));
             }
             // With count and id
             else
             {
                 return(mediaJsonController
                        .MapJsonToMedias(UserEndPoint.APICall(parameter.Id.ToString() + "/media/recent",
                                                              new Dictionary <string, string>()
                 {
                     { "count", parameter.Count.Value.ToString() }
                 })));
             }
         }
         // No parameters
         return(mediaJsonController
                .MapJsonToMedias(UserEndPoint.APICall("self/media/recent")));
     }
     catch (Exceptions.InstagramAPICallException e)
     {
         throw new Exceptions.InstagramAPICallException(e.ToString());
     }
     catch (Exception)
     {
         return(null);
     }
 }
        /// <summary>
        /// Return a list of users who match with the specified query. (MinifiedUser)
        /// </summary>
        /// <exception cref="Exceptions.InstagramAPICallException">Authorization error related to application.</exception>
        public List <IMinifiedUser> SearchUsers(ISearchUserParameters _params)
        {
            try
            {
                // If no parameters or not query -> Invalid request
                if (_params == null)
                {
                    return(null);
                }
                if (_params.Query == null)
                {
                    return(null);
                }

                // No count
                if (_params.Count == null)
                {
                    return(userJsonController.MapJsonToMinifiedUsers(UserEndPoint.
                                                                     ApiCallSearch(_params.Query)));
                }
                // With count
                else
                {
                    return(userJsonController.MapJsonToMinifiedUsers(UserEndPoint.
                                                                     ApiCallSearch(_params.Query, _params.Count.Value)));
                }
            }
            catch (Exceptions.InstagramAPICallException e)
            {
                throw e;
            }
            catch (Exception)
            {
                return(null);
            }
        }
Esempio n. 11
0
 public UserService(UserEndPoint endPoint, CompanyEndPoint companyEndPoint)
 {
     _endPoint        = endPoint;
     _companyEndPoint = companyEndPoint;
 }
Esempio n. 12
0
 public UserService(UserEndPoint endPoint)
 {
     _endPoint = endPoint;
 }
Esempio n. 13
0
 private async void BtnCreateUser_Click(object sender, System.EventArgs e)
 {
     userEndPoint = userEndPoint ?? Program.client.GetUserEndPoint();
     var user = new User(txtUserEmail.Text, txtUserPassword.Text, txtShortName.Text, txtFullName.Text);
     await userEndPoint.CreateUser(user);
 }