Skip to content

Instantly share code, notes, and snippets.

@dotMorten
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dotMorten/85ffed0be3bce412850e to your computer and use it in GitHub Desktop.
Save dotMorten/85ffed0be3bce412850e to your computer and use it in GitHub Desktop.
How to add url to Readability using Hammock (assumes you've already done the oauth part to get the token and tokenSecret)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Peregrine.Utilities
{
public static class Readability
{
private const string consumerKey = "CONSUMERKEY";
private const string consumerSecret = "CONSUMERSECRET";
private const string serviceurl = "https://www.readability.com/api/rest/v1/bookmarks";
public static void AddUrl(string token, string tokenSecret, string username,
string url,
Action<string> complete)
{
//Return codes which should be treated as success: 201=Created, 202=Accepted, 409 Conflict
//Error codes: 400 Bad Request, 401 Auth required, 500 Internal Server Error
if (token == null)
{
complete("Username not set. Please got to settings to configure your Readability account");
return;
}
Hammock.RestClient client = new Hammock.RestClient()
{
Authority = "https://www.readability.com/api/rest/v1",
HasElevatedPermissions = true,
Credentials = new Hammock.Authentication.OAuth.OAuthCredentials()
{
ConsumerKey = consumerKey, ConsumerSecret = consumerSecret,
Token = token, TokenSecret = tokenSecret, ClientUsername = username,
SignatureMethod = Hammock.Authentication.OAuth.OAuthSignatureMethod.HmacSha1,
ParameterHandling = Hammock.Authentication.OAuth.OAuthParameterHandling.UrlOrPostParameters,
Version = "1.0", Type = Hammock.Authentication.OAuth.OAuthType.ProtectedResource
}
};
Hammock.RestRequest request = new Hammock.RestRequest()
{
Path = "bookmarks", Method = Hammock.Web.WebMethod.Post
};
request.AddParameter("url", url);
TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
client.BeginRequest(request, new Hammock.RestCallback((a, b, c) =>
{
if (complete != null)
{
int code = (int)b.StatusCode;
if (code < 300 && code>=200 || code == 409 )
{
complete("OK");
}
else
{
complete(b.StatusDescription);
}
}
}));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment