Beispiel #1
0
 // Forums
 /// <summary>
 /// Get forum scriptions.
 /// </summary>
 /// <param name="onlyShowUnread">Only show subscribed forums with unread threads. Optional.</param>
 /// <returns>JSON response deserialized into Subscriptions object.</returns>
 public Subscriptions GetSubscriptions(bool? onlyShowUnread)
 {
     var builder = new QueryBuilder("ajax.php?action=subscriptions");
     builder.Append("showunread", onlyShowUnread);
     var json = _http.RequestJson(this.RootWhatCDUri, builder.Query.ToString());
     return JsonConvert.DeserializeObject<Subscriptions>(json, JsonSettings);
 }
Beispiel #2
0
 /// <summary>
 /// Gets the top users.
 /// </summary>
 /// <param name="limit">Maximum result limit. Acceptable values: 10, 25, 100, and 250. Optional. Default is 25.</param>
 /// <returns>JSON response deserialized into Top10Users object.</returns>
 public Top10Users GetTop10Users(int? limit)
 {
     var builder = new QueryBuilder("ajax.php?action=top10&type=users");
     builder.Append("limit", limit);
     var json = _http.RequestJson(this.RootWhatCDUri, builder.Query.ToString());
     return JsonConvert.DeserializeObject<Top10Users>(json, JsonSettings);
 }
Beispiel #3
0
 /// <summary>
 /// Searches requests.
 /// If no arguments are specified then the most recent requests are shown.
 /// </summary>
 /// <param name="options">Object that inherits ISearchRequests.</param>
 /// <returns>JSON response deserialized into Requests object.</returns>
 public Requests GetRequests(ISearchRequests options)
 {
     var builder = new QueryBuilder("ajax.php?action=requests");
     builder.Append("tags_type", options.TagsType);
     builder.Append("show_filled", options.ShowFilled.ToString().ToLower());
     builder.Append("page", options.Page);
     builder.Append("tag", options.Tags);
     builder.Append("search", options.SearchTerm);
     var json = _http.RequestJson(this.RootWhatCDUri, builder.Query.ToString());
     return JsonConvert.DeserializeObject<Requests>(json, JsonSettings);
 }
Beispiel #4
0
 // Torrents
 // TODO: Method to get flac log (if it exists)
 /// <summary>
 /// Gets similar artists.
 /// Note: the return response from the server does not conform to the standard JSON response pattern.
 /// </summary>
 /// <param name="artistID">Artist ID. Mandatory.</param>
 /// <param name="limit">Maximum result limit. Mandatory.</param>
 /// <returns>JSON response deserialized into SimilarArtists object.</returns>
 public SimilarArtists GetSimilarArtists(int artistID, int limit)
 {
     var builder = new QueryBuilder("ajax.php?action=similar_artists");
     builder.Append("id", artistID);
     builder.Append("limit", limit);
     var json = _http.RequestJson(this.RootWhatCDUri, builder.Query.ToString());
     // Because similar artists results do not conform to the standard reply we have to be dodgy so it can be deserialised
     if (!string.IsNullOrWhiteSpace(json)) json = string.Format("{{\"artists\":{0}}}", json);
     return JsonConvert.DeserializeObject<SimilarArtists>(json, JsonSettings);
 }
Beispiel #5
0
 /// <summary>
 /// Searches for users.
 /// </summary>
 /// <param name="searchTerm">String to search for. Mandatory.</param>
 /// <param name="page">Results page number. Optional.</param>
 /// <returns>JSON response deserialized into UserSearch object.</returns>
 public UserSearch GetUserSearch(string searchTerm, int? page)
 {
     var builder = new QueryBuilder("ajax.php?action=usersearch");
     builder.Append("search", searchTerm);
     builder.Append("page", page);
     var json = _http.RequestJson(this.RootWhatCDUri, builder.Query.ToString());
     return JsonConvert.DeserializeObject<UserSearch>(json, JsonSettings);
 }
Beispiel #6
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="torrentID"></param>
 /// <returns></returns>
 public Uri GenerateTorrentDownloadUri(int torrentID)
 {
     var builder = new QueryBuilder("torrents.php?action=download");
     builder.Append("id", torrentID);
     builder.Append("authkey", this.AuthKey);
     builder.Append("torrent_pass", this.PassKey);
     return new Uri(this.RootWhatCDUri, builder.Query.ToString());
 }
Beispiel #7
0
 // Messages
 /// <summary>
 /// Searches the contents of messages from either inbox or sentbox.
 /// </summary>
 /// <param name="options">Object implementing the IInbox interface.</param>
 /// <returns>JSON response deserialized into Inbox object.</returns>
 public Inbox GetInbox(IInbox options)
 {
     var builder = new QueryBuilder("ajax.php?action=inbox");
     if (options.DisplayUnreadFirst) builder.Append("sort", "unread");
     builder.Append("type", options.MessageType);
     builder.Append("page", options.Page);
     builder.Append("search", options.SearchTerm);
     builder.Append("searchtype", options.SearchType);
     var json = _http.RequestJson(this.RootWhatCDUri, builder.Query.ToString());
     return JsonConvert.DeserializeObject<Inbox>(json, JsonSettings);
 }
Beispiel #8
0
 /// <summary>
 /// Gets a torrent group.
 /// </summary>
 /// <param name="groupID">Group ID. Mandatory.</param>
 /// <returns>JSON response deserialized into TorrentGroup object.</returns>
 public TorrentGroup GetTorrentGroup(int groupID)
 {
     var builder = new QueryBuilder("ajax.php?action=torrentgroup");
     builder.Append("id", groupID);
     var json = _http.RequestJson(this.RootWhatCDUri, builder.Query.ToString());
     return JsonConvert.DeserializeObject<TorrentGroup>(json, JsonSettings);
 }
Beispiel #9
0
 /// <summary>
 /// Gets a page of threads from a forum.
 /// </summary>
 /// <param name="forumID">Forum ID. Mandatory.</param>
 /// <param name="page">Page number. Optional.</param>
 /// <returns>JSON response deserialized into ForumViewForum object.</returns>
 public ForumViewForum GetForumViewForum(int forumID, int? page)
 {
     var builder = new QueryBuilder("ajax.php?action=forum&type=viewforum");
     builder.Append("forumid", forumID);
     builder.Append("page", page);
     var json = _http.RequestJson(this.RootWhatCDUri, builder.Query.ToString());
     return JsonConvert.DeserializeObject<ForumViewForum>(json, JsonSettings);
 }
Beispiel #10
0
 /// <summary>
 /// Gets a page of forum thread posts where a specific thread exists.
 /// </summary>
 /// <param name="postID">Post ID. Mandatory.</param>
 /// <returns>JSON response deserialized into ForumViewThread object.</returns>
 public ForumViewThread GetForumViewThread(int postID)
 {
     var builder = new QueryBuilder("ajax.php?action=forum&type=viewthread");
     builder.Append("postid", postID);
     var json = _http.RequestJson(this.RootWhatCDUri, builder.Query.ToString());
     return JsonConvert.DeserializeObject<ForumViewThread>(json, JsonSettings);
 }
Beispiel #11
0
 // Collages
 /// <summary>
 /// Gets information about a particular collage.
 /// </summary>
 /// <param name="collageID">Collage ID. Mandatory.</param>
 /// <returns>JSON response deserialized into Collage object</returns>
 public Collage GetCollage(int collageID)
 {
     var builder = new QueryBuilder("ajax.php?action=collage");
     builder.Append("id", collageID);
     var json = _http.RequestJson(this.RootWhatCDUri, builder.Query.ToString());
     return JsonConvert.DeserializeObject<Collage>(json, JsonSettings);
 }
Beispiel #12
0
        /// <summary>
        /// Searches torrents.
        /// </summary>
        /// <param name="options">Object that inherits from ISearchTorrents.</param>
        /// <returns>JSON response deserialized into Browse object.</returns>
        public Browse GetBrowse(ISearchTorrents options)
        {
            var builder = new QueryBuilder("ajax.php?action=browse");
            builder.Append("artistname", options.ArtistName);
            builder.Append("cataloguenumber", options.CatalogueNumber);
            builder.Append("encoding", options.Encoding);
            builder.Append("filelist", options.FileList);
            builder.Append("format", options.Format);
            builder.Append("freetorrent", options.FreeTorrent);
            builder.Append("group_results", options.GroupResults);
            builder.Append("groupname", options.GroupName);
            builder.Append("hascue", options.HasCue);
            builder.Append("haslog",options.HasLog);
            builder.Append("media", options.Media);
            builder.Append("order_by", options.OrderBy);
            builder.Append("order_way",options.OrderWay);
            builder.Append("page", options.Page);
            builder.Append("recordlabel", options.RecordLabel);
            builder.Append("releasetype", options.ReleaseType);
            builder.Append("remastercataloguenumber", options.RemasterCatalogueNumber);
            builder.Append("remasterrecordlabel", options.RemasterRecordLabel);
            builder.Append("remastertitle", options.RemasterTitle);
            builder.Append("remasteryear", options.RemasterYear);
            builder.Append("scene", options.Scene);
            builder.Append("searchterm", options.SearchTerm);
            builder.Append("taglist", options.TagList);
            builder.Append("tags_type", options.TagsType);
            builder.Append("vanityhouse", options.VanityHouse);
            builder.Append("year", options.Year);

            var json = _http.RequestJson(this.RootWhatCDUri, builder.Query.ToString());
            return JsonConvert.DeserializeObject<Browse>(json, JsonSettings);
        }
Beispiel #13
0
 /// <summary>
 /// Gets artist information.
 /// </summary>
 /// <param name="artistName">Artist Name. Mandatory.</param>
 /// <returns>JSON response deserialized into Artist object.</returns>
 public WhatCD.Model.ActionArtist.Artist GetArtist(string artistName)
 {
     var builder = new QueryBuilder("ajax.php?action=artist");
     builder.Append("artistname", artistName);
     var json = _http.RequestJson(this.RootWhatCDUri, builder.Query.ToString());
     return JsonConvert.DeserializeObject<WhatCD.Model.ActionArtist.Artist>(json, JsonSettings);
 }
Beispiel #14
0
 /// <summary>
 /// Gets information about a particular torrent.
 /// </summary>
 /// <param name="id">ID of torrent. Mandatory.</param>
 /// <returns>JSON response deserialized into ActionTorrent.Torrent object.</returns>
 public WhatCD.Model.ActionTorrent.Torrent GetTorrent(int id)
 {
     var builder = new QueryBuilder("ajax.php?action=torrent");
     builder.Append("id", id);
     return this.GetTorrent(builder);
 }
Beispiel #15
0
 /// <summary>
 /// Gets all messages from a conversation.
 /// </summary>
 /// <param name="conversationID">Conversation ID. Mandatory.</param>
 /// <returns>JSON response deserialized into InboxViewConv object.</returns>
 public InboxViewConv GetInboxViewConv(int conversationID)
 {
     var builder = new QueryBuilder("ajax.php?action=inbox&type=viewconv");
     builder.Append("id", conversationID);
     var json = _http.RequestJson(this.RootWhatCDUri, builder.Query.ToString());
     return JsonConvert.DeserializeObject<InboxViewConv>(json, JsonSettings);
 }
Beispiel #16
0
 /// <summary>
 /// Gets information about a particular torrent.
 /// </summary>
 /// <param name="hash">Hash of torrent. Mandatory.</param>
 /// <returns>JSON response deserialized into ActionTorrent.Torrent object.</returns>
 public WhatCD.Model.ActionTorrent.Torrent GetTorrent(string hash)
 {
     var builder = new QueryBuilder("ajax.php?action=torrent");
     builder.Append("hash", hash);
     return this.GetTorrent(builder);
 }
Beispiel #17
0
 /// <summary>
 /// Gets notifications.
 /// </summary>
 /// <param name="page">Notification page number. Optional.</param>
 /// <returns>JSON response deserialized into Notifications object.</returns>
 public WhatCD.Model.ActionNotifications.Notifications GetNotifications(int? page)
 {
     var builder = new QueryBuilder("ajax.php?action=notifications");
     builder.Append("page", page);
     var json = _http.RequestJson(this.RootWhatCDUri, builder.Query.ToString());
     return JsonConvert.DeserializeObject<WhatCD.Model.ActionNotifications.Notifications>(json, JsonSettings);
 }
Beispiel #18
0
 // Users
 /// <summary>
 /// Gets user information.
 /// </summary>
 /// <param name="userID">User ID. Mandatory.</param>
 /// <returns>JSON response deserialized into User object.</returns>
 public User GetUser(int userID)
 {
     var builder = new QueryBuilder("ajax.php?action=user");
     builder.Append("id", userID);
     var json = _http.RequestJson(this.RootWhatCDUri, builder.Query.ToString());
     return JsonConvert.DeserializeObject<User>(json, JsonSettings);
 }
Beispiel #19
0
 // Requests
 /// <summary>
 /// Gets information about a specific request.
 /// </summary>
 /// <param name="options">Object that inherits IGetRequest</param>
 /// <returns>JSON response deserialized into Request object</returns>
 public WhatCD.Model.ActionRequest.Request GetRequest(IGetRequest options)
 {
     var builder = new QueryBuilder("ajax.php?action=request");
     builder.Append("id", options.RequestID);
     builder.Append("page", options.Page);
     var json = _http.RequestJson(this.RootWhatCDUri, builder.Query.ToString());
     return JsonConvert.DeserializeObject<WhatCD.Model.ActionRequest.Request>(json, JsonSettings);
 }
Beispiel #20
0
 /// <summary>
 /// Gets information about a particular torrent.
 /// </summary>
 /// <param name="builder">QueryBuilder object with either a torrent hash or id argument.</param>
 /// <returns>JSON response deserialized into ActionTorrent.Torrent object.</returns>
 private WhatCD.Model.ActionTorrent.Torrent GetTorrent(QueryBuilder builder)
 {
     var json = _http.RequestJson(this.RootWhatCDUri, builder.Query.ToString());
     return JsonConvert.DeserializeObject<WhatCD.Model.ActionTorrent.Torrent>(json, JsonSettings);
 }
Beispiel #21
0
        /// <summary>
        /// Downloads the torrent file.
        /// </summary>
        /// <param name="torrentID">The ID of the torrent to download. Mandatory.</param>
        /// <returns>A byte array with the torrent file contents.</returns>
        public Torrent DownloadTorrent(int torrentID)
        {
            string contentDisposition;
            string contentType;
            var builder = new QueryBuilder("torrents.php?action=download");
            builder.Append("id", torrentID);
            var bytes = _http.RequestBytes(this.RootWhatCDUri, builder.Query.ToString(), out contentDisposition, out contentType);

            if (!string.Equals(contentType, "application/x-bittorrent; charset=utf-8", StringComparison.InvariantCultureIgnoreCase)) throw new Exception("Expected bittorrent content type was not found");
            if (!contentDisposition.StartsWith("attachment; filename=")) throw new Exception("Torrent filename was not found");

            return new Torrent(bytes, contentDisposition.Replace("attachment; filename=", "").Replace("\"", ""));
        }