9 Commits

Author SHA1 Message Date
swcs c36995ea2e update readme; 2013-07-07 22:33:09 +02:00
swcs 9d213d309f fix callbackUri escaping in authentication process; 2013-07-07 22:31:29 +02:00
swcs 01ab0f8bb8 move Auth Models into Response folder; remove unused usings; 2013-07-04 23:47:39 +02:00
swcs 7f38e346a2 add Tests project; 2013-07-03 23:19:47 +02:00
swcs 422ec73374 update documentation; 2013-07-02 21:15:57 +02:00
swcs 5382dd3326 update documentation; 2013-07-02 21:05:43 +02:00
swcs 761a33ebbe update documentation; 2013-07-02 20:59:06 +02:00
swcs edccc8891c update documentation; 2013-07-02 20:58:13 +02:00
swcs 719a53a9c5 fix callback encoding; callback Uri -> string; 2013-07-02 20:43:38 +02:00
13 changed files with 199 additions and 33 deletions
@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{F1CEA363-7039-40BA-9744-0071F46BB90C}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>PocketSharp.Tests</RootNamespace>
<AssemblyName>PocketSharp.Tests</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
</ItemGroup>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
</ItemGroup>
</Otherwise>
</Choose>
<ItemGroup>
<Compile Include="UnitTest1.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
</ItemGroup>
</When>
</Choose>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("PocketSharp.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PocketSharp.Tests")]
[assembly: AssemblyCopyright("Copyright © 2013")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("fbe5a0d2-d0de-44b1-8b8a-cf8cd3ac2230")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
+14
View File
@@ -0,0 +1,14 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace PocketSharp.Tests
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
}
}
}
+6
View File
@@ -5,6 +5,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PocketSharp", "PocketSharp\
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PocketSharp.Console", "PocketSharp.Console\PocketSharp.Console.csproj", "{81B7D587-A189-4785-BDFE-CA8A9ABA0760}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PocketSharp.Tests", "PocketSharp.Tests\PocketSharp.Tests.csproj", "{F1CEA363-7039-40BA-9744-0071F46BB90C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -19,6 +21,10 @@ Global
{81B7D587-A189-4785-BDFE-CA8A9ABA0760}.Debug|Any CPU.Build.0 = Debug|Any CPU
{81B7D587-A189-4785-BDFE-CA8A9ABA0760}.Release|Any CPU.ActiveCfg = Release|Any CPU
{81B7D587-A189-4785-BDFE-CA8A9ABA0760}.Release|Any CPU.Build.0 = Release|Any CPU
{F1CEA363-7039-40BA-9744-0071F46BB90C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F1CEA363-7039-40BA-9744-0071F46BB90C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F1CEA363-7039-40BA-9744-0071F46BB90C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F1CEA363-7039-40BA-9744-0071F46BB90C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
+2 -4
View File
@@ -1,7 +1,5 @@
using PocketSharp.Models.Authentification;
using PocketSharp.Models;
using System;
using System.Collections.Generic;
using RestSharp;
namespace PocketSharp
{
@@ -52,7 +50,7 @@ namespace PocketSharp
RequestCode = requestCode;
}
return new Uri(string.Format(authentificationUri, RequestCode, Uri.EscapeDataString(CallbackUri.ToString())));
return new Uri(string.Format(authentificationUri, RequestCode, CallbackUri));
}
+8 -8
View File
@@ -182,7 +182,7 @@ namespace PocketSharp.Models
/// The _ tag dictionary.
/// </value>
[DataMember(Name = "tags")]
public Dictionary<string, PocketTag> _TagDictionary { get; set; }
public Dictionary<string, PocketTag> TagDictionary { get; set; }
/// <summary>
/// Gets or sets the _ image dictionary.
@@ -191,7 +191,7 @@ namespace PocketSharp.Models
/// The _ image dictionary.
/// </value>
[DataMember(Name = "images")]
public Dictionary<string, PocketImage> _ImageDictionary { get; set; }
public Dictionary<string, PocketImage> ImageDictionary { get; set; }
/// <summary>
/// Gets or sets the _ video dictionary.
@@ -200,7 +200,7 @@ namespace PocketSharp.Models
/// The _ video dictionary.
/// </value>
[DataMember(Name = "videos")]
public Dictionary<string, PocketVideo> _VideoDictionary { get; set; }
public Dictionary<string, PocketVideo> VideoDictionary { get; set; }
/// <summary>
/// Gets or sets the _ author dictionary.
@@ -209,7 +209,7 @@ namespace PocketSharp.Models
/// The _ author dictionary.
/// </value>
[DataMember(Name = "authors")]
public Dictionary<string, PocketAuthor> _AuthorDictionary { get; set; }
public Dictionary<string, PocketAuthor> AuthorDictionary { get; set; }
/// <summary>
@@ -221,7 +221,7 @@ namespace PocketSharp.Models
[IgnoreDataMember]
public List<PocketTag> Tags
{
get { return Utilities.DictionaryToList<PocketTag>(_TagDictionary); }
get { return Utilities.DictionaryToList<PocketTag>(TagDictionary); }
}
/// <summary>
@@ -233,7 +233,7 @@ namespace PocketSharp.Models
[IgnoreDataMember]
public List<PocketImage> Images
{
get { return Utilities.DictionaryToList<PocketImage>(_ImageDictionary); }
get { return Utilities.DictionaryToList<PocketImage>(ImageDictionary); }
}
/// <summary>
@@ -257,7 +257,7 @@ namespace PocketSharp.Models
[IgnoreDataMember]
public List<PocketVideo> Videos
{
get { return Utilities.DictionaryToList<PocketVideo>(_VideoDictionary); }
get { return Utilities.DictionaryToList<PocketVideo>(VideoDictionary); }
}
/// <summary>
@@ -269,7 +269,7 @@ namespace PocketSharp.Models
[IgnoreDataMember]
public List<PocketAuthor> Authors
{
get { return Utilities.DictionaryToList<PocketAuthor>(_AuthorDictionary); }
get { return Utilities.DictionaryToList<PocketAuthor>(AuthorDictionary); }
}
}
}
@@ -1,6 +1,6 @@
using System.Runtime.Serialization;
namespace PocketSharp.Models.Authentification
namespace PocketSharp.Models
{
/// <summary>
/// Access Code
@@ -1,6 +1,6 @@
using System.Runtime.Serialization;
namespace PocketSharp.Models.Authentification
namespace PocketSharp.Models
{
/// <summary>
/// Request Code
+2 -2
View File
@@ -34,7 +34,7 @@ namespace PocketSharp.Models
/// The _ item dictionary.
/// </value>
[DataMember(Name = "list")]
public Dictionary<string, PocketItem> _ItemDictionary { get; set; }
public Dictionary<string, PocketItem> ItemDictionary { get; set; }
/// <summary>
/// Gets the items.
@@ -45,7 +45,7 @@ namespace PocketSharp.Models
[IgnoreDataMember]
public List<PocketItem> Items
{
get { return Utilities.DictionaryToList<PocketItem>(_ItemDictionary); }
get { return Utilities.DictionaryToList<PocketItem>(ItemDictionary); }
}
}
}
+4 -3
View File
@@ -1,5 +1,6 @@
using PocketSharp.Models;
using RestSharp;
using RestSharp.Contrib;
using System;
using System.Collections.Generic;
using System.Net;
@@ -29,7 +30,7 @@ namespace PocketSharp
/// <summary>
/// callback URL for API calls
/// </summary>
protected Uri CallbackUri { get; set; }
protected string CallbackUri { get; set; }
/// <summary>
/// Accessor for the Pocket API key
@@ -59,7 +60,7 @@ namespace PocketSharp
/// <param name="consumerKey">The API key</param>
/// <param name="accessCode">Provide an access code if the user is already authenticated</param>
/// <param name="callbackUri">The callback URL is called by Pocket after authentication</param>
public PocketClient(string consumerKey, string accessCode = null, Uri callbackUri = null)
public PocketClient(string consumerKey, string accessCode = null, string callbackUri = null)
{
// assign public properties
ConsumerKey = consumerKey;
@@ -73,7 +74,7 @@ namespace PocketSharp
// assign callback uri if submitted
if (callbackUri != null)
{
CallbackUri = callbackUri;
CallbackUri = HttpUtility.UrlEncode(callbackUri.ToString());
}
// initialize REST client
+5 -3
View File
@@ -56,8 +56,8 @@
<Compile Include="Components\ModifyTags.cs" />
<Compile Include="Components\Retrieve.cs" />
<Compile Include="JsonDeserializer.cs" />
<Compile Include="Models\Authentification\AccessCode.cs" />
<Compile Include="Models\Authentification\RequestCode.cs" />
<Compile Include="Models\Response\AccessCode.cs" />
<Compile Include="Models\Response\RequestCode.cs" />
<Compile Include="Models\Parameters\AddParameters.cs" />
<Compile Include="Models\PocketAuthor.cs" />
<Compile Include="Models\PocketImage.cs" />
@@ -75,7 +75,9 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Utilities.cs" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Content Include="authentication-screen.png" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

+34 -11
View File
@@ -1,12 +1,9 @@
# PocketSharp
> This project is work in progress. Be aware of this!
> This project is work in progress.
> PocketSharp will be released as a NuGet package when ready.
PocketSharp is a C#.NET class library, that integrates the [Pocket API v3](http://getpocket.com/developer).
_If you don't know [Pocket](http://getpocket.com), be sure to check it out. It's an awesome service, which lets you save articles, videos, ... in the cloud and access it from all your devices._
PocketSharp consists of 4 parts:
**PocketSharp** is a C#.NET class library, that integrates the [Pocket API v3](http://getpocket.com/developer) and consists of 4 parts:
- Authentication
- Retrieve
@@ -15,6 +12,10 @@ PocketSharp consists of 4 parts:
---
_If you don't know [Pocket](http://getpocket.com), be sure to check it out. It's an awesome service that lets you save articles, videos, ... in the cloud and access it from all your devices._
---
## Usage Example
Request a [Consumer Key on Pocket.](http://getpocket.com/developer/apps/)
@@ -86,23 +87,32 @@ _client.AccessCode = "[YOU_ACCESS_CODE]";
In order to communicate with a Pocket User, you will need a consumer key (which is generated by [creating a new application on Pocket](http://getpocket.com/developer/apps/)) and an **Access Code**.
This is a 3-step process:
The authentication is a 3-step process:
1) Receive the **request code** and **authentication URI** from the library by calling `string GetRequestCode()`:
#### 1) Generate authentication URI
Receive the **request code** and **authentication URI** from the library by calling `string GetRequestCode()`:
```csharp
string requestCode = _client.GetRequestCode();
// 0f453f2d-1605-8584-28fd-39af8e
Uri authenticationUri = _client.GenerateAuthenticationUri();
// https://getpocket.com/auth/authorize?request_token=0f453f2d-1605-8584-28fd-39af8e&redirect_uri=http%253a%252f%252fceecore.com
```
The _request code_ is stored internally, but you can also provide it as param in `GenerateAuthenticationUri(string requestCode = null)`.
2) Next you need to redirect the user to the `authenticationUri`, which displays a prompt to grant permissions for the application. After the user granted or denied, he/she is redirected to the `callbackUri`.
#### 2) Redirect to Pocket
Next you need to redirect the user to the `authenticationUri`, which displays a prompt to grant permissions for the application (see image). After the user granted or denied, he/she is redirected to the `callbackUri`.
3) Call `string GetAccessCode(string requestCode = null)`
![authentication screen](https://raw.github.com/ceee/PocketSharp/master/PocketSharp/authentication-screen.png)
#### 3) Get Access Code
Call `string GetAccessCode(string requestCode = null)`
```csharp
string accessCode = _client.GetAccessCode();
// fa8bfc16-69b3-4d22-7db7-84a58d
```
Again, the received _access code_ is stored internally.
@@ -116,6 +126,13 @@ Without it you would always have to redo the authentication process.
## Retrieve
Get list of all items:
```csharp
List<PocketItem> items = _client.Retrieve();
// equivalent to: _client.Retrieve(RetrieveFilter.All)
```
Find items by a tag:
```csharp
@@ -228,10 +245,16 @@ Renames a tag for the specified item:
## Release History
- 2013-07-01 v0.3.0-pre update authentication process _(breaking)_
- 2013-07-07 v0.3.1 authentication fixes
- 2013-07-02 v0.3.0 update authentication process
- 2013-06-27 v0.2.0 add, modify item & modify tags
- 2013-06-26 v0.1.0 authentication & retrieve functionality
## Used Packages
- [RestSharp](http://restsharp.org/)
- [ServiceStack.Text](https://github.com/ServiceStack/ServiceStack.Text)
## Contributors
| [![twitter/artistandsocial](http://gravatar.com/avatar/9c61b1f4307425f12f05d3adb930ba66?s=70)](http://twitter.com/artistandsocial "Follow @artistandsocial on Twitter") |
|---|