Example #1
0
        public static Tuple <User, ApiCallResponse> unblock(string access_token, string usernameOrId)
        {
            ApiCallResponse apiCallResponse = new ApiCallResponse();
            User            user            = new User();

            try
            {
                if (string.IsNullOrEmpty(access_token))
                {
                    apiCallResponse.success      = false;
                    apiCallResponse.errorMessage = "Missing parameter access_token";
                    return(new Tuple <User, ApiCallResponse>(user, apiCallResponse));
                }
                if (string.IsNullOrEmpty(usernameOrId))
                {
                    apiCallResponse.success      = false;
                    apiCallResponse.errorMessage = "Missing parameter usernameOrId";
                    return(new Tuple <User, ApiCallResponse>(user, apiCallResponse));
                }
                string requestUrl = Common.baseUrl + "/users/" + Common.formatUserIdOrUsername(usernameOrId) + "/block";
                Dictionary <string, string> headers = new Dictionary <string, string>();
                headers.Add("Authorization", "Bearer " + access_token);
                Helper.Response response = Helper.SendDeleteRequest(requestUrl, headers);

                return(Helper.getData <User>(response));
            }
            catch (Exception exp)
            {
                apiCallResponse.success          = false;
                apiCallResponse.errorMessage     = exp.Message;
                apiCallResponse.errorDescription = exp.StackTrace;
            }
            return(new Tuple <User, ApiCallResponse>(user, apiCallResponse));
        }
Example #2
0
        public static Tuple <List <Post>, ApiCallResponse> getGlobalStream(string access_token, Parameters parameter = null)
        {
            ApiCallResponse apiCallResponse = new ApiCallResponse();
            List <Post>     posts           = new List <Post>();

            try
            {
                if (string.IsNullOrEmpty(access_token))
                {
                    apiCallResponse.success      = false;
                    apiCallResponse.errorMessage = "Missing parameter access_token";
                    return(new Tuple <List <Post>, ApiCallResponse>(posts, apiCallResponse));
                }
                string requestUrl = Common.baseUrl + "/posts/streams/global";
                if (parameter != null)
                {
                    requestUrl = requestUrl + "?" + parameter.getQueryString();
                }
                Dictionary <string, string> headers = new Dictionary <string, string>();
                headers.Add("Authorization", "Bearer " + access_token);

                Helper.Response response = Helper.SendGetRequest(requestUrl, headers);

                return(Helper.getData <List <Post> >(response));
            }
            catch (Exception exp)
            {
                apiCallResponse.success          = false;
                apiCallResponse.errorMessage     = exp.Message;
                apiCallResponse.errorDescription = exp.StackTrace;
            }
            return(new Tuple <List <Post>, ApiCallResponse>(posts, apiCallResponse));
        }
Example #3
0
        public static Tuple <List <User>, ApiCallResponse> getBlockedUserIdsForMultipleUser(string access_token, List <string> userIds)
        {
            ApiCallResponse apiCallResponse = new ApiCallResponse();
            List <User>     users           = new List <User>();

            try
            {
                if (string.IsNullOrEmpty(access_token))
                {
                    apiCallResponse.success      = false;
                    apiCallResponse.errorMessage = "Missing parameter access_token";
                    return(new Tuple <List <User>, ApiCallResponse>(users, apiCallResponse));
                }
                if (userIds == null)
                {
                    apiCallResponse.success      = false;
                    apiCallResponse.errorMessage = "Missing parameter userIds";
                    return(new Tuple <List <User>, ApiCallResponse>(users, apiCallResponse));
                }
                string requestUrl = Common.baseUrl + "/users/blocked/ids?=" + string.Join(",", userIds);
                Dictionary <string, string> headers = new Dictionary <string, string>();
                headers.Add("Authorization", "Bearer " + access_token);
                Helper.Response response = Helper.SendGetRequest(requestUrl, headers);

                return(Helper.getData <List <User> >(response));
            }
            catch (Exception exp)
            {
                apiCallResponse.success          = false;
                apiCallResponse.errorMessage     = exp.Message;
                apiCallResponse.errorDescription = exp.StackTrace;
            }
            return(new Tuple <List <User>, ApiCallResponse>(users, apiCallResponse));
        }
        public JsonResult AddOutPartialView(AddInViewModel addIn)
        {
            Response _res = new Helper.Response();

            if (Amount < addIn.Amount)
            {
                _res.Code = 0; _res.Message = "提现数量大于您当前持有的货币额"; return(Json(_res));
            }
            if (ModelState.IsValid)
            {
                Interaction interaction = new Interaction();
                interaction.FWalletID     = WalletID;
                interaction.Amount        = addIn.Amount;
                interaction.WalletAddress = addIn.WalletAddrress;
                interaction.Status        = 0;
                interaction.InOrOut       = -1;
                interaction.OperatingTime = DateTime.Now;
                _res = _interaction.Add(interaction);
            }
            if (_res.Code == 1)
            {
                _res.Message = "已提交申请";
            }
            return(Json(_res));
        }
Example #5
0
        public static Tuple <File, ApiCallResponse> getFile(string access_token, string file_id, FileQueryParameters parameter = null)
        {
            ApiCallResponse apiCallResponse = new ApiCallResponse();
            File            file            = new File();

            try
            {
                if (string.IsNullOrEmpty(access_token))
                {
                    apiCallResponse.success      = false;
                    apiCallResponse.errorMessage = "Missing parameter access_token";
                    return(new Tuple <File, ApiCallResponse>(file, apiCallResponse));
                }
                if (string.IsNullOrEmpty(file_id))
                {
                    apiCallResponse.success      = false;
                    apiCallResponse.errorMessage = "Missing parameter file_id";
                    return(new Tuple <File, ApiCallResponse>(file, apiCallResponse));
                }

                string requestUrl = Common.baseUrl + "/stream/0/files/" + file_id;
                Dictionary <string, string> headers = new Dictionary <string, string>();
                headers.Add("Authorization", "Bearer " + access_token);
                Helper.Response response = Helper.SendGetRequest(requestUrl, headers);

                return(Helper.getData <File>(response));
            }
            catch (Exception exp)
            {
                apiCallResponse.success          = false;
                apiCallResponse.errorMessage     = exp.Message;
                apiCallResponse.errorDescription = exp.StackTrace;
            }
            return(new Tuple <File, ApiCallResponse>(file, apiCallResponse));
        }
Example #6
0
        public static Tuple <List <File>, ApiCallResponse> getFiles(string access_token, string comma_separated_list_of_ids, FileQueryParameters parameter = null)
        {
            ApiCallResponse apiCallResponse = new ApiCallResponse();
            List <File>     files           = new List <File>();

            try
            {
                if (string.IsNullOrEmpty(access_token))
                {
                    apiCallResponse.success      = false;
                    apiCallResponse.errorMessage = "Missing parameter access_token";
                    return(new Tuple <List <File>, ApiCallResponse>(files, apiCallResponse));
                }
                if (string.IsNullOrEmpty(comma_separated_list_of_ids))
                {
                    apiCallResponse.success      = false;
                    apiCallResponse.errorMessage = "Missing parameter comma_separated_list_of_ids";
                    return(new Tuple <List <File>, ApiCallResponse>(files, apiCallResponse));
                }

                string requestUrl = Common.baseUrl + "/stream/0/files?ids=" + comma_separated_list_of_ids;
                Dictionary <string, string> headers = new Dictionary <string, string>();
                headers.Add("Authorization", "Bearer " + access_token);
                Helper.Response response = Helper.SendGetRequest(requestUrl, headers);

                return(Helper.getData <List <File> >(response));
            }
            catch (Exception exp)
            {
                apiCallResponse.success          = false;
                apiCallResponse.errorMessage     = exp.Message;
                apiCallResponse.errorDescription = exp.StackTrace;
            }
            return(new Tuple <List <File>, ApiCallResponse>(files, apiCallResponse));
        }
Example #7
0
        public static Tuple <List <Filter>, ApiCallResponse> getForCurrentUser(string access_token)
        {
            ApiCallResponse apiCallResponse = new ApiCallResponse();
            List <Filter>   filters         = new List <Filter>();

            try
            {
                if (string.IsNullOrEmpty(access_token))
                {
                    apiCallResponse.success      = false;
                    apiCallResponse.errorMessage = "Missing parameter access_token";
                    return(new Tuple <List <Filter>, ApiCallResponse>(filters, apiCallResponse));
                }
                string requestUrl = Common.baseUrl + "/stream/0/filters";
                Dictionary <string, string> headers = new Dictionary <string, string>();
                headers.Add("Authorization", "Bearer " + access_token);
                Helper.Response response = Helper.SendGetRequest(requestUrl, headers);

                return(Helper.getData <List <Filter> >(response));
            }
            catch (Exception exp)
            {
                apiCallResponse.success          = false;
                apiCallResponse.errorMessage     = exp.Message;
                apiCallResponse.errorDescription = exp.StackTrace;
            }
            return(new Tuple <List <Filter>, ApiCallResponse>(filters, apiCallResponse));
        }
Example #8
0
        public static Tuple <Post, ApiCallResponse> delete(string access_token, string id)
        {
            ApiCallResponse apiCallResponse = new ApiCallResponse();
            Post            post            = new Post();

            try
            {
                if (string.IsNullOrEmpty(access_token))
                {
                    apiCallResponse.success      = false;
                    apiCallResponse.errorMessage = "Missing parameter access_token";
                    return(new Tuple <Post, ApiCallResponse>(post, apiCallResponse));
                }
                if (string.IsNullOrEmpty(id))
                {
                    apiCallResponse.success      = false;
                    apiCallResponse.errorMessage = "Missing parameter id";
                    return(new Tuple <Post, ApiCallResponse>(post, apiCallResponse));
                }
                string requestUrl = Common.baseUrl + "/posts/" + id;
                Dictionary <string, string> headers = new Dictionary <string, string>();
                headers.Add("Authorization", "Bearer " + access_token);
                Helper.Response response = Helper.SendDeleteRequest(requestUrl, headers);

                return(Helper.getData <Post>(response));
            }
            catch (Exception exp)
            {
                apiCallResponse.success          = false;
                apiCallResponse.errorMessage     = exp.Message;
                apiCallResponse.errorDescription = exp.StackTrace;
            }
            return(new Tuple <Post, ApiCallResponse>(post, apiCallResponse));
        }
Example #9
0
        public static Tuple <Stream, ApiCallResponse> getStatus(string access_token, string streamId)
        {
            ApiCallResponse apiCallResponse = new ApiCallResponse();
            Stream          stream          = new Stream();

            try
            {
                if (string.IsNullOrEmpty(access_token))
                {
                    apiCallResponse.success      = false;
                    apiCallResponse.errorMessage = "Missing parameter access_token";
                    return(new Tuple <Stream, ApiCallResponse>(stream, apiCallResponse));
                }
                string requestUrl = Common.baseUrl + "/streams/" + streamId;
                Dictionary <string, string> headers = new Dictionary <string, string>();
                headers.Add("Authorization", "Bearer " + access_token);
                Helper.Response response = Helper.SendGetRequest(requestUrl, headers);

                return(Helper.getData <Stream>(response));
            }
            catch (Exception exp)
            {
                apiCallResponse.success          = false;
                apiCallResponse.errorMessage     = exp.Message;
                apiCallResponse.errorDescription = exp.StackTrace;
            }
            return(new Tuple <Stream, ApiCallResponse>(stream, apiCallResponse));
        }
Example #10
0
        public static Tuple <Configuration, ApiCallResponse> get()
        {
            {
                ApiCallResponse apiCallResponse = new ApiCallResponse();
                Configuration   configuration   = new Configuration();
                try
                {
                    string requestUrl = Common.baseUrl + "/sys/config";

                    Dictionary <string, string> headers = new Dictionary <string, string>();

                    Helper.Response response = Helper.SendGetRequest(
                        requestUrl,
                        headers);

                    return(Helper.getData <Configuration>(response));
                }
                catch (Exception exp)
                {
                    apiCallResponse.success          = false;
                    apiCallResponse.errorMessage     = exp.Message;
                    apiCallResponse.errorDescription = exp.StackTrace;
                }
                return(new Tuple <Configuration, ApiCallResponse>(configuration, apiCallResponse));
            }
        }
Example #11
0
        public static Tuple <List <Post>, ApiCallResponse> getTaggedPosts(string hashtag, Parameters parameter = null)
        {
            ApiCallResponse apiCallResponse = new ApiCallResponse();
            List <Post>     emptyList       = new List <Post>();

            try
            {
                if (string.IsNullOrEmpty(hashtag))
                {
                    apiCallResponse.success      = false;
                    apiCallResponse.errorMessage = "Missing parameter hashtag";
                    return(new Tuple <List <Post>, ApiCallResponse>(emptyList, apiCallResponse));
                }
                if (hashtag.StartsWith("#"))
                {
                    hashtag = hashtag.TrimStart('#');
                }
                string requestUrl = Common.baseUrl + "/posts/tag/" + hashtag;
                if (parameter != null)
                {
                    requestUrl = requestUrl + "?" + parameter.getQueryString();
                }
                Dictionary <string, string> headers = new Dictionary <string, string>();

                Helper.Response response = Helper.SendGetRequest(requestUrl, headers);
                return(Helper.getData <List <Post> >(response));
            }
            catch (Exception exp)
            {
                apiCallResponse.success          = false;
                apiCallResponse.errorMessage     = exp.Message;
                apiCallResponse.errorDescription = exp.StackTrace;
            }
            return(new Tuple <List <Post>, ApiCallResponse>(emptyList, apiCallResponse));
        }
Example #12
0
        public ActionResult ChangePw(ChangePWViewModel cpw)
        {
            User user = _user.Find(int.Parse(Session["UserID"].ToString()));

            if (Security.SHA256(cpw.Password) != user.Password)
            {
                ViewBag.Message = "<div class=\"alert alert-danger\" role=\"alert\"><span class=\"glyphicon glyphicon-ok\"></span>与原来的密码不一致</div>"; return(View(cpw));
            }
            if (ModelState.IsValid)
            {
                Response _res = new Helper.Response();
                if (Security.SHA256(cpw.ConfirmPassword) != user.Password)
                {
                    _res = _user.ChangePassword(user.UserID, Security.SHA256(cpw.ConfirmPassword));
                    if (_res.Code == 1)
                    {
                        ViewBag.Message = "<div class=\"alert alert-success\" role=\"alert\"><span class=\"glyphicon glyphicon-ok\"></span>修改密码成功!</div>";
                    }
                    else
                    {
                        ViewBag.Message = "<div class=\"alert alert-danger\" role=\"alert\"><span class=\"glyphicon glyphicon-remove\"></span>修改密码失败!</div>";
                    }
                }
            }
            return(View(cpw));
        }
Example #13
0
        public static Tuple <List <User>, ApiCallResponse> getBlockedUsers(string access_token, string userIdOrName = "me", Parameters parameter = null)
        {
            ApiCallResponse apiCallResponse = new ApiCallResponse();
            List <User>     users           = new List <User>();

            try
            {
                if (string.IsNullOrEmpty(access_token))
                {
                    apiCallResponse.success      = false;
                    apiCallResponse.errorMessage = "Missing parameter access_token";
                    return(new Tuple <List <User>, ApiCallResponse>(users, apiCallResponse));
                }
                string requestUrl = Common.baseUrl + "/users/" + userIdOrName + "/blocked";
                if (parameter != null)
                {
                    requestUrl += "?" + parameter.getQueryString();
                }
                Dictionary <string, string> headers = new Dictionary <string, string>();
                headers.Add("Authorization", "Bearer " + access_token);
                Helper.Response response = Helper.SendGetRequest(requestUrl, headers);

                return(Helper.getData <List <User> >(response));
            }
            catch (Exception exp)
            {
                apiCallResponse.success          = false;
                apiCallResponse.errorMessage     = exp.Message;
                apiCallResponse.errorDescription = exp.StackTrace;
            }
            return(new Tuple <List <User>, ApiCallResponse>(users, apiCallResponse));
        }
Example #14
0
 public ApiCallResponse(Helper.Response response)
 {
     if (response != null)
     {
         this.success      = response.Success;
         this.errorMessage = response.Error;
         this.content      = response.Content;
         this.statusCode   = response.StatusCode;
         this.rateLimits   = response.rateLimits;
     }
 }
Example #15
0
        public static Tuple <StreamMarker, ApiCallResponse> set(string access_token, string streamName, string id, int percentage)
        {
            ApiCallResponse apiCallResponse        = new ApiCallResponse();
            StreamMarker    receivedStreamMarker   = new StreamMarker();
            StreamMarker    toBeStoredStreamMarker = new StreamMarker();

            try
            {
                if (string.IsNullOrEmpty(access_token))
                {
                    apiCallResponse.success      = false;
                    apiCallResponse.errorMessage = "Missing parameter access_token";
                    return(new Tuple <StreamMarker, ApiCallResponse>(receivedStreamMarker, apiCallResponse));
                }
                if (string.IsNullOrEmpty(id))
                {
                    apiCallResponse.success      = false;
                    apiCallResponse.errorMessage = "Missing parameter id";
                    return(new Tuple <StreamMarker, ApiCallResponse>(receivedStreamMarker, apiCallResponse));
                }
                if (string.IsNullOrEmpty(streamName))
                {
                    apiCallResponse.success      = false;
                    apiCallResponse.errorMessage = "Missing parameter streamName";
                    return(new Tuple <StreamMarker, ApiCallResponse>(receivedStreamMarker, apiCallResponse));
                }

                toBeStoredStreamMarker.name       = streamName;
                toBeStoredStreamMarker.id         = id;
                toBeStoredStreamMarker.percentage = percentage;

                string jsonString = JsonConvert.SerializeObject(toBeStoredStreamMarker);

                string requestUrl = Common.baseUrl + "/markers";
                Dictionary <string, string> headers = new Dictionary <string, string>();
                headers.Add("Authorization", "Bearer " + access_token);
                Helper.Response response = Helper.SendPostRequestStringDataOnly(
                    requestUrl,
                    jsonString,
                    headers,
                    true,
                    contentType: "application/json");

                return(Helper.getData <StreamMarker>(response));
            }
            catch (Exception exp)
            {
                apiCallResponse.success          = false;
                apiCallResponse.errorMessage     = exp.Message;
                apiCallResponse.errorDescription = exp.StackTrace;
            }
            return(new Tuple <StreamMarker, ApiCallResponse>(receivedStreamMarker, apiCallResponse));
        }
Example #16
0
        public static Tuple <Channel, ApiCallResponse> update(string access_token, string id, List <Annotation> annotations, ACL readers = null, ACL writers = null)
        {
            ApiCallResponse apiCallResponse = new ApiCallResponse();
            Channel         channel         = new Channel();

            try
            {
                if (string.IsNullOrEmpty(access_token))
                {
                    apiCallResponse.success      = false;
                    apiCallResponse.errorMessage = "Missing parameter access_token";
                    return(new Tuple <Channel, ApiCallResponse>(channel, apiCallResponse));
                }
                if (string.IsNullOrEmpty(id))
                {
                    apiCallResponse.success      = false;
                    apiCallResponse.errorMessage = "Missing parameter id";
                    return(new Tuple <Channel, ApiCallResponse>(channel, apiCallResponse));
                }

                string requestUrl = Common.baseUrl + "/channels/" + id;

                channel.raw     = annotations;
                channel.readers = readers;
                channel.writers = writers;

                JsonSerializerSettings settings = new JsonSerializerSettings();
                settings.NullValueHandling = NullValueHandling.Ignore;

                string jsonString = JsonConvert.SerializeObject(channel, Formatting.None, settings);

                Dictionary <string, string> headers = new Dictionary <string, string>();
                headers.Add("Authorization", "Bearer " + access_token);
                headers.Add("X-ADN-Migration-Overrides", "response_envelope=1");
                Helper.Response response = Helper.SendPutRequestStringDataOnly(
                    requestUrl,
                    jsonString,
                    headers,
                    true,
                    contentType: "application/json");

                return(Helper.getData <Channel>(response));
            }
            catch (Exception exp)
            {
                apiCallResponse.success          = false;
                apiCallResponse.errorMessage     = exp.Message;
                apiCallResponse.errorDescription = exp.StackTrace;
            }
            return(new Tuple <Channel, ApiCallResponse>(channel, apiCallResponse));
        }
Example #17
0
        public static Tuple <File, ApiCallResponse> delete(string access_token, string file_id, FileQueryParameters parameter = null)
        {
            ApiCallResponse apiCallResponse = new ApiCallResponse();
            File            file            = new File();

            if (string.IsNullOrEmpty(access_token))
            {
                apiCallResponse.success      = false;
                apiCallResponse.errorMessage = "Missing parameter access_token";
                return(new Tuple <File, ApiCallResponse>(new File(), apiCallResponse));
            }
            if (string.IsNullOrEmpty(file_id))
            {
                apiCallResponse.success      = false;
                apiCallResponse.errorMessage = "Missing parameter file_id";
                return(new Tuple <File, ApiCallResponse>(new File(), apiCallResponse));
            }
            try
            {
                string requestUrl = Common.baseUrl + "/stream/0/files/" + file_id;

                Dictionary <string, string> headers = new Dictionary <string, string>();
                headers.Add("Authorization", "Bearer " + access_token);

                Helper.Response response = Helper.SendDeleteRequest(
                    requestUrl,
                    headers
                    );

                return(Helper.getData <File>(response));
            }
            catch (WebException e)
            {
                WebResponse response = e.Response;

                HttpWebResponse httpResponse = (HttpWebResponse)response;
                Console.WriteLine("Error code: {0}", httpResponse.StatusCode);
                System.IO.Stream data = response.GetResponseStream();

                string text = new System.IO.StreamReader(data).ReadToEnd();
                Console.WriteLine(text);
            }
            catch (Exception exp)
            {
                apiCallResponse.success          = false;
                apiCallResponse.errorMessage     = exp.Message;
                apiCallResponse.errorDescription = exp.StackTrace;
            }
            return(new Tuple <File, ApiCallResponse>(file, apiCallResponse));
        }
Example #18
0
            public void subscribe_to_endpoint(StreamingEndpoint endpoint)
            {
                if (endpoint != null)
                {
                    if (endpoint.needs_channel_id && string.IsNullOrEmpty(endpoint.channel_id))
                    {
                        throw new Exception("Channel endpoint is missing in subsciption");
                    }
                    if (string.IsNullOrEmpty(connection_id))
                    {
                        to_be_subscribed_endpoints.Add(endpoint);
                        return;
                    }

                    string request_url = string.Format("https://alpha-api.app.net{0}?connection_id={1}&ct={2}", endpoint.endpoint, System.Web.HttpUtility.UrlEncode(connection_id), "AppNet.net");
                    if (endpoint.options != null)
                    {
                        if (!string.IsNullOrEmpty(endpoint.options.query_string()))
                        {
                            request_url += "&" + endpoint.options.query_string();
                        }
                    }

                    Dictionary <string, string> header = new Dictionary <string, string>();
                    header.Add("Authorization", "Bearer " + access_token);

                    Helper.Response subscription_response = Helper.SendGetRequest(request_url, header);

                    if (subscription_response.Success)
                    {
                        Tuple <string, ApiCallResponse> apiCallResponse = Helper.getData <string>(subscription_response);
                        if (apiCallResponse != null)
                        {
                            if (apiCallResponse.Item2 != null)
                            {
                                if (apiCallResponse.Item2.meta != null)
                                {
                                    string subscription_id = apiCallResponse.Item2.meta.subscription_id;
                                    endpoint.subscription_id = subscription_id;
                                    if (!string.IsNullOrEmpty(subscription_id))
                                    {
                                        subscribed_endpoints.Add(subscription_id, endpoint);
                                    }
                                }
                            }
                        }
                    }
                }
            }
Example #19
0
        public static Tuple <Message, ApiCallResponse> delete(string access_token, string channelId, string messageId)
        {
            {
                ApiCallResponse apiCallResponse = new ApiCallResponse();
                Message         message         = new Message();

                try
                {
                    if (string.IsNullOrEmpty(access_token))
                    {
                        apiCallResponse.success      = false;
                        apiCallResponse.errorMessage = "Missing parameter access_token";
                        return(new Tuple <Message, ApiCallResponse>(message, apiCallResponse));
                    }
                    if (string.IsNullOrEmpty(channelId))
                    {
                        apiCallResponse.success      = false;
                        apiCallResponse.errorMessage = "Missing channelId";
                        return(new Tuple <Message, ApiCallResponse>(message, apiCallResponse));
                    }
                    if (string.IsNullOrEmpty(messageId))
                    {
                        apiCallResponse.success      = false;
                        apiCallResponse.errorMessage = "Missing messageId";
                        return(new Tuple <Message, ApiCallResponse>(message, apiCallResponse));
                    }

                    string requestUrl = Common.baseUrl + "/stream/0/channels/" + channelId + "/messages/" + messageId;

                    Dictionary <string, string> headers = new Dictionary <string, string>();
                    headers.Add("Authorization", "Bearer " + access_token);
                    headers.Add("X-ADN-Migration-Overrides", "response_envelope=1");
                    Helper.Response response = Helper.SendDeleteRequest(
                        requestUrl,
                        headers);

                    return(Helper.getData <Message>(response));
                }
                catch (Exception exp)
                {
                    apiCallResponse.success          = false;
                    apiCallResponse.errorMessage     = exp.Message;
                    apiCallResponse.errorDescription = exp.StackTrace;
                }
                return(new Tuple <Message, ApiCallResponse>(message, apiCallResponse));
            }
        }
Example #20
0
        public static Tuple <List <Message>, ApiCallResponse> getMessagesInChannel(string access_token, string channelId, messageParameters parameters = null)
        {
            {
                ApiCallResponse apiCallResponse = new ApiCallResponse();
                List <Message>  messages        = new List <Message>();
                try
                {
                    if (string.IsNullOrEmpty(access_token))
                    {
                        apiCallResponse.success      = false;
                        apiCallResponse.errorMessage = "Missing parameter access_token";
                        return(new Tuple <List <Message>, ApiCallResponse>(messages, apiCallResponse));
                    }
                    if (string.IsNullOrEmpty(channelId))
                    {
                        apiCallResponse.success      = false;
                        apiCallResponse.errorMessage = "Missing channelId";
                        return(new Tuple <List <Message>, ApiCallResponse>(messages, apiCallResponse));
                    }


                    string requestUrl = Common.baseUrl + "/stream/0/channels/" + channelId + "/messages";

                    if (parameters != null)
                    {
                        requestUrl += "/?" + parameters.getQueryString();
                    }

                    Dictionary <string, string> headers = new Dictionary <string, string>();
                    headers.Add("Authorization", "Bearer " + access_token);
                    Helper.Response response = Helper.SendGetRequest(
                        requestUrl,
                        headers);

                    return(Helper.getData <List <Message> >(response));
                }
                catch (Exception exp)
                {
                    apiCallResponse.success          = false;
                    apiCallResponse.errorMessage     = exp.Message;
                    apiCallResponse.errorDescription = exp.StackTrace;
                }
                return(new Tuple <List <Message>, ApiCallResponse>(messages, apiCallResponse));
            }
        }
Example #21
0
            public static Tuple <Channel, ApiCallResponse> subscribe(string access_token, string id)
            {
                ApiCallResponse apiCallResponse = new ApiCallResponse();
                Channel         channel         = new Channel();

                try
                {
                    if (string.IsNullOrEmpty(access_token))
                    {
                        apiCallResponse.success      = false;
                        apiCallResponse.errorMessage = "Missing parameter access_token";
                        return(new Tuple <Channel, ApiCallResponse>(channel, apiCallResponse));
                    }
                    if (string.IsNullOrEmpty(id))
                    {
                        apiCallResponse.success      = false;
                        apiCallResponse.errorMessage = "Missing parameter id";
                        return(new Tuple <Channel, ApiCallResponse>(channel, apiCallResponse));
                    }

                    string requestUrl = Common.baseUrl + "/channels/" + id + "/subscribe";

                    Dictionary <string, string> headers = new Dictionary <string, string>();
                    headers.Add("Authorization", "Bearer " + access_token);
                    //headers.Add("X-ADN-Migration-Overrides", "response_envelope=1");
                    Helper.Response response = Helper.SendPutRequest(
                        requestUrl,
                        new
                    {
                        channel_id = id
                    },
                        additionalHeaders: headers);

                    return(Helper.getData <Channel>(response));
                }
                catch (Exception exp)
                {
                    apiCallResponse.success          = false;
                    apiCallResponse.errorMessage     = exp.Message;
                    apiCallResponse.errorDescription = exp.StackTrace;
                }
                return(new Tuple <Channel, ApiCallResponse>(channel, apiCallResponse));
            }
Example #22
0
        public static Tuple <Channel, ApiCallResponse> get(string access_token, string id, channelParameters parameters = null)
        {
            ApiCallResponse apiCallResponse = new ApiCallResponse();
            Channel         channel         = new Channel();

            try
            {
                if (string.IsNullOrEmpty(access_token))
                {
                    apiCallResponse.success      = false;
                    apiCallResponse.errorMessage = "Missing parameter access_token";
                    return(new Tuple <Channel, ApiCallResponse>(channel, apiCallResponse));
                }
                if (string.IsNullOrEmpty(id))
                {
                    apiCallResponse.success      = false;
                    apiCallResponse.errorMessage = "Missing parameter id";
                    return(new Tuple <Channel, ApiCallResponse>(channel, apiCallResponse));
                }

                string requestUrl = Common.baseUrl + "/channels/" + id;
                if (parameters != null)
                {
                    requestUrl += "?" + parameters.getQueryString();
                }

                Dictionary <string, string> headers = new Dictionary <string, string>();
                headers.Add("Authorization", "Bearer " + access_token);
                headers.Add("X-ADN-Migration-Overrides", "response_envelope=1");
                Helper.Response response = Helper.SendGetRequest(
                    requestUrl,
                    headers);

                return(Helper.getData <Channel>(response));
            }
            catch (Exception exp)
            {
                apiCallResponse.success          = false;
                apiCallResponse.errorMessage     = exp.Message;
                apiCallResponse.errorDescription = exp.StackTrace;
            }
            return(new Tuple <Channel, ApiCallResponse>(channel, apiCallResponse));
        }
Example #23
0
            public static Tuple <List <User>, ApiCallResponse> getSubscribers(string access_token, string id)
            {
                ApiCallResponse apiCallResponse = new ApiCallResponse();
                List <User>     users           = new List <User>();

                try
                {
                    if (string.IsNullOrEmpty(access_token))
                    {
                        apiCallResponse.success      = false;
                        apiCallResponse.errorMessage = "Missing parameter access_token";
                        return(new Tuple <List <User>, ApiCallResponse>(users, apiCallResponse));
                    }
                    if (string.IsNullOrEmpty(access_token))
                    {
                        apiCallResponse.success      = false;
                        apiCallResponse.errorMessage = "Missing parameter id";
                        return(new Tuple <List <User>, ApiCallResponse>(users, apiCallResponse));
                    }

                    string requestUrl = Common.baseUrl + "/channels/" + id + "/subscribers";

                    Dictionary <string, string> headers = new Dictionary <string, string>();
                    headers.Add("Authorization", "Bearer " + access_token);
                    headers.Add("X-ADN-Migration-Overrides", "response_envelope=1");
                    Helper.Response response = Helper.SendGetRequest(
                        requestUrl,
                        headers);

                    return(Helper.getData <List <User> >(response));
                }
                catch (Exception exp)
                {
                    apiCallResponse.success          = false;
                    apiCallResponse.errorMessage     = exp.Message;
                    apiCallResponse.errorDescription = exp.StackTrace;
                }
                return(new Tuple <List <User>, ApiCallResponse>(users, apiCallResponse));
            }
Example #24
0
        public static Tuple <List <User>, ApiCallResponse> searchUsers(string access_token, string searchString, Parameters parameter = null)
        {
            ApiCallResponse apiCallResponse = new ApiCallResponse();
            List <User>     users           = new List <User>();

            try
            {
                if (string.IsNullOrEmpty(access_token))
                {
                    apiCallResponse.success      = false;
                    apiCallResponse.errorMessage = "Missing parameter access_token";
                    return(new Tuple <List <User>, ApiCallResponse>(users, apiCallResponse));
                }
                if (string.IsNullOrEmpty(searchString))
                {
                    apiCallResponse.success      = false;
                    apiCallResponse.errorMessage = "Missing parameter searchString";
                    return(new Tuple <List <User>, ApiCallResponse>(users, apiCallResponse));
                }
                string requestUrl = Common.baseUrl + "/stream/0/users/search?q=" + System.Web.HttpUtility.HtmlEncode(searchString);
                if (parameter != null)
                {
                    requestUrl += "?" + parameter.getQueryString();
                }
                Dictionary <string, string> headers = new Dictionary <string, string>();
                headers.Add("Authorization", "Bearer " + access_token);
                Helper.Response response = Helper.SendGetRequest(requestUrl, headers);

                return(Helper.getData <List <User> >(response));
            }
            catch (Exception exp)
            {
                apiCallResponse.success          = false;
                apiCallResponse.errorMessage     = exp.Message;
                apiCallResponse.errorDescription = exp.StackTrace;
            }
            return(new Tuple <List <User>, ApiCallResponse>(users, apiCallResponse));
        }
Example #25
0
        public static Tuple <Filter, ApiCallResponse> create(string access_token, Filter filter)
        {
            ApiCallResponse apiCallResponse = new ApiCallResponse();
            Filter          createdFilter   = new Filter();

            try
            {
                if (string.IsNullOrEmpty(access_token))
                {
                    apiCallResponse.success      = false;
                    apiCallResponse.errorMessage = "Missing parameter access_token";
                    return(new Tuple <Filter, ApiCallResponse>(createdFilter, apiCallResponse));
                }
                if (filter == null)
                {
                    apiCallResponse.success      = false;
                    apiCallResponse.errorMessage = "Missing parameter Filter";
                    return(new Tuple <Filter, ApiCallResponse>(createdFilter, apiCallResponse));
                }
                string requestUrl = Common.baseUrl + "/stream/0/filters";
                Dictionary <string, string> headers = new Dictionary <string, string>();
                headers.Add("Authorization", "Bearer " + access_token);
                Helper.Response response = Helper.SendPostRequest(requestUrl, new
                {
                    createdFilter = JsonConvert.SerializeObject(filter)
                },
                                                                  headers);

                return(Helper.getData <Filter>(response));
            }
            catch (Exception exp)
            {
                apiCallResponse.success          = false;
                apiCallResponse.errorMessage     = exp.Message;
                apiCallResponse.errorDescription = exp.StackTrace;
            }
            return(new Tuple <Filter, ApiCallResponse>(filter, apiCallResponse));
        }
Example #26
0
        /// <summary>
        /// When a request is made to create a Post the provided body text is processed for entities. You can use this endpoint to test how App.net will parse text for entities as well as render text as html.
        /// Calls to this endpoint will not create or update any objects in App.net
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="text"></param>
        /// <returns></returns>
        public static Tuple <Post, ApiCallResponse> process(string access_token, string text)
        {
            ApiCallResponse apiCallResponse = new ApiCallResponse();
            Post            post            = new Post();

            try
            {
                if (string.IsNullOrEmpty(access_token))
                {
                    apiCallResponse.success      = false;
                    apiCallResponse.errorMessage = "Missing parameter access_token";
                    return(new Tuple <Post, ApiCallResponse>(post, apiCallResponse));
                }
                if (string.IsNullOrEmpty(text))
                {
                    apiCallResponse.success      = false;
                    apiCallResponse.errorMessage = "Missing parameter text";
                    return(new Tuple <Post, ApiCallResponse>(post, apiCallResponse));
                }
                string requestUrl = Common.baseUrl + "/stream/0/text/process";
                Dictionary <string, string> headers = new Dictionary <string, string>();
                headers.Add("Authorization", "Bearer " + access_token);
                Helper.Response response = Helper.SendPostRequestStringDataOnly(
                    requestUrl,
                    "text=" + System.Web.HttpUtility.UrlEncode(text),
                    headers,
                    true);

                return(Helper.getData <Post>(response));
            }
            catch (Exception exp)
            {
                apiCallResponse.success          = false;
                apiCallResponse.errorMessage     = exp.Message;
                apiCallResponse.errorDescription = exp.StackTrace;
            }
            return(new Tuple <Post, ApiCallResponse>(post, apiCallResponse));
        }
Example #27
0
        public static Tuple <User, ApiCallResponse> followByUsernameOrId(string access_token, string usernameOrId, Parameters parameter = null)
        {
            ApiCallResponse apiCallResponse = new ApiCallResponse();
            User            user            = new User();

            try
            {
                if (string.IsNullOrEmpty(access_token))
                {
                    apiCallResponse.success      = false;
                    apiCallResponse.errorMessage = "Missing parameter access_token";
                    return(new Tuple <User, ApiCallResponse>(user, apiCallResponse));
                }
                if (string.IsNullOrEmpty(usernameOrId))
                {
                    apiCallResponse.success      = false;
                    apiCallResponse.errorMessage = "Missing parameter usernameOrId";
                    return(new Tuple <User, ApiCallResponse>(user, apiCallResponse));
                }
                string requestUrl = Common.baseUrl + "/stream/0/users/" + Common.formatUserIdOrUsername(usernameOrId) + "/follow";
                if (parameter != null)
                {
                    requestUrl += "?" + parameter.getQueryString();
                }
                Dictionary <string, string> headers = new Dictionary <string, string>();
                headers.Add("Authorization", "Bearer " + access_token);
                Helper.Response response = Helper.SendPostRequest(requestUrl, new object(), headers);

                return(Helper.getData <User>(response));
            }
            catch (Exception exp)
            {
                apiCallResponse.success          = false;
                apiCallResponse.errorMessage     = exp.Message;
                apiCallResponse.errorDescription = exp.StackTrace;
            }
            return(new Tuple <User, ApiCallResponse>(user, apiCallResponse));
        }
Example #28
0
        public static Tuple <List <Post>, ApiCallResponse> getMentionsOfUsernameOrId(string access_token, string usernameOrId, Parameters parameter = null)
        {
            ApiCallResponse apiCallResponse = new ApiCallResponse();
            List <Post>     emptyList       = new List <Post>();

            try
            {
                if (string.IsNullOrEmpty(access_token))
                {
                    apiCallResponse.success      = false;
                    apiCallResponse.errorMessage = "Missing parameter access_token";
                    return(new Tuple <List <Post>, ApiCallResponse>(emptyList, apiCallResponse));
                }
                if (string.IsNullOrEmpty(usernameOrId))
                {
                    apiCallResponse.success      = false;
                    apiCallResponse.errorMessage = "Missing parameter username or id";
                    return(new Tuple <List <Post>, ApiCallResponse>(emptyList, apiCallResponse));
                }
                string requestUrl = Common.baseUrl + "/users/" + Common.formatUserIdOrUsername(usernameOrId) + "/mentions";
                if (parameter != null)
                {
                    requestUrl = requestUrl + "?" + parameter.getQueryString();
                }
                Dictionary <string, string> headers = new Dictionary <string, string>();
                headers.Add("Authorization", "Bearer " + access_token);
                Helper.Response response = Helper.SendGetRequest(requestUrl, headers);
                return(Helper.getData <List <Post> >(response));
            }
            catch (Exception exp)
            {
                apiCallResponse.success          = false;
                apiCallResponse.errorMessage     = exp.Message;
                apiCallResponse.errorDescription = exp.StackTrace;
            }
            return(new Tuple <List <Post>, ApiCallResponse>(emptyList, apiCallResponse));
        }
Example #29
0
        public static Tuple <File, ApiCallResponse> update(string access_token, string file_id, string name = null, List <Annotation> annotations = null, FileQueryParameters parameter = null)
        {
            ApiCallResponse apiCallResponse = new ApiCallResponse();
            File            file            = new File();

            if (string.IsNullOrEmpty(access_token))
            {
                apiCallResponse.success      = false;
                apiCallResponse.errorMessage = "Missing parameter access_token";
                return(new Tuple <File, ApiCallResponse>(new File(), apiCallResponse));
            }
            if (string.IsNullOrEmpty(file_id))
            {
                apiCallResponse.success      = false;
                apiCallResponse.errorMessage = "Missing parameter file_id";
                return(new Tuple <File, ApiCallResponse>(new File(), apiCallResponse));
            }
            if (string.IsNullOrEmpty(name) && annotations == null)
            {
                apiCallResponse.success      = false;
                apiCallResponse.errorMessage = "Missing parameter name or annotations - at least one of those must be set";
                return(new Tuple <File, ApiCallResponse>(new File(), apiCallResponse));
            }


            try
            {
                FileUpdateParameters tempFile = new FileUpdateParameters();
                tempFile.name        = name;
                tempFile.annotations = annotations;

                string requestUrl = Common.baseUrl + "/stream/0/files/" + file_id;
                JsonSerializerSettings settings = new JsonSerializerSettings();
                settings.NullValueHandling = NullValueHandling.Ignore;

                string jsonString = JsonConvert.SerializeObject(tempFile, Formatting.None, settings);

                Dictionary <string, string> headers = new Dictionary <string, string>();
                headers.Add("Authorization", "Bearer " + access_token);

                Helper.Response response = Helper.SendPutRequestStringDataOnly(
                    requestUrl,
                    jsonString,
                    headers,
                    true,
                    contentType: "application/json");

                return(Helper.getData <File>(response));
            }
            catch (WebException e)
            {
                WebResponse response = e.Response;

                HttpWebResponse httpResponse = (HttpWebResponse)response;
                Console.WriteLine("Error code: {0}", httpResponse.StatusCode);
                System.IO.Stream data = response.GetResponseStream();

                string text = new System.IO.StreamReader(data).ReadToEnd();
                Console.WriteLine(text);
            }
            catch (Exception exp)
            {
                apiCallResponse.success          = false;
                apiCallResponse.errorMessage     = exp.Message;
                apiCallResponse.errorDescription = exp.StackTrace;
            }
            return(new Tuple <File, ApiCallResponse>(file, apiCallResponse));
        }
Example #30
0
        public static Tuple <File, ApiCallResponse> create(string access_token, string local_file_path = null, string name = null, string type = null, List <Annotation> annotations = null, string kind = null, FileQueryParameters parameter = null, string mimetype = null)
        {
            ApiCallResponse apiCallResponse = new ApiCallResponse();
            File            file            = new File();

            if (string.IsNullOrEmpty(access_token))
            {
                apiCallResponse.success      = false;
                apiCallResponse.errorMessage = "Missing parameter access_token";
                return(new Tuple <File, ApiCallResponse>(new File(), apiCallResponse));
            }
            if (string.IsNullOrEmpty(type))
            {
                apiCallResponse.success      = false;
                apiCallResponse.errorMessage = "Missing parameter type";
                return(new Tuple <File, ApiCallResponse>(new File(), apiCallResponse));
            }

            try
            {
                FileCreateParameters tempFile = new FileCreateParameters();
                if (!string.IsNullOrEmpty(local_file_path))
                {
                    tempFile.name = System.IO.Path.GetFileName(local_file_path);
                }
                if (!string.IsNullOrEmpty(name))
                {
                    tempFile.name = name;
                }

                tempFile.type        = type;
                tempFile.annotations = annotations;
                tempFile.kind        = kind;

                string requestUrl = Common.baseUrl + "/stream/0/files/";


                JsonSerializerSettings settings = new JsonSerializerSettings();
                settings.NullValueHandling = NullValueHandling.Ignore;

                string jsonString = JsonConvert.SerializeObject(tempFile, Formatting.None, settings);

                Dictionary <string, string> headers = new Dictionary <string, string>();
                headers.Add("Authorization", "Bearer " + access_token);

                Helper.Response response = Helper.SendPostRequestStringDataOnly(
                    requestUrl,
                    jsonString,
                    headers,
                    true,
                    contentType: "application/json");

                Tuple <File, ApiCallResponse> returnValue = Helper.getData <File>(response);

                if (returnValue.Item2.success)
                {
                    if (!string.IsNullOrEmpty(local_file_path))
                    {
                        setContent(access_token, returnValue.Item1.id, local_file_path, mimeType: mimetype);
                        return(returnValue);
                    }
                }
            }
            catch (WebException e)
            {
                WebResponse response = e.Response;

                HttpWebResponse httpResponse = (HttpWebResponse)response;
                Console.WriteLine("Error code: {0}", httpResponse.StatusCode);
                System.IO.Stream data = response.GetResponseStream();

                string text = new System.IO.StreamReader(data).ReadToEnd();
                Console.WriteLine(text);
            }
            catch (Exception exp)
            {
                apiCallResponse.success          = false;
                apiCallResponse.errorMessage     = exp.Message;
                apiCallResponse.errorDescription = exp.StackTrace;
            }
            return(new Tuple <File, ApiCallResponse>(file, apiCallResponse));
        }