public override async Task <APIResponse> UpdateAnimeInLibrary(UserLoginInfo userInfo, LibraryObject libraryObject, IProgress <APIProgressReport> progress)
        {
            if (!userInfo.IsUserLoggedIn)
            {
                if (progress != null)
                {
                    progress.Report(new APIProgressReport(100.0, "This user is not logged in", APIResponse.Failed));
                }
                return(APIResponse.Failed);
            }
            if (libraryObject == null)
            {
                if (progress != null)
                {
                    progress.Report(new APIProgressReport(100.0, "Please supply a valid LibraryObject", APIResponse.Failed));
                }
                return(APIResponse.Failed);
            }
            if (libraryObject.Anime == null)
            {
                if (progress != null)
                {
                    progress.Report(new APIProgressReport(100.0, "There is no valid AnimeObject attacked to the LibraryObject", APIResponse.Failed));
                }
                return(APIResponse.Failed);
            }

            string             compliantAnimeID = libraryObject.Anime.ID.ID.ConvertToAPIConpliantString(' ', '-');
            HttpRequestMessage requestMessage   = new HttpRequestMessage(HttpMethod.Post, Service.CreateAPIServiceUri("/libraries/" + compliantAnimeID));

            requestMessage.Headers.Add("accept", "application/json");
            requestMessage.Content = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("auth_token", userInfo.AuthToken),
                new KeyValuePair <string, string>("status", Converters.LibrarySectionConverter.LibrarySectionToString(libraryObject.Section)),
                new KeyValuePair <string, string>("privacy", Converters.PrivacySettingsConverter.PrivacySettingsToString(libraryObject.Private)), // Can be "public", "private"
                new KeyValuePair <string, string>("sane_rating_update", libraryObject.Rating.ToString()),                                         // none = None Selected, 0-2 = Unhappy, 3 = Neutral, 4-5 = Happy
                //new KeyValuePair<string,string>("rewatching", (false.ToString()).ToLower()),
                new KeyValuePair <string, string>("rewatched_times", libraryObject.RewatchedTimes.ToString()),
                new KeyValuePair <string, string>("notes", libraryObject.Notes),
                new KeyValuePair <string, string>("episodes_watched", libraryObject.EpisodesWatched.ToString()),
                new KeyValuePair <string, string>("increment_episodes", (false.ToString()).ToLower())
            });
            HttpResponseMessage response = await APIWebClient.MakeAPICall(requestMessage);

            if (response.IsSuccessStatusCode)
            {
                if (progress != null)
                {
                    progress.Report(new APIProgressReport(100.0, "Library Object Updated", APIResponse.Successful, APIResponse.Successful, APIResponse.Successful));
                }
                return(APIResponse.Successful);
            }

            if (progress != null)
            {
                progress.Report(new APIProgressReport(100.0, "API Call wasn't successul", APIResponse.Failed));
            }
            return(APIResponse.Failed);
        }
예제 #2
0
        public override async Task <List <UserInfo> > SearchUsers(string searchTerms, IProgress <APIProgressReport> progress)
        {
            if (string.IsNullOrWhiteSpace(searchTerms))
            {
                if (progress != null)
                {
                    progress.Report(new APIProgressReport(100.0, "Please enter a search", APIResponse.Failed));
                }
                return(new List <UserInfo>());
            }

            HttpRequestMessage  requestMessage = new HttpRequestMessage(HttpMethod.Get, "https://hummingbird.me/search.json?depth=full&scope=users&query=" + searchTerms);
            HttpResponseMessage response       = await APIWebClient.MakeAPICall(requestMessage);

            if (response.IsSuccessStatusCode)
            {
                string responseAsString = await response.Content.ReadAsStringAsync();

                if (progress != null)
                {
                    progress.Report(new APIProgressReport(50.0, "Recieved User From Server", APIResponse.ContinuingExecution));
                }

                JObject o = JObject.Parse(responseAsString);
                UserSearchHummingbird_UndocumentedV1 rawUserSearch = JsonConvert.DeserializeObject <UserSearchHummingbird_UndocumentedV1>(o.ToString());

                List <UserInfo> convertedSearchResult = new List <UserInfo>();
                foreach (var searchResult in rawUserSearch.search)
                {
                    if (searchResult.type != "user")
                    {
                        continue;
                    }
                    UserInfo user = new UserInfo();
                    user.AvatarUrl = new Uri(searchResult.image, UriKind.Absolute);
                    user.Username  = searchResult.title;
                    user.Biography = searchResult.desc;
                    convertedSearchResult.Add(user);
                }

                if (progress != null)
                {
                    progress.Report(new APIProgressReport(100.0, "Converted Successfully", APIResponse.Successful, convertedSearchResult, rawUserSearch));
                }
                return(convertedSearchResult);
            }

            if (progress != null)
            {
                progress.Report(new APIProgressReport(100.0, "API Call wasn't successul", APIResponse.Failed));
            }
            return(new List <UserInfo>());
        }
예제 #3
0
        public override async Task <List <CalendarEntry> > GetCalendar(string username, IProgress <APIProgressReport> progress)
        {
            if (string.IsNullOrWhiteSpace(username))
            {
                if (progress != null)
                {
                    progress.Report(new APIProgressReport(100.0, "Please enter a Username", APIResponse.Failed));
                }
                return(new List <CalendarEntry>());
            }

            HttpRequestMessage  requestMessage = new HttpRequestMessage(HttpMethod.Get, "http://cal.hb.cybrox.eu/api.php?user="******"Received Calendar Feed From Server", APIResponse.ContinuingExecution));
                }

                // Parse the Raw Entries
                JObject o = JObject.Parse(responseAsString);
                CalendarRootHummingbird_Undocumented rawCalendarInfo = JsonConvert.DeserializeObject <CalendarRootHummingbird_Undocumented>(o.ToString());;

                // Now convert them to the universal entries
                List <CalendarEntry> convertedCalendarEntryList = new List <CalendarEntry>();
                foreach (var entry in rawCalendarInfo.dataset)
                {
                    convertedCalendarEntryList.Add((CalendarEntry)entry);
                }

                if (progress != null)
                {
                    progress.Report(new APIProgressReport(100.0, "Converted Successfully", APIResponse.Successful, convertedCalendarEntryList, rawCalendarInfo));
                }
                return(convertedCalendarEntryList);
            }

            if (progress != null)
            {
                progress.Report(new APIProgressReport(100.0, "API Call wasn't successful", APIResponse.Failed));
            }
            return(new List <CalendarEntry>());
        }
        public override async Task <List <AnimeObject> > GetAnimeFavourites(string username, IProgress <APIProgressReport> progress)
        {
            if (string.IsNullOrWhiteSpace(username))
            {
                if (progress != null)
                {
                    progress.Report(new APIProgressReport(100.0, "Please enter a Username", APIResponse.Failed));
                }
                return(new List <AnimeObject>());
            }

            HttpRequestMessage  requestMessage = new HttpRequestMessage(HttpMethod.Get, Service.CreateAPIServiceUri("/users/" + username + "/favorite_anime"));
            HttpResponseMessage response       = await APIWebClient.MakeAPICall(requestMessage);

            if (response.IsSuccessStatusCode)
            {
                string responseAsString = await response.Content.ReadAsStringAsync();

                if (progress != null)
                {
                    progress.Report(new APIProgressReport(50.0, "Recieved LibraryObjects From Server", APIResponse.ContinuingExecution));
                }

                JObject o = JObject.Parse("{\"anime\":" + responseAsString + "}");
                AnimeObjectListHummingbirdV1 favouriteList = JsonConvert.DeserializeObject <AnimeObjectListHummingbirdV1>(o.ToString());


                List <AnimeObject> convertedFavouriteAnimeObjects = new List <AnimeObject>();
                foreach (var anime in favouriteList.anime)
                {
                    convertedFavouriteAnimeObjects.Add((AnimeObject)anime);
                }

                if (progress != null)
                {
                    progress.Report(new APIProgressReport(100.0, "Converted Successfully", APIResponse.Successful, convertedFavouriteAnimeObjects, favouriteList));
                }
                return(convertedFavouriteAnimeObjects);
            }

            if (progress != null)
            {
                progress.Report(new APIProgressReport(100.0, "API Call wasn't successul", APIResponse.Failed));
            }
            return(new List <AnimeObject>());
        }
        public override async Task <APIResponse> RemoveAnimeFromLibrary(UserLoginInfo userInfo, string animeID, IProgress <APIProgressReport> progress)
        {
            if (!userInfo.IsUserLoggedIn)
            {
                if (progress != null)
                {
                    progress.Report(new APIProgressReport(100.0, "This user is not logged in", APIResponse.Failed));
                }
                return(APIResponse.Failed);
            }
            if (string.IsNullOrWhiteSpace(animeID))
            {
                if (progress != null)
                {
                    progress.Report(new APIProgressReport(100.0, "Please enter an AnimeID", APIResponse.Failed));
                }
                return(APIResponse.Failed);
            }

            string compliantAnimeID = animeID.ConvertToAPIConpliantString(' ', '-');

            HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post, Service.CreateAPIServiceUri("/libraries/" + compliantAnimeID + "/remove"));

            requestMessage.Headers.Add("accept", "application/json");
            requestMessage.Content = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("auth_token", userInfo.AuthToken),      //Consts.settings.auth_token),
            });

            HttpResponseMessage response = await APIWebClient.MakeAPICall(requestMessage);

            if (response.IsSuccessStatusCode)
            {
                if (progress != null)
                {
                    progress.Report(new APIProgressReport(100.0, "Anime Removed", APIResponse.Successful, APIResponse.Successful, APIResponse.Successful));
                }
                return(APIResponse.Successful);
            }

            if (progress != null)
            {
                progress.Report(new APIProgressReport(100.0, "API Call wasn't successful", APIResponse.Failed));
            }
            return(APIResponse.Failed);
        }
        public override async Task <List <AnimeObject> > SearchAnime(string searchTerm, IProgress <APIProgressReport> progress)
        {
            if (string.IsNullOrWhiteSpace(searchTerm))
            {
                if (progress != null)
                {
                    progress.Report(new APIProgressReport(100.0, "Please enter Search Terms", APIResponse.Failed));
                }
                return(new List <AnimeObject>());
            }

            HttpRequestMessage  requestMessage = new HttpRequestMessage(HttpMethod.Get, Service.CreateAPIServiceUri("/search/anime?query=" + searchTerm));
            HttpResponseMessage response       = await APIWebClient.MakeAPICall(requestMessage);

            if (response.IsSuccessStatusCode)
            {
                string responseAsString = await response.Content.ReadAsStringAsync();

                if (progress != null)
                {
                    progress.Report(new APIProgressReport(50.0, "Recieved Search Results From Server", APIResponse.ContinuingExecution));
                }

                JObject o = JObject.Parse("{\"anime\":" + responseAsString + "}");
                AnimeObjectListHummingbirdV1 hummingbirdSearchResults = JsonConvert.DeserializeObject <AnimeObjectListHummingbirdV1>(o.ToString());

                List <AnimeObject> convertedSearchResults = new List <AnimeObject>();
                foreach (var anime in hummingbirdSearchResults.anime)
                {
                    convertedSearchResults.Add((AnimeObject)anime);
                }

                if (progress != null)
                {
                    progress.Report(new APIProgressReport(100.0, "Converted Successfully", APIResponse.Successful, convertedSearchResults, hummingbirdSearchResults));
                }
                return(convertedSearchResults);
            }

            if (progress != null)
            {
                progress.Report(new APIProgressReport(100.0, "API Call wasn't successul", APIResponse.Failed));
            }
            return(new List <AnimeObject>());
        }
        public override async Task <AnimeObject> GetAnime(string animeID, IProgress <APIProgressReport> progress)
        {
            if (string.IsNullOrWhiteSpace(animeID))
            {
                if (progress != null)
                {
                    progress.Report(new APIProgressReport(100.0, "Please enter an AnimeID", APIResponse.Failed));
                }
                return(new AnimeObject());
            }

            string compliantAnimeID = animeID.ConvertToAPIConpliantString(' ', '-');

            HttpRequestMessage  requestMessage = new HttpRequestMessage(HttpMethod.Get, Service.CreateAPIServiceUri("/anime/" + compliantAnimeID + "?title_language_preference=romanized"));
            HttpResponseMessage response       = await APIWebClient.MakeAPICall(requestMessage);

            if (response.IsSuccessStatusCode)
            {
                string responseAsString = await response.Content.ReadAsStringAsync();

                if (progress != null)
                {
                    progress.Report(new APIProgressReport(50.0, "Recieved Anime From Server", APIResponse.ContinuingExecution));
                }

                JObject o = JObject.Parse(responseAsString);
                AnimeObjectHummingbirdV1 animeObject = JsonConvert.DeserializeObject <AnimeObjectHummingbirdV1>(o.ToString());

                AnimeObject convertedAnimeObject = (AnimeObject)animeObject;

                if (progress != null)
                {
                    progress.Report(new APIProgressReport(100.0, "Converted Successfully", APIResponse.Successful, convertedAnimeObject, animeObject));
                }
                return(convertedAnimeObject);
            }

            if (progress != null)
            {
                progress.Report(new APIProgressReport(100.0, "API Call wasn't successul", APIResponse.Failed));
            }
            return(new AnimeObject());
        }
예제 #8
0
        public override async Task <UserInfo> GetUserInfo(string username, IProgress <APIProgressReport> progress)
        {
            if (string.IsNullOrWhiteSpace(username))
            {
                if (progress != null)
                {
                    progress.Report(new APIProgressReport(100.0, "Please enter a Username", APIResponse.Failed));
                }
                return(new UserInfo());
            }

            HttpRequestMessage  requestMessage = new HttpRequestMessage(HttpMethod.Get, CreateAPIServiceUri("/users/" + username));
            HttpResponseMessage response       = await APIWebClient.MakeAPICall(requestMessage);

            if (response.IsSuccessStatusCode)
            {
                string responseAsString = await response.Content.ReadAsStringAsync();

                if (progress != null)
                {
                    progress.Report(new APIProgressReport(50.0, "Recieved User From Server", APIResponse.ContinuingExecution));
                }

                JObject o = JObject.Parse(responseAsString);
                UserObjectHummingbirdV1 rawUserInfo = JsonConvert.DeserializeObject <UserObjectHummingbirdV1>(o.ToString());

                UserInfo convertedUserInfo = (UserInfo)rawUserInfo;

                if (progress != null)
                {
                    progress.Report(new APIProgressReport(100.0, "Converted Successfully", APIResponse.Successful, convertedUserInfo, rawUserInfo));
                }
                return(convertedUserInfo);
            }

            if (progress != null)
            {
                progress.Report(new APIProgressReport(100.0, "API Call wasn't successul", APIResponse.Failed));
            }
            return(new UserInfo());
        }
        public override async Task <ObservableCollection <AActivityFeedItem> > GetActivityFeed(string username, int paginationIndex, IProgress <APIProgressReport> progress)
        {
            if (string.IsNullOrWhiteSpace(username))
            {
                if (progress != null)
                {
                    progress.Report(new APIProgressReport(100.0, "Please enter a Username", APIResponse.Failed));
                }
                return(new ObservableCollection <AActivityFeedItem>());
            }

            HttpRequestMessage  requestMessage = new HttpRequestMessage(HttpMethod.Get, Service.CreateAPIServiceUri("/users/" + username + "/feed?page=" + paginationIndex));
            HttpResponseMessage response       = await APIWebClient.MakeAPICall(requestMessage);

            if (response.IsSuccessStatusCode)
            {
                string responseAsString = await response.Content.ReadAsStringAsync();

                if (progress != null)
                {
                    progress.Report(new APIProgressReport(50.0, "Recieved Activity Feed From Server", APIResponse.ContinuingExecution));
                }

                JObject o = JObject.Parse("{\"status_feed\":" + responseAsString + "}");
                StoryObjectListHummingbirdV1 activityFeedRaw = JsonConvert.DeserializeObject <StoryObjectListHummingbirdV1>(o.ToString());

                ObservableCollection <AActivityFeedItem> convertedActivityFeed = new ObservableCollection <AActivityFeedItem>();
                foreach (var aFO in activityFeedRaw.status_feed)
                {
                    string   tts = aFO.updated_at.Substring(0, aFO.updated_at.Length - 1);
                    string[] tS  = tts.Split('T');

                    UserInfo user = new UserInfo();
                    DateTime timestamp;
                    if (!DateTime.TryParse(tts, out timestamp))
                    {
                        timestamp = DateTime.MinValue;
                    }

                    if (aFO.story_type == "comment")
                    {
                        user.Username  = aFO.poster.name;
                        user.AvatarUrl = new Uri(aFO.poster.avatar, UriKind.Absolute);

                        convertedActivityFeed.Add(new ActivityFeedComment(user, aFO.substories[0].comment, timestamp));
                    }
                    else if (aFO.story_type == "media_story")
                    {
                        user.Username  = aFO.user.name;
                        user.AvatarUrl = new Uri(aFO.user.avatar, UriKind.Absolute);

                        string intelligibleString = "";
                        if (aFO.substories[0].substory_type == "watchlist_status_update")
                        {
                            LibrarySection librarySection = Converters.LibrarySectionConverter.StringToLibrarySection(aFO.substories[0].new_status);
                            intelligibleString = user.Username + " " + Converters.LibrarySectionConverter.LibrarySectionToIntelligableStatusString(librarySection);
                        }
                        else if (aFO.substories[0].substory_type == "watched_episode")
                        {
                            intelligibleString = user.Username + " watched episode " + aFO.substories[0].episode_number;
                        }

                        ServiceID mediaID           = new ServiceID(ServiceName.Hummingbird, MediaType.Anime, aFO.media.slug);
                        Uri       activityFeedImage = new Uri(aFO.media.cover_image, UriKind.Absolute);
                        convertedActivityFeed.Add(new ActivityFeedMediaUpdate(user, mediaID, activityFeedImage, aFO.media.title, intelligibleString, timestamp));
                    }
                }

                if (progress != null)
                {
                    progress.Report(new APIProgressReport(100.0, "Converted Successfully", APIResponse.Successful, convertedActivityFeed, activityFeedRaw));
                }
                return(convertedActivityFeed);
            }

            if (progress != null)
            {
                progress.Report(new APIProgressReport(100.0, "API Call wasn't successul", APIResponse.Failed));
            }
            return(new ObservableCollection <AActivityFeedItem>());
        }
        /// <summary>
        /// Doesn't Work
        /// </summary>
        /// <param name="senderUserLoginInfo">The Senders LoginInfo</param>
        /// <param name="senderUserInfo">The Senders UserInfo</param>
        /// <param name="receiverUserInfo">The Recievers UserInfo</param>
        /// <param name="message">The Message to post</param>
        /// <param name="progress">To report progress and completion</param>
        /// <returns></returns>
        public override async Task <AActivityFeedItem> PostStatusUpdate(UserLoginInfo senderUserLoginInfo, UserInfo senderUserInfo, UserInfo receiverUserInfo, string message, IProgress <APIProgressReport> progress)
        {
            #region Early Exits
            if (!senderUserLoginInfo.IsUserLoggedIn)
            {
                if (progress != null)
                {
                    progress.Report(new APIProgressReport(100.0, "You must be logged in to use this feature", APIResponse.Failed));
                }
                return(null);
            }

            if (senderUserInfo != null)
            {
                if (string.IsNullOrWhiteSpace(senderUserInfo.Username))
                {
                    if (progress != null)
                    {
                        progress.Report(new APIProgressReport(100.0, "Sender UserInfo has no Username", APIResponse.Failed));
                    }
                    return(null);
                }
            }
            else
            {
                if (progress != null)
                {
                    progress.Report(new APIProgressReport(100.0, "Sender UserInfo is Null", APIResponse.Failed));
                }
                return(null);
            }

            if (receiverUserInfo != null)
            {
                if (string.IsNullOrWhiteSpace(receiverUserInfo.Username))
                {
                    if (progress != null)
                    {
                        progress.Report(new APIProgressReport(100.0, "Receiver UserInfo has no Username", APIResponse.Failed));
                    }
                    return(null);
                }
            }
            else
            {
                if (progress != null)
                {
                    progress.Report(new APIProgressReport(100.0, "Receiver UserInfo is Null", APIResponse.Failed));
                }
                return(null);
            }

            if (string.IsNullOrWhiteSpace(message))
            {
                if (progress != null)
                {
                    progress.Report(new APIProgressReport(100.0, "Please enter a status message", APIResponse.Failed));
                }
                return(null);
            }
            #endregion

            // Post
            // https://hummingbird.me/stories
            // Content
            //

            HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post, "http://hummingbird.me/users/" + receiverUserInfo.Username + "/comment.json");
            requestMessage.Headers.Add("accept", "application/json");
            requestMessage.Content = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("auth_token", senderUserLoginInfo.AuthToken),
                new KeyValuePair <string, string>("comment", message),
            });
            HttpResponseMessage response = await APIWebClient.MakeAPICall(requestMessage);

            if (response.IsSuccessStatusCode)
            {
                string responseAsString = await response.Content.ReadAsStringAsync();

                ActivityFeedComment comment = new ActivityFeedComment(senderUserInfo, message, DateTime.UtcNow);
                if (progress != null)
                {
                    progress.Report(new APIProgressReport(100.0, "Converted Successfully", APIResponse.Successful, comment, comment));
                }
                return(comment);
            }

            if (progress != null)
            {
                progress.Report(new APIProgressReport(100.0, "API Call wasn't successul", APIResponse.Failed));
            }
            return(null);
        }
예제 #11
0
        public override async Task <UserLoginInfo> Login(string username, string password, IProgress <APIProgressReport> progress, string otherAuth = "")
        {
            if (string.IsNullOrWhiteSpace(username) ||
                string.IsNullOrWhiteSpace(password))
            {
                if (progress != null)
                {
                    progress.Report(new APIProgressReport(100.0, "Please type in your username/password", APIResponse.InfoNotEntered));
                }
                return(new UserLoginInfo());
            }
            if (username.Contains("@"))
            {
                if (progress != null)
                {
                    progress.Report(new APIProgressReport(100.0, "Logging in through Email is not supported yet. Please use your Username", APIResponse.NotSupported));
                }
                return(new UserLoginInfo());
            }

            if (progress != null)
            {
                progress.Report(new APIProgressReport(10.0, "Username/Password Okay", APIResponse.ContinuingExecution));
            }

            // Create the Request Message
            HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post, CreateAPIServiceUri("/users/authenticate/"));

            requestMessage.Headers.Add("accept", "application/json");
            requestMessage.Content = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("username", username),
                new KeyValuePair <string, string>("password", password)
            });

            // Make the API Call
            HttpResponseMessage response = await APIWebClient.MakeAPICall(requestMessage);

            if (response.IsSuccessStatusCode)
            {
                if (progress != null)
                {
                    progress.Report(new APIProgressReport(50.0, "Login Authorized", APIResponse.ContinuingExecution));
                }

                string responseAsString = await response.Content.ReadAsStringAsync();

                //Parse the responseAsString to remove ""'s
                string userAuthToken = "";
                char[] txtarr        = responseAsString.ToCharArray();
                foreach (char c in txtarr)
                {
                    switch (c)
                    {
                    case '"':
                        break;

                    default:
                        userAuthToken += c;
                        break;
                    }
                }

                UserLoginInfo userLoginInfo = new UserLoginInfo(username, password, userAuthToken, LoginMethod.Username);
                if (progress != null)
                {
                    progress.Report(new APIProgressReport(100.0, "Successfully Logged In", APIResponse.Successful, userLoginInfo, userLoginInfo));
                }

                return(userLoginInfo);
            }

            if (await response.Content.ReadAsStringAsync() == "{\"error\":\"Invalid credentials\"}")
            {
                if (progress != null)
                {
                    progress.Report(new APIProgressReport(100.0, "Invalid Login Credidentials", APIResponse.InvalidCredentials));
                }
            }
            else
            {
                if (progress != null)
                {
                    progress.Report(new APIProgressReport(100.0, "Error connecting to hummingbird.me. Try again later", APIResponse.InvalidCredentials));
                }
            }

            return(new UserLoginInfo());
        }