Example #1
0
        public static Tuple<Filter, ApiCallResponse> delete(string access_token, string filterId)
        {
            ApiCallResponse apiCallResponse = new ApiCallResponse();
            Filter filter = new Filter();
            try
            {
                if (string.IsNullOrEmpty(access_token))
                {
                    apiCallResponse.success = false;
                    apiCallResponse.errorMessage = "Missing parameter access_token";
                    return new Tuple<Filter, ApiCallResponse>(filter, apiCallResponse);
                }
                if (string.IsNullOrEmpty(filterId))
                {
                    apiCallResponse.success = false;
                    apiCallResponse.errorMessage = "Missing parameter filterId";
                    return new Tuple<Filter, ApiCallResponse>(filter, apiCallResponse);
                }
                string requestUrl = Common.baseUrl + "/stream/0/filters/" + filterId;
                Dictionary<string, string> headers = new Dictionary<string, string>();
                headers.Add("Authorization", "Bearer " + access_token);
                Helper.Response response = Helper.SendDeleteRequest(requestUrl, 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 #2
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 #3
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 #4
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 #5
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 #6
0
 public static Tuple<User,ApiCallResponse> unfollowByUsernameOrId(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";
         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 #7
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));
        }
Example #8
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 #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 + "/stream/0/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 <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 #11
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 #12
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 #13
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 + "/stream/0/posts/stream/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 #14
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 #15
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 #16
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 #17
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 #18
0
 private void sendIssue(AppNetDotNet.ApiCalls.ApiCallResponse issue)
 {
     if (issue != null)
     {
         UserInterface.Report_issue issue_window = new UserInterface.Report_issue(issue);
         issue_window.Show();
     }
 }
Example #19
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 #20
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 #21
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 #22
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 #23
0
        public static Tuple<Channel, ApiCallResponse> create(string access_token, string type, 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);
                }

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

                channel.annotations = annotations;
                channel.readers = readers;
                channel.writers = writers;
                channel.type = type;

                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.SendPostRequestStringDataOnly(
                        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 #24
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 #25
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 #26
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 #27
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 #28
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 #29
0
        public static Tuple<Channel, ApiCallResponse> get(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 += "/stream/0/channels/" + id;

                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 #30
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 #31
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 #32
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));
        }
        /// <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 #34
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 #35
0
        public static Tuple<List<Place>, ApiCallResponse> search(string access_token, 
            decimal latitude, 
            decimal longitude,
            string query = null,
            decimal radius = -1,
            int count = -1,
            decimal altitude = -100000,
            decimal horizontal_accuracy = -100000,
            decimal vertical_accuracy = -100000

            )
        {
            {
                ApiCallResponse apiCallResponse = new ApiCallResponse();
                List<Place> places = new List<Place>();
                try
                {
                    if (string.IsNullOrEmpty(access_token))
                    {
                        apiCallResponse.success = false;
                        apiCallResponse.errorMessage = "Missing parameter access_token";
                        return new Tuple<List<Place>, ApiCallResponse>(places, apiCallResponse);
                    }
                
                    string searchParameters = "?latitude=" + latitude + "&longitude=" + longitude;
                    searchParameters = searchParameters.Replace(",", ".");
                        if(!string.IsNullOrEmpty(query)) {
                            searchParameters += "&q=" + query;
                        }
                        if (radius >= 0)
                        {
                            searchParameters += "&radius=" + radius;
                        }
                        if (count > 0)
                        {
                            searchParameters += "&count=" + count;
                        }
                        if (altitude != -100000)
                        {
                            searchParameters += "&altitude=" + altitude;
                        }
                        if (horizontal_accuracy != -100000)
                        {
                            searchParameters += "&horizontal_accuracy=" + horizontal_accuracy;
                        }
                        if (vertical_accuracy != -100000)
                        {
                            searchParameters += "&vertical_accuracy=" + vertical_accuracy;
                        }

                        string requestUrl = Common.baseUrl + "/stream/0/places/search" + searchParameters;

                    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<Place>>(response);
                }
                catch (Exception exp)
                {
                    apiCallResponse.success = false;
                    apiCallResponse.errorMessage = exp.Message;
                    apiCallResponse.errorDescription = exp.StackTrace;
                }
                return new Tuple<List<Place>, ApiCallResponse>(places, apiCallResponse);
            }
        }
Example #36
0
            public static Tuple<Post,ApiCallResponse> create(string access_token, string text, string reply_to = null, List<File> toBeEmbeddedFiles = null, List<Annotation> annotations = null, Entities entities = null, int machine_only = 0)
            {
                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/posts";
                    Dictionary<string, string> headers = new Dictionary<string, string>();
                    headers.Add("Authorization", "Bearer " + access_token);

                    postCreateParameters postCreateContent = new postCreateParameters();
                    postCreateContent.text = text;
                    postCreateContent.reply_to = reply_to;
                    postCreateContent.machine_only = machine_only;
                    postCreateContent.entities = new EntitiesWithoutAllProperty(entities);
                    //postCreateContent.annotations = annotations;
                    if (toBeEmbeddedFiles != null)
                    {
                        if (postCreateContent.annotations == null)
                        {
                            postCreateContent.annotations = new List<AppNetDotNet.Model.Annotations.AnnotationReplacement_File>();
                        }
                        foreach (File file in toBeEmbeddedFiles)
                        {
                            AppNetDotNet.Model.Annotations.AnnotationReplacement_File fileReplacementAnnotation = new AppNetDotNet.Model.Annotations.AnnotationReplacement_File(file);
                            postCreateContent.annotations.Add(fileReplacementAnnotation);
                        }
                    }

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

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

                    jsonString = jsonString.Replace("netAppCoreFile_dummy_for_replacement", "+net.app.core.file");

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

                        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 #37
0
            /// <summary>
            /// Report a post as spam. This will mute the author of the post and send a report to App.net.
            /// </summary>
            /// <param name="access_token">the user access token</param>
            /// <param name="id">the id of the post to be reported</param>
            /// <returns></returns>
            public static Tuple<Post, ApiCallResponse> report(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 + string.Format("/stream/0/posts/{0}/report",id);
                    Dictionary<string, string> headers = new Dictionary<string, string>();
                    headers.Add("Authorization", "Bearer " + access_token);
                    Helper.Response response = Helper.SendPostRequest(
                        requestUrl, 
                        new Dictionary<string,string>(),
                        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 #38
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 #39
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));
        }
Example #40
0
        public static ApiCallResponse setContent(string access_token, string file_id, string local_file_path, string file_type = null, string mimeType = null, 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(apiCallResponse);
                }
                if (string.IsNullOrEmpty(local_file_path))
                {
                    apiCallResponse.success      = false;
                    apiCallResponse.errorMessage = "Missing parameter local_file_path";
                    return(apiCallResponse);
                }
                if (string.IsNullOrEmpty(file_id))
                {
                    apiCallResponse.success      = false;
                    apiCallResponse.errorMessage = "Missing parameter file_id";
                    return(apiCallResponse);
                }

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

                if (!System.IO.File.Exists(local_file_path))
                {
                    apiCallResponse.success          = false;
                    apiCallResponse.errorMessage     = "File not found";
                    apiCallResponse.errorDescription = "The local file has not been found at " + local_file_path;
                }
                else
                {
                    System.IO.FileStream fs = new System.IO.FileStream(local_file_path, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                    byte[] data             = new byte[fs.Length];
                    fs.Read(data, 0, data.Length);
                    fs.Close();

                    if (string.IsNullOrEmpty(mimeType))
                    {
                        mimeType = Helper.getMimeFromFile(local_file_path);
                    }

                    Helper.Response response = Helper.SendPutRequestBinaryDataOnly(
                        requestUrl,
                        data,
                        headers,
                        true,
                        contentType: mimeType
                        );

                    apiCallResponse = new ApiCallResponse(response);
                    return(apiCallResponse);
                }
            }
            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(apiCallResponse);
        }
Example #41
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 + "/stream/0/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);
        }
Example #42
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 #43
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 #44
0
        public static Tuple<Message, ApiCallResponse> get(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);
                Helper.Response response = Helper.SendGetRequest(
                        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 #45
0
        public static ApiCallResponse setContent(string access_token, string file_id, string local_file_path, string file_type = null, string mimeType = null, 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 apiCallResponse;
                }
                if (string.IsNullOrEmpty(local_file_path))
                {
                    apiCallResponse.success = false;
                    apiCallResponse.errorMessage = "Missing parameter local_file_path";
                    return apiCallResponse;
                }
                if (string.IsNullOrEmpty(file_id))
                {
                    apiCallResponse.success = false;
                    apiCallResponse.errorMessage = "Missing parameter file_id";
                    return apiCallResponse;
                }

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

                    if (!System.IO.File.Exists(local_file_path))
                    {
                        apiCallResponse.success = false;
                        apiCallResponse.errorMessage = "File not found";
                        apiCallResponse.errorDescription = "The local file has not been found at " + local_file_path;
                    }
                    else
                    {
                        System.IO.FileStream fs = new System.IO.FileStream(local_file_path, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                        byte[] data = new byte[fs.Length];
                        fs.Read(data, 0, data.Length);
                        fs.Close();

                        if (string.IsNullOrEmpty(mimeType))
                        {
                            mimeType = Helper.getMimeFromFile(local_file_path);
                        }
                         
                        Helper.Response response = Helper.SendPutRequestBinaryDataOnly(
                                requestUrl,
                                data,
                                headers,
                                true,
                                contentType: mimeType 
                                );

                        apiCallResponse = new ApiCallResponse(response);
                        return apiCallResponse;
                    }
            
            }
            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 apiCallResponse;
        }
Example #46
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)
        {
            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);
                        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);
        }
Example #47
0
        public static Tuple<List<User>,ApiCallResponse> searchUsers(string access_token, string searchString)
        {
            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);
                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 #48
0
        public static Tuple <Post, ApiCallResponse> create(string access_token, string text, string reply_to = null, List <File> toBeEmbeddedFiles = null, List <Annotation> annotations = null, Entities entities = null, bool?parse_links = null)
        {
            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 + "/posts";
                Dictionary <string, string> headers = new Dictionary <string, string>();
                headers.Add("Authorization", "Bearer " + access_token);

                postCreateParameters postCreateContent = new postCreateParameters();
                postCreateContent.text     = text;
                postCreateContent.reply_to = reply_to;
                //postCreateContent.entities = new EntitiesWithoutAllProperty(entities);
                //postCreateContent.annotations = annotations;

                /*if (postCreateContent.entities != null)
                 * {
                 *  postCreateContent.entities.parse_links = parse_links;
                 * }*/


                if (toBeEmbeddedFiles != null)
                {
                    if (postCreateContent.annotations == null)
                    {
                        postCreateContent.annotations = new List <AppNetDotNet.Model.Annotations.AnnotationReplacement_File>();
                    }
                    foreach (File file in toBeEmbeddedFiles)
                    {
                        AppNetDotNet.Model.Annotations.AnnotationReplacement_File fileReplacementAnnotation = new AppNetDotNet.Model.Annotations.AnnotationReplacement_File(file);
                        postCreateContent.annotations.Add(fileReplacementAnnotation);
                    }
                }

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

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

                jsonString = jsonString.Replace("netAppCoreFile_dummy_for_replacement", "+net.app.core.file");

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

                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 #49
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 #50
0
            public static Tuple<List<Channel>, ApiCallResponse> getOfCurrentUser(string access_token, channelParameters parameters = null)
            {
                ApiCallResponse apiCallResponse = new ApiCallResponse();
                List<Channel> channels = new List<Channel>();
                try
                {
                    if (string.IsNullOrEmpty(access_token))
                    {
                        apiCallResponse.success = false;
                        apiCallResponse.errorMessage = "Missing parameter access_token";
                        return new Tuple<List<Channel>, ApiCallResponse>(channels, apiCallResponse);
                    }

                    string requestUrl = Common.baseUrl + "/stream/0/channels";
                    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<List<Channel>>(response);
                }
                catch (Exception exp)
                {
                    apiCallResponse.success = false;
                    apiCallResponse.errorMessage = exp.Message;
                    apiCallResponse.errorDescription = exp.StackTrace;
                }
                return new Tuple<List<Channel>, ApiCallResponse>(channels, apiCallResponse);
            }
Example #51
0
            private void ParseMessage(string json)
            {
                Helper.Response api_response = new Helper.Response();
                api_response.Success = true;
                api_response.Content = json;

                ApiCallResponse apiCallResponse = new ApiCallResponse();

                apiCallResponse.success = true;
                apiCallResponse.content = json;

                Newtonsoft.Json.Linq.JObject responseJson = Newtonsoft.Json.Linq.JObject.Parse(json);
                JsonSerializerSettings       settings     = new JsonSerializerSettings();

                settings.Error += delegate(object sender, Newtonsoft.Json.Serialization.ErrorEventArgs args)
                {
                    throw args.ErrorContext.Error;
                };
                if (responseJson != null)
                {
                    try
                    {
                        apiCallResponse.meta = JsonConvert.DeserializeObject <Model.Meta>(responseJson["meta"].ToString(), settings);
                    }
                    catch (Exception exp) {
                        apiCallResponse.success          = false;
                        apiCallResponse.errorMessage     = exp.Message;
                        apiCallResponse.errorDescription = exp.StackTrace;
                        return;
                    }
                }

                if (apiCallResponse.meta != null)
                {
                    if (apiCallResponse.meta.subscription_ids != null)
                    {
                        string data = null;
                        try
                        {
                            data = responseJson["data"].ToString();
                        }
                        catch { return; }
                        if (string.IsNullOrEmpty(data))
                        {
                            return;
                        }
                        foreach (string subscription_id in apiCallResponse.meta.subscription_ids)
                        {
                            if (subscribed_endpoints.ContainsKey(subscription_id))
                            {
                                StreamingEndpoint endpoint = subscribed_endpoints[subscription_id];
                                if (endpoint != null)
                                {
                                    switch (endpoint.title)
                                    {
                                    case "Following":
                                        List <User> following = JsonConvert.DeserializeObject <List <User> >(data, settings);
                                        if (following != null && followingCallback != null)
                                        {
                                            followingCallback(following, is_deleted: apiCallResponse.meta.is_deleted);
                                        }
                                        break;

                                    case "Followers":
                                        List <User> followers = JsonConvert.DeserializeObject <List <User> >(data, settings);
                                        if (followers != null && followersCallback != null)
                                        {
                                            followersCallback(followers, is_deleted: apiCallResponse.meta.is_deleted);
                                        }
                                        break;

                                    case "Posts":
                                        List <Post> posts = JsonConvert.DeserializeObject <List <Post> >(data, settings);
                                        if (posts != null && postsCallback != null)
                                        {
                                            postsCallback(posts, is_deleted: apiCallResponse.meta.is_deleted);
                                        }
                                        break;

                                    case "Mentions":
                                        List <Post> mentions = JsonConvert.DeserializeObject <List <Post> >(data, settings);
                                        if (mentions != null && mentionsCallback != null)
                                        {
                                            mentionsCallback(mentions, is_deleted: apiCallResponse.meta.is_deleted);
                                        }
                                        break;

                                    case "Stream":
                                        List <Post> stream = JsonConvert.DeserializeObject <List <Post> >(data, settings);
                                        if (stream != null && streamCallback != null)
                                        {
                                            streamCallback(stream, is_deleted: apiCallResponse.meta.is_deleted);
                                        }
                                        break;

                                    case "Unified":
                                        List <Post> unified_posts = JsonConvert.DeserializeObject <List <Post> >(data, settings);
                                        if (unified_posts != null && unifiedCallback != null)
                                        {
                                            unifiedCallback(unified_posts, is_deleted: apiCallResponse.meta.is_deleted);
                                        }
                                        break;

                                    case "Channels":
                                        List <Message> channels = JsonConvert.DeserializeObject <List <Message> >(data, settings);
                                        if (channels != null && channelsCallback != null)
                                        {
                                            channelsCallback(channels, is_deleted: apiCallResponse.meta.is_deleted);
                                        }
                                        break;

                                    case "Channel subscribers":
                                        List <User> subscribers = JsonConvert.DeserializeObject <List <User> >(data, settings);
                                        if (subscribers != null && channelSubscribersCallback != null)
                                        {
                                            channelSubscribersCallback(subscribers, is_deleted: apiCallResponse.meta.is_deleted);
                                        }
                                        break;

                                    case "Channel messages":
                                        List <Message> messages = JsonConvert.DeserializeObject <List <Message> >(data, settings);
                                        if (messages != null && channelMessagesCallback != null)
                                        {
                                            channelMessagesCallback(messages, is_deleted: apiCallResponse.meta.is_deleted);
                                        }
                                        break;

                                    case "Files":
                                        List <AppNetDotNet.Model.File> files = JsonConvert.DeserializeObject <List <AppNetDotNet.Model.File> >(data, settings);
                                        if (files != null && filesCallback != null)
                                        {
                                            filesCallback(files, is_deleted: apiCallResponse.meta.is_deleted);
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
Example #52
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 + "/stream/0/posts/marker";
                    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 #53
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 #54
0
        public static Tuple<Message, ApiCallResponse> create(string access_token, string text, string channelId, List<string> receipientUsersnameOrIds, string reply_to = null, List<Annotation> annotations = null, Entities entities = null, int machineOnly = 0)
        {
            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(text))
                {
                    apiCallResponse.success = false;
                    apiCallResponse.errorMessage = "Missing parameter text";
                    return new Tuple<Message, ApiCallResponse>(message, apiCallResponse);
                }
                if (channelId.ToLower() == "pm" && receipientUsersnameOrIds == null)
                {
                    apiCallResponse.success = false;
                    apiCallResponse.errorMessage = "Missing parameter destinations for PM";
                    return new Tuple<Message, ApiCallResponse>(message, apiCallResponse);
                }
                string requestUrl = Common.baseUrl;
                if (channelId.ToLower() == "pm")
                {
                    requestUrl += "/stream/0/channels/pm/messages";
                }
                else
                {
                    requestUrl += "/stream/0/channels/" + channelId + "/messages";
                }

                messageCreateParameters messageContent = new messageCreateParameters();
                messageContent.text = text;
                messageContent.reply_to = reply_to;
                //messageContent.annotations = annotations;
                messageContent.entities = entities;
                messageContent.machine_only = machineOnly;
                messageContent.destinations = receipientUsersnameOrIds;

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

                string jsonString = JsonConvert.SerializeObject(messageContent, 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");

                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 #55
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 + "/stream/0/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);
 }