Permalink
Browse files

also added the query string authenticator for completeness, header au…

…thenticator is default though
  • Loading branch information...
1 parent 769e0b2 commit d6946e59c72228ac434a6a31ef1aa9cd3e186efa @ntziolis committed Mar 22, 2012
Showing with 35 additions and 12 deletions.
  1. +29 −8 AppHarbor.Net/AppHaborAuthenticator.cs
  2. +6 −4 AppHarbor.Net/AppHarborApi.cs
@@ -21,23 +21,44 @@
namespace AppHarbor
{
- public class AppHaborAuthenticator : RestSharp.IAuthenticator
- {
- private readonly string _AuthorizationValue;
- public AppHaborAuthenticator(AuthInfo authInfo)
- {
+ public class QUeryStringAppHaborAuthenticator : RestSharp.IAuthenticator
+ {
+ private readonly string _AuthorizationQueryString;
+
+ public QUeryStringAppHaborAuthenticator(AuthInfo authInfo)
+ {
if (authInfo == null)
throw new ArgumentNullException("authInfo");
if (authInfo.AccessToken == null)
throw new ArgumentNullException("authInfo.AccessToken");
+ _AuthorizationQueryString = string.Format("?access_token={0}", authInfo.AccessToken);
+ }
+
+ public void Authenticate(RestSharp.IRestClient client, RestSharp.IRestRequest request)
+ {
+ request.Resource += _AuthorizationQueryString;
+ }
+ }
+
+ public class HeaderAppHaborAuthenticator : RestSharp.IAuthenticator
+ {
+ private readonly string _AuthorizationHeaderValue;
- _AuthorizationValue = string.Format("BEARER {0}", authInfo.AccessToken);
- }
+ public HeaderAppHaborAuthenticator(AuthInfo authInfo)
+ {
+ if (authInfo == null)
+ throw new ArgumentNullException("authInfo");
+
+ if (authInfo.AccessToken == null)
+ throw new ArgumentNullException("authInfo.AccessToken");
+
+ _AuthorizationHeaderValue = string.Format("BEARER {0}", authInfo.AccessToken);
+ }
public void Authenticate(RestSharp.IRestClient client, RestSharp.IRestRequest request)
{
- request.AddHeader("Authorization", _AuthorizationValue);
+ request.AddHeader("Authorization", _AuthorizationHeaderValue);
}
}
}
@@ -102,7 +102,7 @@ internal AppHarborApi(AuthInfo authInfo, RestClient restClient)
throw new ArgumentNullException("restClient");
_Client = restClient;
- _Client.Authenticator = new AppHaborAuthenticator(authInfo);
+ _Client.Authenticator = new HeaderAppHaborAuthenticator(authInfo);
_BaseUri = new Uri(BaseUrl);
_JsonDeserializer = new CustomJsonDeserializer();
@@ -230,6 +230,8 @@ private bool ExecuteDelete(RestRequest request)
if (response == null)
return false;
+ // System.Net.HttpStatusCode.NotFound is returned if there is nothing to delete
+
return (response.StatusCode == System.Net.HttpStatusCode.NoContent);
}
@@ -262,11 +264,11 @@ public Application GetApplication(string applicationID)
}
/// <summary>
- /// Creates a new application
+ /// Creates a new AppHarbor application
/// </summary>
/// <param name="name">Name of the application.</param>
- /// <param name="regionIdentifier">Region the application will be created at, will default to "amazon-web-services::us-east-1".</param>
- /// <returns></returns>
+ /// <param name="regionIdentifier">Region the application will be created in. If null, it will default to "amazon-web-services::us-east-1".</param>
+ /// <returns>Returns a create result. The Status of the CreateResult indicates whether the creation was successfull or not.</returns>
public CreateResult<string> CreateApplication(string name, string regionIdentifier)
{
CheckArgumentNull("name", name);

0 comments on commit d6946e5

Please sign in to comment.