Skip to content

Commit

Permalink
Changes into bridge registration
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalii-bezuhlyi committed Mar 20, 2024
1 parent 6f812ee commit f5df082
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Apps.Lionbridge/Api/LionbridgeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected override Exception ConfigureErrorException(RestResponse response)
}
catch (Exception e)
{
return new Exception($"Error was thrown while executing request, response content: {response.Content}; status code: {response.StatusCode}");
return new Exception($"Error was thrown while executing request, response content: {response.Content}; status code: {response.StatusCode}; Exception message: {e.Message}");
}
}

Expand Down
23 changes: 19 additions & 4 deletions Apps.Lionbridge/Webhooks/Handlers/BaseWebhookHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public async Task SubscribeAsync(IEnumerable<AuthenticationCredentialsProvider>
}

var bridge = new BridgeService(authenticationCredentialsProviders, _bridgeServiceUrl);
bridge.Subscribe(GetEventType(), listener.ListenerId, values["payloadUrl"]);
string eventType = GetEventType();
bridge.Subscribe(eventType, listener.ListenerId, values["payloadUrl"]);
}

public async Task UnsubscribeAsync(IEnumerable<AuthenticationCredentialsProvider> authenticationCredentialsProviders,
Expand All @@ -46,7 +47,8 @@ public async Task UnsubscribeAsync(IEnumerable<AuthenticationCredentialsProvider
if (listener != null)
{
var bridge = new BridgeService(authenticationCredentialsProviders, _bridgeServiceUrl);
bridge.Unsubscribe(GetEventType(), listener.ListenerId, values["payloadUrl"]);
string eventType = GetEventType();
bridge.Unsubscribe(eventType, listener.ListenerId, values["payloadUrl"]);
await DeleteListenerAsync(listener.ListenerId);
}
}
Expand Down Expand Up @@ -82,6 +84,19 @@ private async Task DeleteListenerAsync(string listenerId)
}

protected abstract string[] GetStatusCodes();

protected abstract string GetEventType();

private string GetEventType()
{
if(SubscriptionEvent.Contains("JOB"))
{
return "JOB_UPDATE";
}

if(SubscriptionEvent.Contains("REQUEST"))
{
return "REQUEST_UPDATE";
}

throw new Exception("Invalid event type");
}
}
5 changes: 0 additions & 5 deletions Apps.Lionbridge/Webhooks/Handlers/JobStatusUpdatedHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,4 @@ protected override string[] GetStatusCodes()
{
return ["IN_TRANSLATION", "CANCELLED", "SENT_TO_PROVIDER"];
}

protected override string GetEventType()
{
return "JOB_UPDATE";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,4 @@ protected override string[] GetStatusCodes()
{
return new[] { "IN_TRANSLATION", "CANCELLED", "REVIEW_TRANSLATION" };
}

protected override string GetEventType()
{
return "REQUEST_UPDATE";
}
}

0 comments on commit f5df082

Please sign in to comment.