Skip to content

Commit

Permalink
migrate to tito
Browse files Browse the repository at this point in the history
  • Loading branch information
mzaatar committed Mar 28, 2019
1 parent a08e0dc commit aa9b048
Show file tree
Hide file tree
Showing 16 changed files with 170 additions and 160 deletions.
4 changes: 2 additions & 2 deletions DDD.Core/DDD.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="WindowsAzure.Storage" Version="8.6.0" />
<PackageReference Include="Polly" Version="5.9.0" />
<PackageReference Include="WindowsAzure.Storage" Version="9.3.3" />
<PackageReference Include="Polly" Version="7.0.3" />
</ItemGroup>

</Project>
19 changes: 0 additions & 19 deletions DDD.Core/Eventbrite/EventbriteOrder.cs

This file was deleted.

20 changes: 20 additions & 0 deletions DDD.Core/Tito/TitoOrder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

using Microsoft.WindowsAzure.Storage.Table;

namespace DDD.Core.Tito
{
public class TitoOrder : TableEntity
{
public TitoOrder()
{
}

public TitoOrder(string conferenceInstance, string orderNumber)
{
PartitionKey = conferenceInstance;
RowKey = orderNumber;
}

public string OrderId => RowKey;
}
}
2 changes: 1 addition & 1 deletion DDD.Functions.Extensions/DDD.Functions.Extensions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="microsoft.net.sdk.functions" Version="1.0.22" />
<PackageReference Include="microsoft.net.sdk.functions" Version="1.0.26" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions DDD.Functions.Extensions/KeyDatesConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ public class KeyDatesConfig : Attribute
public string StopSyncingAppInsightsFrom { get; set; }
public DateTimeOffset StopSyncingAppInsightsFromDate => StopSyncingAppInsightsFrom != null ? DateTimeOffset.Parse(StopSyncingAppInsightsFrom) : DateTimeOffset.MinValue;

// Eventbrite Sync
[AppSetting(Default = "StopSyncingEventbriteFrom")]
public string StopSyncingEventbriteFrom { get; set; }
public DateTimeOffset StopSyncingEventbriteFromDate => StopSyncingEventbriteFrom != null ? DateTimeOffset.Parse(StopSyncingEventbriteFrom) : DateTimeOffset.MinValue;
// Tito Sync
[AppSetting(Default = "StopSyncingTitoFrom")]
public string StopSyncingTitoFrom { get; set; }
public DateTimeOffset StopSyncingTitoFromDate => StopSyncingTitoFrom != null ? DateTimeOffset.Parse(StopSyncingTitoFrom) : DateTimeOffset.MinValue;

public bool Before(Func<KeyDatesConfig, DateTimeOffset> date, TimeSpan? tolerance = null)
{
Expand Down
6 changes: 3 additions & 3 deletions DDD.Functions.Extensions/SessionData.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Threading.Tasks;
using DDD.Core.AppInsights;
using DDD.Core.AzureStorage;
using DDD.Core.Eventbrite;
using DDD.Core.Tito;
using DDD.Core.Voting;
using Microsoft.WindowsAzure.Storage;

Expand All @@ -26,9 +26,9 @@ public static async Task<ITableStorageRepository<NotifiedSessionEntity>> GetRepo
return GetSessionRepositoryAsync(config.ConnectionString, config.SessionsTable, config.PresentersTable);
}

public static async Task<ITableStorageRepository<EventbriteOrder>> GetRepositoryAsync(this EventbriteSyncConfig config)
public static async Task<ITableStorageRepository<TitoOrder>> GetRepositoryAsync(this TitoSyncConfig config)
{
var repo = new TableStorageRepository<EventbriteOrder>(CloudStorageAccount.Parse(config.ConnectionString), config.Table);
var repo = new TableStorageRepository<TitoOrder>(CloudStorageAccount.Parse(config.ConnectionString), config.Table);
await repo.InitializeAsync();
return repo;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,34 @@

namespace DDD.Functions.Extensions
{
public class EventbriteSyncConfig : Attribute
public class TitoSyncConfig : Attribute
{
[AppSetting(Default = "VotesConnectionString")]
public string ConnectionString { get; set; }
[AppSetting(Default = "EventbriteTable")]
[AppSetting(Default = "TitoTable")]
public string Table { get; set; }
[AppSetting(Default = "EventbriteApiBearerToken")]
[AppSetting(Default = "TitoApiBearerToken")]
public string ApiKey { get; set; }
[AppSetting(Default = "EventbriteEventId")]
[AppSetting(Default = "TitoEventId")]
public string EventId { get; set; }
[AppSetting(Default = "TitoAccountId")]
public string AccountId { get; set; }
}

[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.ReturnValue)]
[Binding]
public class BindEventbriteSyncConfigAttribute : EventbriteSyncConfig { }
public class BindTitoSyncConfigAttribute : TitoSyncConfig { }

public class BindEventbriteSyncConfigExtension : IExtensionConfigProvider
public class BindTitoSyncConfigExtension : IExtensionConfigProvider
{
public void Initialize(ExtensionConfigContext context)
{
var rule = context.AddBindingRule<BindEventbriteSyncConfigAttribute>();
var rule = context.AddBindingRule<BindTitoSyncConfigAttribute>();

rule.BindToInput(BuildItemFromAttr);
}

private EventbriteSyncConfig BuildItemFromAttr(BindEventbriteSyncConfigAttribute attr)
private TitoSyncConfig BuildItemFromAttr(BindTitoSyncConfigAttribute attr)
{
return attr;
}
Expand Down
6 changes: 3 additions & 3 deletions DDD.Functions/DDD.Functions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.22" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.26" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DDD.Functions.Extensions\DDD.Functions.Extensions.csproj" />
Expand All @@ -17,10 +17,10 @@
<None Update="node_modules\**\*.*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="EventbriteNotification\function.json">
<None Update="TitoNotification\function.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="EventbriteNotification\index.js">
<None Update="TitoNotification\index.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="host.json">
Expand Down
84 changes: 0 additions & 84 deletions DDD.Functions/EventbriteSync.cs

This file was deleted.

14 changes: 7 additions & 7 deletions DDD.Functions/GetVotes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public static async Task<IActionResult> Run(
SubmissionsConfig submissions,
[BindVotingConfig]
VotingConfig voting,
[BindEventbriteSyncConfig]
EventbriteSyncConfig eventbrite,
[BindTitoSyncConfig]
TitoSyncConfig titoSyncConfig,
[BindAppInsightsSyncConfig]
AppInsightsSyncConfig appInsights)
{
Expand All @@ -42,17 +42,17 @@ public static async Task<IActionResult> Run(
var votingRepo = await voting.GetRepositoryAsync();
var votes = await votingRepo.GetAllAsync(conference.ConferenceInstance);

// Get Eventbrite ids
var ebRepo = await eventbrite.GetRepositoryAsync();
var eventbriteOrders = await ebRepo.GetAllAsync(conference.ConferenceInstance);
var eventbriteIds = eventbriteOrders.Select(o => o.OrderId).ToArray();
// Get Tito ids
var titoRebo = await titoSyncConfig.GetRepositoryAsync();
var titoOrders = await titoRebo.GetAllAsync(conference.ConferenceInstance);
var titoIds = titoOrders.Select(o => o.OrderId).ToArray();

// Get AppInsights sessions
var aiRepo = await appInsights.GetRepositoryAsync();
var userSessions = await aiRepo.GetAllAsync(conference.ConferenceInstance);

// Analyse votes
var analysedVotes = votes.Select(v => new AnalysedVote(v, votes, eventbriteIds, userSessions)).ToArray();
var analysedVotes = votes.Select(v => new AnalysedVote(v, votes, titoIds, userSessions)).ToArray();

// Get summary
var sessions = receivedSubmissions.Select(x => x.GetSession())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ function deDupeWebhookRequest(payload, log, successAction, duplicateAction, erro
errorAction();
}
});


}

function preventWebhookRequestDuplication(payload, log, successAction, errorAction) {
Expand Down Expand Up @@ -57,7 +55,7 @@ module.exports = function (context, req) {
}

var deDupePayload = {
webhook: "eventbrite",
webhook: "tito",
action: req.body.config.action,
id: req.body.api_url
};
Expand All @@ -68,23 +66,20 @@ module.exports = function (context, req) {
return;
}

var orderUrl = req.body.api_url + "?expand=attendees,event,attendees.ticket_class";
var bearer = process.env["EventbriteApiBearerToken"]
request.get(orderUrl, {auth: {bearer: bearer}}, function(error, response, body) {
var orderUrl = req.body.api_url;
var token = process.env["TitoApiBearerToken"]
request.get(orderUrl, {auth: {token: `token=${token}`}}, function(error, response, body) {

try {

var bodyAsJson = JSON.parse(body);

if (response && response.statusCode && response.statusCode === 200) {
var attendees = bodyAsJson.attendees.map(function(attendee) {
var attendees = bodyAsJson.tickets.map(function(ticket) {
return {
name: attendee.profile.name,
name: ticket.name,
event: bodyAsJson.event.name.text,
ticketClass: attendee.ticket_class_name,
qtySold: attendee.ticket_class.quantity_sold,
totalQty: attendee.ticket_class.quantity_total,
orderId: attendee.order_id
orderId: tickets.registration_id
};
});
context.log("Attendee(s):", attendees);
Expand All @@ -98,7 +93,7 @@ module.exports = function (context, req) {
});

} else {
context.log("ERROR calling EventBrite: (", response.statusCode, ") ", body);
context.log("ERROR calling Tito: (", response.statusCode, ") ", body);
end(500);
}
} catch (e) {
Expand All @@ -120,9 +115,9 @@ Test using:
{
action: 'order.placed',
user_id: '141671750594',
endpoint_url: 'https://dddperth-eventbritewebhook.azurewebsites.net/api/HttpTriggerJS1?code=...',
endpoint_url: 'https://dddperth-titowebhook.azurewebsites.net/api/HttpTriggerJS1?code=...',
webhook_id: '438789'
},
api_url: 'https://www.eventbriteapi.com/v3/orders/650520140/'
api_url: 'https://api.tito.io/v3/:account_slug/:event_slug/registrations/:registration_slug'
}
*/
Loading

0 comments on commit aa9b048

Please sign in to comment.