Skip to content

Commit 9c6e92c

Browse files
committed
Made things public, readme fixes, Renamed Driver -> CloudCMSDriver
1 parent 8e5d27f commit 9c6e92c

21 files changed

+70
-78
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ The [Cloud CMS](https://www.cloudcms.com/) C# driver is a .NET core client libra
77
Command Line:
88

99
````
10-
dotnet add cloudcms
10+
dotnet add package cloudcms
1111
````
1212

1313
Visual Studio:
@@ -18,7 +18,7 @@ Install-Package cloudcms
1818

1919
## Connecting to Cloud CMS
2020

21-
To connect to Cloud CMS, use the static `CloudCMS.ConnectAsync` method. This takes either a file path to a `gitana.json` file, a JObject json object, dictionary, or ConnectionObject.
21+
To connect to Cloud CMS, use the static `CloudCMSDriver.ConnectAsync` method. This takes either a file path to a `gitana.json` file, a JObject json object, dictionary, or ConnectionObject.
2222

2323
The required API key properties for this are:
2424

@@ -32,16 +32,16 @@ Connection examples:
3232

3333
````csharp
3434
string path = "gitana.json";
35-
IPlatform platform1 = await CloudCMS.ConnectAsync(path);
35+
IPlatform platform1 = await CloudCMSDriver.ConnectAsync(path);
3636

3737
JObject configObj = ...;
38-
IPlatform platform2 = await CloudCMS.ConnectAsync(configObj);
38+
IPlatform platform2 = await CloudCMSDriver.ConnectAsync(configObj);
3939

4040
IDictionary<string, string> configDict = ...;
41-
IPlatform platform3 = await CloudCMS.ConnectAsync(configDict);
41+
IPlatform platform3 = await CloudCMSDriver.ConnectAsync(configDict);
4242

4343
ConnectionConfig config = ...;
44-
IPlatform platform4 = await CloudCMS.ConnectAsync(config);
44+
IPlatform platform4 = await CloudCMSDriver.ConnectAsync(config);
4545
````
4646

4747
## Examples
@@ -51,7 +51,7 @@ Below are some examples of how you might use this driver:
5151
````csharp
5252
// Connect to Cloud CMS
5353
string path = "gitana.json";
54-
IPlatform platform = await CloudCMS.ConnectAsync(path);
54+
IPlatform platform = await CloudCMSDriver.ConnectAsync(path);
5555

5656
// Read repository
5757
IRepository repository = await platform.ReadRepositoryAsync("<repositoryId>");

cloudcms-csharp-driver.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
<RootNamespace>CloudCMS</RootNamespace>
77

88
<PackageId>cloudcms</PackageId>
9-
<PackageVersion>1.0.0</PackageVersion>
9+
<PackageVersion>1.0.2</PackageVersion>
1010
<Title>CloudCMS Driver</Title>
1111
<Description>C# .NET driver for CloudCMS</Description>
1212
<Summary>C# .NET driver for CloudCMS</Summary>
1313
<PackageTags>cloudcms;cms;</PackageTags>
14-
<Authors>cloudcms</Authors>
14+
<Authors>Michael Whitman</Authors>
1515
<RepositoryUrl>https://github.com/gitana/cloudcms-csharp-driver</RepositoryUrl>
1616
<PackageIconUrl>https://github.com/gitana/cloudcms-csharp-driver/blob/master/icon.png?raw=true</PackageIconUrl>
1717
<PackageLicenseFile>LICENSE</PackageLicenseFile>

src/CloudCMS.cs

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/Driver.cs renamed to src/CloudCMSDriver.cs

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,53 @@
1313

1414
namespace CloudCMS
1515
{
16-
class Driver
16+
public class CloudCMSDriver
1717
{
18+
// Static connection methods
19+
20+
public static async Task<IPlatform> ConnectAsync(string configPath)
21+
{
22+
using (StreamReader file = File.OpenText(configPath))
23+
using (JsonTextReader reader = new JsonTextReader(file))
24+
{
25+
JObject json = (JObject)JToken.ReadFrom(reader);
26+
ConnectionConfig config = json.ToObject<ConnectionConfig>();
27+
28+
return await ConnectAsync(config);
29+
}
30+
}
31+
32+
public static async Task<IPlatform> ConnectAsync(IDictionary<string, string> configDict)
33+
{
34+
JObject configObject = JObject.FromObject(configDict);
35+
return await ConnectAsync(configObject);
36+
}
37+
38+
public static async Task<IPlatform> ConnectAsync(JObject configObject)
39+
{
40+
ConnectionConfig config = configObject.ToObject<ConnectionConfig>();
41+
return await ConnectAsync(config);
42+
}
43+
44+
public static async Task<IPlatform> ConnectAsync(ConnectionConfig config)
45+
{
46+
CloudCMSDriver driver = new CloudCMSDriver();
47+
return await driver.doConnectAsync(config);
48+
}
49+
50+
// Instance methods
51+
1852
private static string TOKEN_URI = "/oauth/token";
1953

2054
private ConnectionConfig Config;
21-
private Token token;
55+
private OAuthToken token;
2256

23-
public Driver()
57+
protected CloudCMSDriver()
2458
{
2559

2660
}
2761

28-
public async Task<IPlatform> ConnectAsync(ConnectionConfig config)
62+
private async Task<IPlatform> doConnectAsync(ConnectionConfig config)
2963
{
3064
if (config.clientKey == null)
3165
{
@@ -47,7 +81,7 @@ public async Task<IPlatform> ConnectAsync(ConnectionConfig config)
4781
{
4882
throw new OAuthException("Missing required config property baseURL");
4983
}
50-
84+
5185
this.Config = config;
5286
await GetTokenAsync();
5387
return await ReadPlatformAsync();
@@ -152,7 +186,7 @@ private async Task GetTokenAsync()
152186
HttpResponseMessage response = await client.PostAsync(Config.baseURL + TOKEN_URI, requestBody);
153187
string responseBody = await response.Content.ReadAsStringAsync();
154188

155-
token = JsonConvert.DeserializeObject<Token>(responseBody);
189+
token = JsonConvert.DeserializeObject<OAuthToken>(responseBody);
156190
token.expireTime = DateTime.UtcNow.AddSeconds(token.expires_in);
157191
}
158192
}
@@ -175,7 +209,7 @@ private async Task RefreshTokenAsync()
175209
HttpResponseMessage response = await client.PostAsync(Config.baseURL + TOKEN_URI, requestBody);
176210
string responseBody = await response.Content.ReadAsStringAsync();
177211

178-
token = JsonConvert.DeserializeObject<Token>(responseBody);
212+
token = JsonConvert.DeserializeObject<OAuthToken>(responseBody);
179213
token.expireTime = DateTime.UtcNow.AddSeconds(token.expires_in);
180214
}
181215
}

src/ConnectionConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace CloudCMS
22
{
3-
class ConnectionConfig
3+
public class ConnectionConfig
44
{
55
public string clientKey { get; set; }
66
public string clientSecret { get; set; }

src/Token.cs renamed to src/OAuthToken.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace CloudCMS
44
{
5-
class Token
5+
public class OAuthToken
66
{
77
public string access_token { get; set; }
88
public string refresh_token { get; set; }

src/branches/Branch.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace CloudCMS.Branches
1010
{
11-
class Branch : AbstractRepositoryDocument,
11+
public class Branch : AbstractRepositoryDocument,
1212
IBranch
1313
{
1414
public Branch(IRepository repository, JObject obj) : base(repository, obj)

src/branches/IBranch.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace CloudCMS.Branches
88
{
9-
interface IBranch : IRepositoryDocument
9+
public interface IBranch : IRepositoryDocument
1010
{
1111
Task<INode> ReadNodeAsync(string nodeId);
1212

src/documents/AbstractDocument.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44

55
namespace CloudCMS.Documents
66
{
7-
abstract class AbstractDocument : IDocument
7+
public abstract class AbstractDocument : IDocument
88
{
99
public string Id { get; set; }
1010

1111
public JObject Data { get; set; }
1212

1313
public abstract string URI { get; }
1414

15-
public Driver Driver { get; }
15+
public CloudCMSDriver Driver { get; }
1616

17-
protected AbstractDocument(Driver driver, JObject obj)
17+
protected AbstractDocument(CloudCMSDriver driver, JObject obj)
1818
{
1919
this.Driver = driver;
2020
this.Id = obj.GetValue("_doc").ToString();

src/documents/IDocument.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33

44
namespace CloudCMS.Documents
55
{
6-
interface IDocument
6+
public interface IDocument
77
{
88
string Id { get; set; }
99

1010
JObject Data { get; set; }
1111

12-
Driver Driver { get; }
12+
CloudCMSDriver Driver { get; }
1313

1414
string URI { get; }
1515

0 commit comments

Comments
 (0)