Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to previous pull request #50

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions createsend-netstandard.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26403.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "createsend-netstandard", "createsend-netstandard\createsend-netstandard.csproj", "{74932B63-D31D-4682-BE98-5F96D0B91E04}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{74932B63-D31D-4682-BE98-5F96D0B91E04}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{74932B63-D31D-4682-BE98-5F96D0B91E04}.Debug|Any CPU.Build.0 = Debug|Any CPU
{74932B63-D31D-4682-BE98-5F96D0B91E04}.Release|Any CPU.ActiveCfg = Release|Any CPU
{74932B63-D31D-4682-BE98-5F96D0B91E04}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
29 changes: 29 additions & 0 deletions createsend-netstandard/Account.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Collections.Generic;
using System.Collections.Specialized;

namespace createsend_dotnet
{
public class Account : CreateSendBase
{
public Account(AuthenticationDetails auth) : base(auth) { }

public string GetPrimaryContact()
{
return HttpGet<PersonResult>("/primarycontact.json", null)
.EmailAddress;
}

public string SetPrimaryContact(string emailAddress)
{
return HttpPut<string, PersonResult>("/primarycontact.json",
new NameValueCollection { { "email", emailAddress } }, null)
.EmailAddress;
}

public IEnumerable<AdministratorDetails> Administrators()
{
return HttpGet<IEnumerable<AdministratorDetails>>(
"/admins.json", null);
}
}
}
35 changes: 35 additions & 0 deletions createsend-netstandard/Administrator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Collections.Specialized;

namespace createsend_dotnet
{
public class Administrator : CreateSendBase
{
private string AdminsUrl { get { return string.Format("/admins.json"); } }

public Administrator(AuthenticationDetails auth) : base(auth) { }

public AdministratorDetails Details(string emailAddress)
{
return HttpGet<AdministratorDetails>(
AdminsUrl, new NameValueCollection {{"email", emailAddress}});
}

public string Add(AdministratorDetails admin)
{
return HttpPost<AdministratorDetails, AdministratorResult>(
AdminsUrl, null, admin).EmailAddress;
}

public string Update(string emailAddress, AdministratorDetails admin)
{
return HttpPut<AdministratorDetails, AdministratorResult>(
AdminsUrl, new NameValueCollection {{ "email", emailAddress }},
admin).EmailAddress;
}

public void Delete(string emailAddress)
{
HttpDelete(AdminsUrl, new NameValueCollection {{"email", emailAddress}});
}
}
}
82 changes: 82 additions & 0 deletions createsend-netstandard/AuthenticationDetails.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace createsend_dotnet
{
public abstract class AuthenticationDetails { }

public class OAuthAuthenticationDetails : AuthenticationDetails
{
public string AccessToken { get; set; }
public string RefreshToken { get; set; }

public OAuthAuthenticationDetails(
string accessToken,
string refreshToken)
{
AccessToken = accessToken;
RefreshToken = refreshToken;
}
}

public class ApiKeyAuthenticationDetails : AuthenticationDetails
{
public string ApiKey { get; set; }

public ApiKeyAuthenticationDetails(string apiKey)
{
ApiKey = apiKey;
}
}

internal sealed class ClientApiKey : ApiKeyAuthenticationDetails
{
public ClientApiKey(string apiKey) : base(apiKey)
{

}
}

internal sealed class AccountApiKey : ApiKeyAuthenticationDetails, IProvideClientId
{
public string ClientId { get; private set; }
public AccountApiKey(string apiKey, string clientId = null) : base(apiKey)
{
ClientId = clientId;
}
}

internal sealed class OAuthWithClientId : OAuthAuthenticationDetails, IProvideClientId
{
public string ClientId { get; private set; }
public OAuthWithClientId(
string accessToken,
string refreshToken,
string clientId) : base(accessToken, refreshToken)
{
if(clientId == null) throw new ArgumentNullException("clientId");

ClientId = clientId;
}
}

public interface IProvideClientId
{
string ClientId { get; }
}

public class BasicAuthAuthenticationDetails : AuthenticationDetails
{
public string Username { get; set; }
public string Password { get; set; }

public BasicAuthAuthenticationDetails(
string username,
string password)
{
Username = username;
Password = password;
}
}
}
Loading