├── .nuget
├── NuGet.exe
├── NuGet.Config
└── NuGet.targets
├── Assets
├── pocketsharp.png
├── github-header.png
└── authentication-screen.png
├── PocketSharp.Examples
└── PocketSharp.UWP
│ ├── FodyWeavers.xml
│ ├── Assets
│ ├── StoreLogo.png
│ ├── SplashScreen.scale-200.png
│ ├── LockScreenLogo.scale-200.png
│ ├── Square44x44Logo.scale-200.png
│ ├── Wide310x150Logo.scale-200.png
│ ├── Square150x150Logo.scale-200.png
│ └── Square44x44Logo.targetsize-24_altform-unplated.png
│ ├── App.xaml
│ ├── project.json
│ ├── Properties
│ ├── AssemblyInfo.cs
│ └── Default.rd.xml
│ ├── MainPage.xaml.cs
│ ├── MainPage.xaml
│ ├── Package.appxmanifest
│ ├── PocketSharp.UWP.nuget.targets
│ ├── App.xaml.cs
│ ├── PocketSharp.UWP.nuget.props
│ └── PocketSharp.UWP.csproj
├── PocketSharp
├── Utilities
│ ├── PocketAuthException.cs
│ ├── PocketLimitException.cs
│ ├── PocketRequestException.cs
│ ├── HtmlNodeExtensions.cs
│ ├── Utilities.cs
│ ├── PocketException.cs
│ └── JsonExtensions.cs
├── Models
│ ├── PocketBoolean.cs
│ ├── PocketVideoType.cs
│ ├── Response
│ │ ├── Guid.cs
│ │ ├── Add.cs
│ │ ├── Modify.cs
│ │ ├── Topics.cs
│ │ ├── ResponseBase.cs
│ │ ├── RequestCode.cs
│ │ ├── Retrieve.cs
│ │ └── GetUser.cs
│ ├── Parameters
│ │ ├── ModifyParameters.cs
│ │ ├── AddParameters.cs
│ │ ├── Parameters.cs
│ │ └── RetrieveParameters.cs
│ ├── PocketTag.cs
│ ├── PocketAuthor.cs
│ ├── PocketTopic.cs
│ ├── PocketStatistics.cs
│ ├── PocketImage.cs
│ ├── PocketVideo.cs
│ ├── PocketUser.cs
│ ├── PocketLimits.cs
│ ├── PocketAction.cs
│ ├── PocketArticle.cs
│ ├── PocketExploreItem.cs
│ └── PocketItem.cs
├── PocketSharp.nuspec
├── PocketSharp.csproj
├── Components
│ ├── Trending.cs
│ ├── Add.cs
│ ├── Statistics.cs
│ ├── Explore.cs
│ ├── Account.cs
│ ├── Modify.cs
│ ├── ModifyTags.cs
│ └── Get.cs
└── PocketClient.cs
├── .editorconfig
├── PocketSharp.Tests
├── app.config
├── ExploreTests.cs
├── TrendingTests.cs
├── AccountTests.cs
├── TestsBase.cs
├── PocketSharp.Tests.csproj
├── MiscTests.cs
├── ModifyTagsTests.cs
├── AddTests.cs
├── StressTests.cs
├── ModifyTests.cs
└── GetTests.cs
├── .gitattributes
├── LICENSE-MIT
├── README.md
├── .gitignore
├── CHANGELOG.md
└── PocketSharp.sln
/.nuget/NuGet.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ceee/PocketSharp/HEAD/.nuget/NuGet.exe
--------------------------------------------------------------------------------
/Assets/pocketsharp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ceee/PocketSharp/HEAD/Assets/pocketsharp.png
--------------------------------------------------------------------------------
/Assets/github-header.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ceee/PocketSharp/HEAD/Assets/github-header.png
--------------------------------------------------------------------------------
/Assets/authentication-screen.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ceee/PocketSharp/HEAD/Assets/authentication-screen.png
--------------------------------------------------------------------------------
/PocketSharp.Examples/PocketSharp.UWP/FodyWeavers.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/PocketSharp/Utilities/PocketAuthException.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace PocketSharp
3 | {
4 | public class PocketAuthException : PocketException
5 | {
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/PocketSharp/Utilities/PocketLimitException.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace PocketSharp
3 | {
4 | public class PocketLimitException : PocketException
5 | {
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/PocketSharp.Examples/PocketSharp.UWP/Assets/StoreLogo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ceee/PocketSharp/HEAD/PocketSharp.Examples/PocketSharp.UWP/Assets/StoreLogo.png
--------------------------------------------------------------------------------
/PocketSharp/Utilities/PocketRequestException.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace PocketSharp
3 | {
4 | public class PocketRequestException : PocketException
5 | {
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/PocketSharp.Examples/PocketSharp.UWP/Assets/SplashScreen.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ceee/PocketSharp/HEAD/PocketSharp.Examples/PocketSharp.UWP/Assets/SplashScreen.scale-200.png
--------------------------------------------------------------------------------
/PocketSharp/Models/PocketBoolean.cs:
--------------------------------------------------------------------------------
1 | namespace PocketSharp.Models
2 | {
3 | internal enum PocketBoolean
4 | {
5 | No = 0,
6 | Yes = 1,
7 | IsType = 2
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/PocketSharp.Examples/PocketSharp.UWP/Assets/LockScreenLogo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ceee/PocketSharp/HEAD/PocketSharp.Examples/PocketSharp.UWP/Assets/LockScreenLogo.scale-200.png
--------------------------------------------------------------------------------
/PocketSharp.Examples/PocketSharp.UWP/Assets/Square44x44Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ceee/PocketSharp/HEAD/PocketSharp.Examples/PocketSharp.UWP/Assets/Square44x44Logo.scale-200.png
--------------------------------------------------------------------------------
/PocketSharp.Examples/PocketSharp.UWP/Assets/Wide310x150Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ceee/PocketSharp/HEAD/PocketSharp.Examples/PocketSharp.UWP/Assets/Wide310x150Logo.scale-200.png
--------------------------------------------------------------------------------
/.nuget/NuGet.Config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/PocketSharp.Examples/PocketSharp.UWP/Assets/Square150x150Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ceee/PocketSharp/HEAD/PocketSharp.Examples/PocketSharp.UWP/Assets/Square150x150Logo.scale-200.png
--------------------------------------------------------------------------------
/PocketSharp.Examples/PocketSharp.UWP/Assets/Square44x44Logo.targetsize-24_altform-unplated.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ceee/PocketSharp/HEAD/PocketSharp.Examples/PocketSharp.UWP/Assets/Square44x44Logo.targetsize-24_altform-unplated.png
--------------------------------------------------------------------------------
/PocketSharp/Models/PocketVideoType.cs:
--------------------------------------------------------------------------------
1 | namespace PocketSharp.Models
2 | {
3 | public enum PocketVideoType
4 | {
5 | Unknown = 7,
6 | YouTube = 1,
7 | Vimeo = 2,
8 | HTML = 5,
9 | Flash = 6
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/PocketSharp.Examples/PocketSharp.UWP/App.xaml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | ; This file is for unifying the coding style for different editors and IDEs
2 | ; editorconfig.org
3 |
4 | root = true
5 |
6 | [*]
7 | end_of_line = crlf
8 | charset = utf-8
9 | trim_trailing_whitespace = true
10 | insert_final_newline = true
11 | indent_style = space
12 | indent_size = 2
13 |
14 | [*.md]
15 | trim_trailing_whitespace = false
16 |
--------------------------------------------------------------------------------
/PocketSharp/Models/Response/Guid.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 |
3 | namespace PocketSharp.Models
4 | {
5 | ///
6 | /// Guid
7 | ///
8 | [JsonObject]
9 | internal class GuidResponse
10 | {
11 | ///
12 | /// Gets or sets the GUID.
13 | ///
14 | ///
15 | /// The GUID.
16 | ///
17 | [JsonProperty]
18 | public string Guid { get; set; }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/PocketSharp/Models/Response/Add.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 |
3 | namespace PocketSharp.Models
4 | {
5 | ///
6 | /// Add Response
7 | ///
8 | [JsonObject]
9 | internal class Add : ResponseBase
10 | {
11 | ///
12 | /// Gets or sets the item.
13 | ///
14 | ///
15 | /// The item.
16 | ///
17 | [JsonProperty]
18 | public PocketItem Item { get; set; }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/PocketSharp.Examples/PocketSharp.UWP/project.json:
--------------------------------------------------------------------------------
1 | {
2 | "dependencies": {
3 | "Microsoft.NETCore.UniversalWindowsPlatform": "6.0.8",
4 | "Newtonsoft.Json": "11.0.2",
5 | "PropertyChanged.Fody": "2.4.0"
6 | },
7 | "frameworks": {
8 | "uap10.0.15063": {}
9 | },
10 | "runtimes": {
11 | "win10-arm": {},
12 | "win10-arm-aot": {},
13 | "win10-x86": {},
14 | "win10-x86-aot": {},
15 | "win10-x64": {},
16 | "win10-x64-aot": {}
17 | }
18 | }
--------------------------------------------------------------------------------
/PocketSharp.Tests/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/PocketSharp/Models/Response/Modify.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 |
3 | namespace PocketSharp.Models
4 | {
5 | ///
6 | /// Modify Response
7 | ///
8 | [JsonObject]
9 | internal class Modify : ResponseBase
10 | {
11 | ///
12 | /// Gets or sets the action results.
13 | ///
14 | ///
15 | /// The action results.
16 | ///
17 | //[JsonProperty("action_results")]
18 | //public bool[] ActionResults { get; set; }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/PocketSharp/Models/Response/Topics.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using System;
3 | using System.Collections.Generic;
4 |
5 | namespace PocketSharp.Models
6 | {
7 | ///
8 | /// Topics Response
9 | ///
10 | [JsonObject]
11 | internal class TopicsResponse : ResponseBase
12 | {
13 | ///
14 | /// Gets the topics.
15 | ///
16 | ///
17 | /// The topics.
18 | ///
19 | [JsonProperty("topics")]
20 | public IEnumerable Items { get; set; }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/PocketSharp.Tests/ExploreTests.cs:
--------------------------------------------------------------------------------
1 | using PocketSharp.Models;
2 | using System.Collections.Generic;
3 | using System.Threading.Tasks;
4 | using Xunit;
5 | using System.Linq;
6 |
7 | namespace PocketSharp.Tests
8 | {
9 | public class ExploreTests : TestsBase
10 | {
11 | public ExploreTests() : base()
12 | {
13 |
14 | }
15 |
16 |
17 | //[Fact]
18 | //public async Task CheckPreRequestAction()
19 | //{
20 | // var results = await client.Explore(".net");
21 |
22 | // Assert.NotEmpty(results);
23 | //}
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/PocketSharp/Models/Response/ResponseBase.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 |
3 | namespace PocketSharp.Models
4 | {
5 | ///
6 | /// Base for Responses
7 | ///
8 | [JsonObject]
9 | internal class ResponseBase
10 | {
11 | ///
12 | /// Gets or sets a value indicating whether this is status.
13 | ///
14 | ///
15 | /// true if status is OK; otherwise, false.
16 | ///
17 | [JsonProperty("status")]
18 | public bool Status { get; set; }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text
3 |
4 | # Don't check these into the repo as LF to work around TeamCity bug
5 | *.xml -text
6 | *.targets -text
7 |
8 | # Custom for Visual Studio
9 | *.cs diff=csharp
10 | *.sln merge=union
11 | *.csproj merge=union
12 | *.vbproj merge=union
13 | *.fsproj merge=union
14 | *.dbproj merge=union
15 |
16 | # Denote all files that are truly binary and should not be modified.
17 | *.dll binary
18 | *.exe binary
19 | *.png binary
20 | *.ico binary
21 | *.snk binary
22 | *.pdb binary
23 | *.svg binary
24 |
--------------------------------------------------------------------------------
/PocketSharp/Models/Parameters/ModifyParameters.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Runtime.Serialization;
3 |
4 | namespace PocketSharp.Models
5 | {
6 | ///
7 | /// All parameters which can be passed to modify an item
8 | ///
9 | [DataContract]
10 | internal class ModifyParameters : Parameters
11 | {
12 | ///
13 | /// Gets or sets the actions.
14 | ///
15 | ///
16 | /// The actions.
17 | ///
18 | [DataMember(Name = "actions")]
19 | public IEnumerable> Actions { get; set; }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/PocketSharp.Tests/TrendingTests.cs:
--------------------------------------------------------------------------------
1 | using PocketSharp.Models;
2 | using System.Collections.Generic;
3 | using System.Threading.Tasks;
4 | using Xunit;
5 |
6 | namespace PocketSharp.Tests
7 | {
8 | public class TrendingTests : TestsBase
9 | {
10 | [Fact]
11 | public async Task AreTrendingArticlesReturned()
12 | {
13 | var articles = await client.GetTrendingArticles();
14 | Assert.NotEmpty(articles);
15 | }
16 |
17 |
18 | [Fact]
19 | public async Task AreTrendingTopicsReturned()
20 | {
21 | var topics = await client.GetTrendingTopics();
22 | Assert.NotEmpty(topics);
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/PocketSharp/Models/PocketTag.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 |
3 | namespace PocketSharp.Models
4 | {
5 | ///
6 | /// Tag
7 | ///
8 | [JsonObject]
9 | public class PocketTag
10 | {
11 | ///
12 | /// Gets or sets the name.
13 | ///
14 | ///
15 | /// The name.
16 | ///
17 | [JsonProperty("tag")]
18 | public string Name { get; set; }
19 |
20 | ///
21 | /// Gets or sets the item iD.
22 | ///
23 | ///
24 | /// The name.
25 | ///
26 | [JsonProperty("item_id")]
27 | public string ItemID { get; set; }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/PocketSharp/Models/Response/RequestCode.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 |
3 | namespace PocketSharp.Models
4 | {
5 | ///
6 | /// Request Code
7 | ///
8 | [JsonObject]
9 | internal class RequestCode
10 | {
11 | ///
12 | /// Gets or sets the code.
13 | ///
14 | ///
15 | /// The code.
16 | ///
17 | [JsonProperty]
18 | public string Code { get; set; }
19 |
20 | ///
21 | /// Gets or sets the state.
22 | ///
23 | ///
24 | /// The state.
25 | ///
26 | [JsonProperty]
27 | public string State { get; set; }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/PocketSharp/Utilities/HtmlNodeExtensions.cs:
--------------------------------------------------------------------------------
1 | //using HtmlAgilityPack;
2 | //using System;
3 | //using System.Collections.Generic;
4 | //using System.Linq;
5 | //using System.Text;
6 |
7 | //namespace PocketSharp
8 | //{
9 | // internal static class HtmlNodeExtensions
10 | // {
11 | // public static IEnumerable SelectNodesByClass(this HtmlNode node, string className)
12 | // {
13 | // return node.Descendants().Where(x => x.HasClass(className));
14 | // }
15 |
16 |
17 | // public static HtmlNode SelectNodeByClass(this HtmlNode node, string className)
18 | // {
19 | // return node.Descendants().FirstOrDefault(x => x.HasClass(className));
20 | // }
21 | // }
22 | //}
23 |
--------------------------------------------------------------------------------
/PocketSharp/Utilities/Utilities.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace PocketSharp
5 | {
6 | ///
7 | /// General utilities
8 | ///
9 | internal class Utilities
10 | {
11 | ///
12 | /// converts DateTime to an UNIX timestamp
13 | ///
14 | /// The date.
15 | ///
16 | /// UNIX timestamp
17 | ///
18 | public static int? GetUnixTimestamp(DateTime? dateTime)
19 | {
20 | if (dateTime == null)
21 | {
22 | return null;
23 | }
24 |
25 | return (int)((DateTime)dateTime - new DateTime(1970, 1, 1)).TotalSeconds;
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/PocketSharp/PocketSharp.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $id$
5 | $version$
6 | $title$
7 | $author$
8 | $author$
9 | MIT
10 | https://github.com/ceee/PocketSharp
11 | https://raw.github.com/ceee/PocketSharp/master/Assets/pocketsharp.png
12 | false
13 | $description$
14 | en-US
15 | $releaseNotes$
16 | $copyright$
17 | $tags$
18 |
19 |
20 |
--------------------------------------------------------------------------------
/PocketSharp.Tests/AccountTests.cs:
--------------------------------------------------------------------------------
1 | using PocketSharp.Models;
2 | using System;
3 | using System.Threading.Tasks;
4 | using Xunit;
5 |
6 | namespace PocketSharp.Tests
7 | {
8 | public class AccountTests : TestsBase
9 | {
10 | public AccountTests() : base() { }
11 |
12 |
13 | [Fact]
14 | public async Task IsAuthenticationSuccessful()
15 | {
16 | string requestCode = await client.GetRequestCode();
17 |
18 | PocketUser user = await client.GetUser(requestCode);
19 | }
20 |
21 | [Fact]
22 | public async Task IsRegistrationURLSuccessfullyCreated()
23 | {
24 | string requestCode = await client.GetRequestCode();
25 |
26 | Uri uri = client.GenerateRegistrationUri(requestCode);
27 |
28 | Assert.Contains(requestCode, uri.OriginalString);
29 | Assert.Contains("force=signup", uri.OriginalString);
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/PocketSharp/Models/PocketAuthor.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using System;
3 |
4 | namespace PocketSharp.Models
5 | {
6 | ///
7 | /// Author
8 | ///
9 | [JsonObject]
10 | public class PocketAuthor
11 | {
12 | ///
13 | /// Gets or sets the ID.
14 | ///
15 | ///
16 | /// The ID.
17 | ///
18 | [JsonProperty("author_id")]
19 | public string ID { get; set; }
20 |
21 | ///
22 | /// Gets or sets the name.
23 | ///
24 | ///
25 | /// The name.
26 | ///
27 | [JsonProperty]
28 | public string Name { get; set; }
29 |
30 | ///
31 | /// Gets or sets the URI.
32 | ///
33 | ///
34 | /// The URI.
35 | ///
36 | [JsonProperty("url")]
37 | public Uri Uri { get; set; }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/PocketSharp/Models/PocketTopic.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using System;
3 |
4 | namespace PocketSharp.Models
5 | {
6 | ///
7 | /// Topic
8 | ///
9 | [JsonObject]
10 | public class PocketTopic
11 | {
12 | ///
13 | /// Gets or sets the category.
14 | ///
15 | ///
16 | /// The topic category.
17 | ///
18 | [JsonProperty("category")]
19 | public string Category { get; set; }
20 |
21 | ///
22 | /// Gets or sets the name.
23 | ///
24 | ///
25 | /// The name of the topic.
26 | ///
27 | [JsonProperty("name")]
28 | public string Name { get; set; }
29 |
30 | ///
31 | /// Gets or sets the URI.
32 | ///
33 | ///
34 | /// Link to the topic listing on Pocket.
35 | ///
36 | [JsonProperty("url")]
37 | public Uri Uri { get; set; }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/PocketSharp/Models/PocketStatistics.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 |
3 | namespace PocketSharp.Models
4 | {
5 | ///
6 | /// Statistics
7 | ///
8 | [JsonObject]
9 | public class PocketStatistics
10 | {
11 | ///
12 | /// Gets or sets all items.
13 | ///
14 | ///
15 | /// All items count.
16 | ///
17 | [JsonProperty("count_list")]
18 | public int CountAll { get; set; }
19 |
20 | ///
21 | /// Gets or sets all read items.
22 | ///
23 | ///
24 | /// Read items count.
25 | ///
26 | [JsonProperty("count_read")]
27 | public int CountRead { get; set; }
28 |
29 | ///
30 | /// Gets or sets all unread items.
31 | ///
32 | ///
33 | /// Unread items count.
34 | ///
35 | [JsonProperty("count_unread")]
36 | public int CountUnread { get; set; }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/PocketSharp/PocketSharp.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0
5 | 5.0.0
6 | Tobias Klika
7 | brothers
8 | https://github.com/ceee/PocketSharp
9 | Copyright by brothers, 2019
10 | PocketAPI Pocket API PocketSharp Tobias Klika cee Scott Lovegrove scottisafool NReadability SgmlReader Reader Article SDK Pockem
11 | PocketSharp is a .NET Standard library that integrates the Pocket API v3.
12 |
15 | true
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/PocketSharp/Models/Response/Retrieve.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using System;
3 | using System.Collections.Generic;
4 |
5 | namespace PocketSharp.Models
6 | {
7 | ///
8 | /// Item Response
9 | ///
10 | [JsonObject]
11 | internal class Retrieve : ResponseBase
12 | {
13 | ///
14 | /// Gets or sets the complete.
15 | ///
16 | ///
17 | /// The complete.
18 | ///
19 | [JsonProperty("complete")]
20 | public int Complete { get; set; }
21 |
22 | ///
23 | /// Gets or sets the since.
24 | ///
25 | ///
26 | /// The since.
27 | ///
28 | [JsonProperty("since")]
29 | public DateTime Since { get; set; }
30 |
31 | ///
32 | /// Gets the items.
33 | ///
34 | ///
35 | /// The items.
36 | ///
37 | [JsonProperty("list")]
38 | [JsonConverter(typeof(ObjectToArrayConverter))]
39 | public IEnumerable Items { get; set; }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/LICENSE-MIT:
--------------------------------------------------------------------------------
1 | Copyright (c) 2015 cee, Tobias Klika
2 |
3 | Permission is hereby granted, free of charge, to any person
4 | obtaining a copy of this software and associated documentation
5 | files (the "Software"), to deal in the Software without
6 | restriction, including without limitation the rights to use,
7 | copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the
9 | Software is furnished to do so, subject to the following
10 | conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 | OTHER DEALINGS IN THE SOFTWARE.
23 |
--------------------------------------------------------------------------------
/PocketSharp.Examples/PocketSharp.UWP/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("PocketSharp.UWP")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("PocketSharp.UWP")]
13 | [assembly: AssemblyCopyright("Copyright © 2015")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Version information for an assembly consists of the following four values:
18 | //
19 | // Major Version
20 | // Minor Version
21 | // Build Number
22 | // Revision
23 | //
24 | // You can specify all the values or you can default the Build and Revision Numbers
25 | // by using the '*' as shown below:
26 | // [assembly: AssemblyVersion("1.0.*")]
27 | [assembly: AssemblyVersion("1.0.0.0")]
28 | [assembly: AssemblyFileVersion("1.0.0.0")]
29 | [assembly: ComVisible(false)]
--------------------------------------------------------------------------------
/PocketSharp/Models/Response/GetUser.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 |
3 | namespace PocketSharp.Models
4 | {
5 | ///
6 | /// Response from the GetUser() method
7 | ///
8 | [JsonObject]
9 | internal class GetUserResponse
10 | {
11 | public string Access_token { get; set; }
12 |
13 | public string Username { get; set; }
14 |
15 | public GetUserAccountResponse Account { get; set; }
16 | }
17 |
18 |
19 | [JsonObject]
20 | internal class GetUserAccountResponse
21 | {
22 | public string Email { get; set; }
23 |
24 | public string First_name { get; set; }
25 |
26 | public string Last_name { get; set; }
27 |
28 | public string User_id { get; set; }
29 |
30 | //public bool Premium_on_trial { get; set; }
31 |
32 | //public bool Premium_status { get; set; }
33 |
34 | public GetUserAccountProfileResponse Profile { get; set; }
35 | }
36 |
37 |
38 | [JsonObject]
39 | internal class GetUserAccountProfileResponse
40 | {
41 | public string Avatar_url { get; set; }
42 |
43 | public int Follow_count { get; set; }
44 |
45 | public int Follower_count { get; set; }
46 |
47 | public string Description { get; set; }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/PocketSharp/Models/Parameters/AddParameters.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.Serialization;
3 |
4 | namespace PocketSharp.Models
5 | {
6 | ///
7 | /// All parameters which can be passed to add a new item
8 | ///
9 | [DataContract]
10 | internal class AddParameters : Parameters
11 | {
12 | ///
13 | /// Gets or sets the URI.
14 | ///
15 | ///
16 | /// The URI.
17 | ///
18 | [DataMember(Name="url")]
19 | public Uri Uri { get; set; }
20 |
21 | ///
22 | /// Gets or sets the title.
23 | ///
24 | ///
25 | /// The title.
26 | ///
27 | [DataMember(Name="title")]
28 | public string Title { get; set; }
29 |
30 | ///
31 | /// Gets or sets the tags.
32 | ///
33 | ///
34 | /// The tags.
35 | ///
36 | [DataMember(Name="tags")]
37 | public string[] Tags { get; set; }
38 |
39 | ///
40 | /// Gets or sets the tweet ID.
41 | ///
42 | ///
43 | /// The tweet ID.
44 | ///
45 | [DataMember(Name="tweet_id")]
46 | public string TweetID { get; set; }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/PocketSharp.Tests/TestsBase.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Threading.Tasks;
4 | using Xunit;
5 |
6 | namespace PocketSharp.Tests
7 | {
8 | public class TestsBase : IDisposable
9 | {
10 | protected PocketClient client;
11 |
12 | protected List itemsToDelete = new List();
13 |
14 |
15 | // setup
16 | public TestsBase()
17 | {
18 | // !! please don't misuse this account !!
19 | client = new PocketClient(
20 | consumerKey: "15396-f6f92101d72c8e270a6c9bb3",
21 | callbackUri: "http://frontendplay.com",
22 | accessCode: "80acf6c5-c198-03c0-b94c-e74402"
23 | );
24 | }
25 |
26 |
27 | // teardown
28 | public void Dispose()
29 | {
30 | itemsToDelete.ForEach(async id =>
31 | {
32 | await client.Delete(id);
33 | });
34 | }
35 |
36 |
37 | // async throws
38 | public static async Task ThrowsAsync(Func func)
39 | {
40 | var expected = typeof(TException);
41 | Type actual = null;
42 | try
43 | {
44 | await func();
45 | }
46 | catch (Exception e)
47 | {
48 | actual = e.GetType();
49 | }
50 | Assert.Equal(expected, actual);
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/PocketSharp.Tests/PocketSharp.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.0
5 |
6 | false
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | PreserveNewest
17 |
18 |
19 | PreserveNewest
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 | all
29 | runtime; build; native; contentfiles; analyzers
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/PocketSharp/Models/PocketImage.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using System;
3 |
4 | namespace PocketSharp.Models
5 | {
6 | ///
7 | /// Image
8 | ///
9 | [JsonObject]
10 | public class PocketImage
11 | {
12 | ///
13 | /// Gets or sets the ID.
14 | ///
15 | ///
16 | /// The ID.
17 | ///
18 | [JsonProperty("image_id")]
19 | public string ID { get; set; }
20 |
21 | ///
22 | /// Gets or sets the Item ID.
23 | ///
24 | ///
25 | /// The Item ID.
26 | ///
27 | [JsonProperty("item_id")]
28 | public string ItemID { get; set; }
29 |
30 | ///
31 | /// Gets or sets the caption.
32 | ///
33 | ///
34 | /// The caption.
35 | ///
36 | [JsonProperty]
37 | public string Caption { get; set; }
38 |
39 | ///
40 | /// Gets or sets the credit.
41 | ///
42 | ///
43 | /// The credit.
44 | ///
45 | [JsonProperty]
46 | public string Credit { get; set; }
47 |
48 | ///
49 | /// Gets or sets the URI.
50 | ///
51 | ///
52 | /// The URI.
53 | ///
54 | [JsonProperty("src")]
55 | public Uri Uri { get; set; }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/PocketSharp.Examples/PocketSharp.UWP/Properties/Default.rd.xml:
--------------------------------------------------------------------------------
1 |
17 |
18 |
19 |
20 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/PocketSharp/Models/PocketVideo.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using System;
3 |
4 | namespace PocketSharp.Models
5 | {
6 | ///
7 | /// Video
8 | ///
9 | [JsonObject]
10 | public class PocketVideo
11 | {
12 | ///
13 | /// Gets or sets the ID.
14 | ///
15 | ///
16 | /// The ID.
17 | ///
18 | [JsonProperty("video_id")]
19 | public string ID { get; set; }
20 |
21 | ///
22 | /// Gets or sets the Item ID.
23 | ///
24 | ///
25 | /// The Item ID.
26 | ///
27 | [JsonProperty("item_id")]
28 | public string ItemID { get; set; }
29 |
30 | ///
31 | /// Gets or sets the external ID.
32 | ///
33 | ///
34 | /// The external ID.
35 | ///
36 | [JsonProperty("vid")]
37 | public string ExternalID { get; set; }
38 |
39 | ///
40 | /// Gets or sets the URI.
41 | ///
42 | ///
43 | /// The URI.
44 | ///
45 | [JsonProperty("src")]
46 | public Uri Uri { get; set; }
47 |
48 | ///
49 | /// Gets or sets the URI.
50 | ///
51 | ///
52 | /// The URI.
53 | ///
54 | [JsonProperty("type")]
55 | [JsonConverter(typeof(VideoTypeConverter))]
56 | public PocketVideoType Type { get; set; }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/PocketSharp/Models/PocketUser.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using System;
3 |
4 | namespace PocketSharp.Models
5 | {
6 | ///
7 | /// Access Code
8 | ///
9 | [JsonObject]
10 | public class PocketUser
11 | {
12 | ///
13 | /// Pocket user id.
14 | ///
15 | public string Id { get; set; }
16 |
17 | ///
18 | /// The access code.
19 | ///
20 | public string Code { get; set; }
21 |
22 | ///
23 | /// Pocket username.
24 | ///
25 | public string Username { get; set; }
26 |
27 | ///
28 | /// Email address.
29 | ///
30 | public string Email { get; set; }
31 |
32 | ///
33 | /// First name.
34 | ///
35 | public string FirstName { get; set; }
36 |
37 | ///
38 | /// Last name.
39 | ///
40 | public string LastName { get; set; }
41 |
42 | ///
43 | /// Profile avatar.
44 | ///
45 | public Uri Avatar { get; set; }
46 |
47 | ///
48 | /// Is default avatar.
49 | ///
50 | public bool IsDefaultAvatar { get; set; } = true;
51 |
52 | ///
53 | /// Follower count.
54 | ///
55 | public int Followers { get; set; }
56 |
57 | ///
58 | /// Follow count.
59 | ///
60 | public int Follows { get; set; }
61 |
62 | ///
63 | /// Profile text.
64 | ///
65 | public string Description { get; set; }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/PocketSharp.Tests/MiscTests.cs:
--------------------------------------------------------------------------------
1 | using PocketSharp.Models;
2 | using System.Collections.Generic;
3 | using System.Threading.Tasks;
4 | using Xunit;
5 | using System.Linq;
6 |
7 | namespace PocketSharp.Tests
8 | {
9 | public class MiscTests : TestsBase
10 | {
11 | private int Incrementor = 0;
12 |
13 | public MiscTests() : base()
14 | {
15 | client.PreRequest = method => Incrementor++;
16 | }
17 |
18 |
19 | [Fact]
20 | public async Task CheckPreRequestAction()
21 | {
22 | IEnumerable items = await client.Get(count: 1);
23 | PocketItem item = items.First();
24 |
25 | await client.Favorite(item);
26 | await client.Unfavorite(item);
27 |
28 | Assert.True(Incrementor >= 3);
29 | }
30 |
31 | [Fact]
32 | public void ItemEqualityChecks()
33 | {
34 | PocketItem item1 = new PocketItem() { ID = "12872" };
35 | PocketItem item2 = new PocketItem() { ID = "12872" };
36 | PocketItem item3 = new PocketItem() { ID = "12800" };
37 | PocketArticle article = new PocketArticle();
38 |
39 | Assert.True(item1.Equals(item2));
40 | Assert.False(item1.Equals(item3));
41 | Assert.False(item1.Equals(null));
42 |
43 | Assert.True(item1 == item2);
44 | Assert.False(item1 == item3);
45 | Assert.False(item1 == null);
46 |
47 | Assert.False(item1 != item2);
48 | Assert.True(item1 != item3);
49 | Assert.True(item1 != null);
50 |
51 | Assert.False(item1.Equals(article));
52 |
53 | Assert.True(new List() { item1 }.IndexOf(item2) > -1);
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/PocketSharp/Utilities/PocketException.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace PocketSharp
4 | {
5 | ///
6 | /// custom Pocket API Exceptions
7 | ///
8 | public class PocketException : Exception
9 | {
10 | ///
11 | /// Gets or sets the pocket error code.
12 | ///
13 | ///
14 | /// The pocket error code.
15 | ///
16 | public int? PocketErrorCode { get; set; }
17 |
18 | ///
19 | /// Gets or sets the pocket error.
20 | ///
21 | ///
22 | /// The pocket error.
23 | ///
24 | public string PocketError { get; set; }
25 |
26 |
27 | ///
28 | /// Initializes a new instance of the class.
29 | ///
30 | public PocketException()
31 | : base() { }
32 |
33 |
34 | ///
35 | /// Initializes a new instance of the class.
36 | ///
37 | /// The message that describes the error.
38 | public PocketException(string message)
39 | : base(message) { }
40 |
41 |
42 | ///
43 | /// Initializes a new instance of the class.
44 | ///
45 | /// The error message that explains the reason for the exception.
46 | /// The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner exception is specified.
47 | public PocketException(string message, Exception innerException)
48 | : base(message, innerException) { }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/PocketSharp.Examples/PocketSharp.UWP/MainPage.xaml.cs:
--------------------------------------------------------------------------------
1 | using PocketSharp.Models;
2 | using System.Collections.Generic;
3 | using System.Collections.ObjectModel;
4 | using System.Diagnostics;
5 | using System.Linq;
6 | using System.Threading.Tasks;
7 | using Windows.UI.Xaml.Controls;
8 |
9 | // The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
10 |
11 | namespace PocketSharp.UWP
12 | {
13 | ///
14 | /// An empty page that can be used on its own or navigated to within a Frame.
15 | ///
16 |
17 | public sealed partial class MainPage : Page
18 | {
19 | public ObservableCollection Items { get; set; }
20 |
21 |
22 | public MainPage()
23 | {
24 | InitializeComponent();
25 | Items = new ObservableCollection();
26 | }
27 |
28 | public async Task LoadData()
29 | {
30 | // !! please don't misuse this account !!
31 | PocketClient client = new PocketClient(
32 | consumerKey: "15396-f6f92101d72c8e270a6c9bb3",
33 | callbackUri: "http://frontendplay.com",
34 | accessCode: "80acf6c5-c198-03c0-b94c-e74402"
35 | );
36 |
37 | List items = null;
38 |
39 | try
40 | {
41 | items = (await client.Get()).ToList();
42 | foreach (var item in items)
43 | {
44 | Items.Add(item);
45 | }
46 | }
47 | catch (PocketException ex)
48 | {
49 | Debug.WriteLine(ex.Message);
50 | }
51 | }
52 |
53 | private async void Button_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
54 | {
55 | await LoadData();
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/PocketSharp.Examples/PocketSharp.UWP/MainPage.xaml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/PocketSharp.Examples/PocketSharp.UWP/Package.appxmanifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
13 |
14 |
15 |
16 |
17 | PocketSharp.UWP
18 | tobi
19 | Assets\StoreLogo.png
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
34 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/PocketSharp/Models/PocketLimits.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 |
3 | namespace PocketSharp.Models
4 | {
5 | ///
6 | /// API Limitation Statistics
7 | ///
8 | [JsonObject]
9 | public class PocketLimits
10 | {
11 | ///
12 | /// Gets or sets the rate limit.
13 | ///
14 | ///
15 | /// Rate limit for current consumer key.
16 | ///
17 | [JsonProperty("X-Limit-Key-Limit")]
18 | public int RateLimitForConsumerKey { get; set; }
19 |
20 | ///
21 | /// Gets or sets the remaining calls.
22 | ///
23 | ///
24 | /// Remaining calls for current consumer key.
25 | ///
26 | [JsonProperty("X-Limit-Key-Remaining")]
27 | public int RemainingCallsForConsumerKey { get; set; }
28 |
29 | ///
30 | /// Gets or sets the reset seconds.
31 | ///
32 | ///
33 | /// Seconds until limit resets for current consumer key.
34 | ///
35 | [JsonProperty("X-Limit-Key-Reset")]
36 | public int SecondsUntilLimitResetsForConsumerKey { get; set; }
37 |
38 | ///
39 | /// Gets or sets the rate limit.
40 | ///
41 | ///
42 | /// Rate limit for current user.
43 | ///
44 | [JsonProperty("X-Limit-User-Limit")]
45 | public int RateLimitForUser { get; set; }
46 |
47 | ///
48 | /// Gets or sets the remaining calls.
49 | ///
50 | ///
51 | /// Remaining calls for current user.
52 | ///
53 | [JsonProperty("X-Limit-User-Remaining")]
54 | public int RemainingCallsForUser { get; set; }
55 |
56 | ///
57 | /// Gets or sets the reset seconds.
58 | ///
59 | ///
60 | /// Seconds until limit resets for current user.
61 | ///
62 | [JsonProperty("X-Limit-User-Reset")]
63 | public int SecondsUntilLimitResetsForUser { get; set; }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/PocketSharp/Components/Trending.cs:
--------------------------------------------------------------------------------
1 | using PocketSharp.Models;
2 | using System.Collections.Generic;
3 | using System.Threading;
4 | using System.Threading.Tasks;
5 |
6 | namespace PocketSharp
7 | {
8 | ///
9 | /// PocketClient
10 | ///
11 | public partial class PocketClient
12 | {
13 | ///
14 | /// Get trending articles on Pocket.
15 | ///
16 | /// Article count.
17 | /// Two-letter language code for language-specific results.
18 | /// The cancellation token.
19 | ///
20 | ///
21 | public async Task> GetTrendingArticles(int count = 20, string languageCode = "en", CancellationToken cancellationToken = default(CancellationToken))
22 | {
23 | return (await Request("getGlobalRecs", cancellationToken, new Dictionary()
24 | {
25 | { "locale_lang", languageCode },
26 | { "count", count.ToString() },
27 | { "version", "2" }
28 | }, false)).Items ?? new List();
29 | }
30 |
31 |
32 | ///
33 | /// Get trending topics on Pocket.
34 | ///
35 | /// Two-letter language code for language-specific results.
36 | /// The cancellation token.
37 | ///
38 | ///
39 | public async Task> GetTrendingTopics(string languageCode = "en", CancellationToken cancellationToken = default(CancellationToken))
40 | {
41 | return (await Request("getTrendingTopics", cancellationToken, new Dictionary()
42 | {
43 | { "locale_lang", languageCode },
44 | { "version", "2" }
45 | }, false)).Items ?? new List();
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 | **PocketSharp** is a .NET Standard library that integrates the [Pocket API v3](http://getpocket.com/developer).
4 |
5 | ## Install PocketSharp using [NuGet](https://www.nuget.org/packages/PocketSharp/)
6 |
7 | ```
8 | Install-Package PocketSharp
9 | ```
10 |
11 |
12 | ## Documentation
13 |
14 | See [wiki](https://github.com/ceee/PocketSharp/wiki)
15 |
16 | ## Where's the Article View API?
17 |
18 | You can either use the open source [ReadSharp](https://github.com/ceee/ReadSharp) parser or if you want to use the official API by Pocket, you have to request access to it.
19 | Afterwards you can use the access information to query the endpoint with PocketSharp. Instructions [here](https://github.com/ceee/PocketSharp/wiki/Article-parser).
20 |
21 |
22 | ---
23 |
24 | ## Usage Example:
25 |
26 | A search for items containing `CSS`:
27 |
28 | ```csharp
29 | PocketClient client = new PocketClient("[YOUR_CONSUMER_KEY]", "[YOUR_ACCESS_CODE]");
30 |
31 | List items = await client.Search("css");
32 |
33 | items.ForEach(
34 | item => Debug.WriteLine(item.ID + " | " + item.Title)
35 | );
36 | ```
37 |
38 | Which will output:
39 |
40 | 330361896 | CSS Front-end Frameworks with comparison : By usabli.ca
41 | 345541438 | Editr - HTML, CSS, JavaScript playground
42 | 251743431 | CSS Architecture
43 | 343693149 | CSS3 Transitions - Thank God We Have A Specification!
44 | ...
45 |
46 | ---
47 |
48 | ## Dependencies
49 |
50 | - [Newtonsoft.Json](https://www.nuget.org/packages/Newtonsoft.Json/)
51 |
52 | ## Contributors
53 |
54 | | [](https://github.com/ceee "Tobias Klika") | [](https://github.com/ScottIsAFool "Scott Lovegrove") |
55 | |---|---|
56 | | [ceee](https://github.com/ceee) | [ScottIsAFool](https://github.com/ScottIsAFool) |
57 |
58 | ## License
59 |
60 | [MIT License](https://github.com/ceee/PocketSharp/blob/master/LICENSE-MIT)
61 |
--------------------------------------------------------------------------------
/PocketSharp/Components/Add.cs:
--------------------------------------------------------------------------------
1 | using PocketSharp.Models;
2 | using System;
3 | using System.Threading;
4 | using System.Threading.Tasks;
5 |
6 | namespace PocketSharp
7 | {
8 | ///
9 | /// PocketClient
10 | ///
11 | public partial class PocketClient
12 | {
13 | ///
14 | /// Adds a new item to pocket
15 | ///
16 | /// The URL of the item you want to save
17 | /// A comma-separated list of tags to apply to the item
18 | /// This can be included for cases where an item does not have a title, which is typical for image or PDF URLs. If Pocket detects a title from the content of the page, this parameter will be ignored.
19 | /// If you are adding Pocket support to a Twitter client, please send along a reference to the tweet status id. This allows Pocket to show the original tweet alongside the article.
20 | /// The cancellation token.
21 | ///
22 | /// A simple representation of the saved item which doesn't contain all data (is only returned by calling the Retrieve method)
23 | ///
24 | /// (1) Uri should be absolute.
25 | ///
26 | public async Task Add(
27 | Uri uri,
28 | string[] tags = null,
29 | string title = null,
30 | string tweetID = null,
31 | CancellationToken cancellationToken = default(CancellationToken)
32 | )
33 | {
34 | if (!uri.IsAbsoluteUri)
35 | {
36 | throw new FormatException("(1) Uri should be absolute.");
37 | }
38 |
39 | AddParameters parameters = new AddParameters()
40 | {
41 | Uri = uri,
42 | Tags = tags,
43 | Title = title,
44 | TweetID = tweetID
45 | };
46 |
47 | Add response = await Request("add", cancellationToken, parameters.Convert());
48 |
49 | return response.Item;
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/PocketSharp/Components/Statistics.cs:
--------------------------------------------------------------------------------
1 | using PocketSharp.Models;
2 | using System;
3 | using System.Threading;
4 | using System.Threading.Tasks;
5 |
6 | namespace PocketSharp
7 | {
8 | ///
9 | /// PocketClient
10 | ///
11 | public partial class PocketClient
12 | {
13 | ///
14 | /// Statistics from the user account.
15 | ///
16 | /// The cancellation token.
17 | ///
18 | ///
19 | public async Task GetUserStatistics(CancellationToken cancellationToken = default(CancellationToken))
20 | {
21 | return await Request("stats", cancellationToken);
22 | }
23 |
24 |
25 | ///
26 | /// Returns API usage statistics.
27 | /// If a request was made before, the data is returned synchronously from the cache.
28 | /// Note: This method only works for authenticated users with a given AccessCode.
29 | ///
30 | /// The cancellation token.
31 | ///
32 | ///
33 | public async Task GetUsageLimits(CancellationToken cancellationToken = default(CancellationToken))
34 | {
35 | string rateLimitForConsumerKey = TryGetHeaderValue(lastHeaders, "X-Limit-Key-Limit");
36 |
37 | if (rateLimitForConsumerKey == null)
38 | {
39 | // this is the fastest way to do a non-failing request to receive the correct headers
40 | await Get(
41 | cancellationToken: cancellationToken,
42 | count: 1
43 | );
44 | }
45 |
46 | return new PocketLimits()
47 | {
48 | RateLimitForConsumerKey = Convert.ToInt32(TryGetHeaderValue(lastHeaders, "X-Limit-Key-Limit")),
49 | RemainingCallsForConsumerKey = Convert.ToInt32(TryGetHeaderValue(lastHeaders, "X-Limit-Key-Remaining")),
50 | SecondsUntilLimitResetsForConsumerKey = Convert.ToInt32(TryGetHeaderValue(lastHeaders, "X-Limit-Key-Reset")),
51 | RateLimitForUser = Convert.ToInt32(TryGetHeaderValue(lastHeaders, "X-Limit-User-Limit")),
52 | RemainingCallsForUser = Convert.ToInt32(TryGetHeaderValue(lastHeaders, "X-Limit-User-Remaining")),
53 | SecondsUntilLimitResetsForUser = Convert.ToInt32(TryGetHeaderValue(lastHeaders, "X-Limit-User-Reset"))
54 | };
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/PocketSharp/Models/Parameters/Parameters.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Reflection;
4 | using System.Runtime.Serialization;
5 | using System.Linq;
6 | using System.Collections;
7 |
8 | namespace PocketSharp.Models
9 | {
10 | ///
11 | /// Parameter
12 | ///
13 | internal class Parameters
14 | {
15 |
16 | ///
17 | /// Converts an object to a list of HTTP Post parameters.
18 | ///
19 | ///
20 | public Dictionary Convert()
21 | {
22 | // store HTTP parameters here
23 | Dictionary parameterDict = new Dictionary();
24 |
25 | // get object properties
26 | IEnumerable properties = this.GetType()
27 | .GetTypeInfo()
28 | .DeclaredMembers
29 | .Where(p => p.CustomAttributes.FirstOrDefault(a => a.AttributeType == typeof(DataMemberAttribute)) != null);
30 |
31 | // gather attributes of object
32 | foreach (MemberInfo memberInfo in properties)
33 | {
34 | DataMemberAttribute attribute = (DataMemberAttribute)memberInfo.GetCustomAttributes(typeof(DataMemberAttribute), false).FirstOrDefault();
35 | string name = attribute.Name ?? memberInfo.Name.ToLower();
36 | object value = null;
37 |
38 | if (memberInfo is FieldInfo)
39 | {
40 | value = ((FieldInfo)memberInfo).GetValue(this);
41 | }
42 | else
43 | {
44 | value = ((PropertyInfo)memberInfo).GetValue(this, null);
45 | }
46 |
47 | // invalid parameter
48 | if (value == null)
49 | {
50 | continue;
51 | }
52 |
53 | // convert array to comma-seperated list
54 | if (value is IEnumerable && value.GetType().GetElementType() == typeof(string))
55 | {
56 | value = string.Join(",", ((IEnumerable)value).Cast