Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
}
};

await client.SaveContentAsync(generateId: (x) => $"{x.Name}_{x.Address.City}", exampleDataInstance1, exampleDataInstance2, exampleDataInstance3);
await client.SaveContentAsync(generateId: (x) => $"{x.Name}_{x.Address.City}", "en", exampleDataInstance1, exampleDataInstance2, exampleDataInstance3);
#endregion

#region ExampleTypes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public async Task SaveContentAsync_SerializesData_AndCallsGraphClient()
mockRestClient.Setup(c => c.HandleResponse(response));

// Act
await repository.SaveContentAsync(generateId: (x) => x.ToString(), exampleData);
await repository.SaveContentAsync(generateId: (x) => x.ToString(), "en", exampleData);

// Assert
mockRestClient.Verify(c => c.SendAsync(It.Is<HttpRequestMessage>(x => Compare(request, x))), Times.Once);
Expand Down Expand Up @@ -316,7 +316,7 @@ public async Task SaveContentAsync_WithMultipleTypes_ShouldGenerateJsonForConten
mockRestClient.Setup(c => c.HandleResponse(response));

// Act
await repository.SaveContentAsync<object>(generateId, locationStockholm, locationLondon, event1, event2, event3);
await repository.SaveContentAsync<object>(generateId, "en", locationStockholm, locationLondon, event1, event2, event3);

// Assert
Assert.AreEqual(expectedJsonString, jsonString);
Expand Down Expand Up @@ -353,7 +353,7 @@ public async Task CreateContent_ShouldContainTwoNewLines()
};

// Act
var createdContent = repository.CreateContent(generateId: (x) => x.ToString(), exampleData);
var createdContent = repository.CreateContent(generateId: (x) => x.ToString(), "en", exampleData);
var result = createdContent.ReadAsStringAsync().Result;

// Assert
Expand Down Expand Up @@ -387,7 +387,7 @@ public async Task CreateContent_ShouldProduceMinifiedContent()
};

// Act
var createdContent = repository.CreateContent(generateId: (x) => x.ToString(), exampleData);
var createdContent = repository.CreateContent(generateId: (x) => x.ToString(), "en", exampleData);
var result = createdContent.ReadAsStringAsync().Result;

// Assert
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ public async Task<string> SaveTypesAsync()
/// <param name="generateId">Id associated with content.</param>
/// <param name="data">Dynamic data being saved to Content Graph.</param>
/// <returns></returns>
public async Task<string> SaveContentAsync<T>(Func<T, string> generateId, params T[] data)
public async Task<string> SaveContentAsync<T>(Func<T, string> generateId, string language, params T[] data)
where T : class, new()
{
return await repository.SaveContentAsync(generateId, data);
return await repository.SaveContentAsync(generateId, language, data);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ public async Task<string> SaveTypesAsync()
}

/// <inheritdoc/>
public async Task<string> SaveContentAsync<T>(Func<T, string> generateId, params T[] data)
public async Task<string> SaveContentAsync<T>(Func<T, string> generateId, string language, params T[] data)
where T : class, new()
{
var content = CreateContent(generateId, data);
var content = CreateContent(generateId, language, data);

using (var requestMessage = new HttpRequestMessage(HttpMethod.Post, $"{DataUrl}?id={source}"))
{
Expand All @@ -96,7 +96,7 @@ public async Task<string> SaveContentAsync<T>(Func<T, string> generateId, params
return string.Empty;
}

public StringContent CreateContent<T>(Func<T, string> generateId, params T[] data)
public StringContent CreateContent<T>(Func<T, string> generateId, string language, params T[] data)
{
var serializeOptions = new JsonSerializerOptions
{
Expand All @@ -111,7 +111,6 @@ public StringContent CreateContent<T>(Func<T, string> generateId, params T[] dat
foreach (var item in data)
{
var id = generateId(item);
var language = "en";

itemJson += $"{{\"index\":{{\"_id\":\"{id}\",\"language_routing\":\"{language}\"}}}}";
itemJson += Environment.NewLine;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public interface IGraphSourceRepository
/// <param name="generateId">Id associated with content.</param>
/// <param name="data">Dynamic data being saved to Content Graph.</param>
/// <returns></returns>
Task<string> SaveContentAsync<T>(Func<T, string> generateId, params T[] data) where T : class, new();
Task<string> SaveContentAsync<T>(Func<T, string> generateId, string language, params T[] data) where T : class, new();

/// <summary>
/// Removes content previously stored by source.
Expand Down
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ You can find more information https://docs.developers.optimizely.com/platform-op

You can use the client by calling `Create()` and providing your base url, Content Graph source, application key and secret, then calling one of the provided functions for synchronizing Content Types and Content Data.

#### Sync Content Types
```csharp
// Initialize the GraphSourceClient by calling the Create method
var client = GraphSourceClient.Create(new Uri("https://cg.optimizely.com"), "", "", "");
Expand Down Expand Up @@ -57,6 +58,26 @@ client.ConfigurePropertyType<ExampleClassObject.SubType1>()
var result = await graphSourceClient.SaveTypesAsync();
```

#### Sync Content
```csharp
// Instantiate custom C# object and assign values
var exampleData = new ExampleClassObject
{
FirstName = "First",
LastName = "Last",
Age = 30,
SubType = new SubType1
{
One = "One",
Two = 2,
}
};

// Use the client to sync content
// Parameters are generated id, language, and data object
await client.SaveContentAsync(generateId: (x) => $"{x.FirstName}_{x.LastName}", "en", exampleData);
```

## Run Examples
In visual studio, set your startup project to the Optimizely.Graph.Source.Sdk.Sample project.

Expand Down