-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
643 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System.Threading.Tasks; | ||
|
||
namespace OpenAlprWebhookProcessor.Alerts | ||
{ | ||
public interface IAlertClient | ||
{ | ||
Task SendAlertAsync(Alert alert); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
OpenAlprWebhookProcessor/Alerts/Pushover/PushoverClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
|
||
namespace OpenAlprWebhookProcessor.Alerts.Pushover | ||
{ | ||
public class PushoverClient : IAlertClient | ||
{ | ||
private const string PushOverApiUrl = "https://api.pushover.net/1/messages.json"; | ||
|
||
private readonly HttpClient _httpClient; | ||
|
||
private readonly PushoverConfiguration _pushoverConfiguration; | ||
|
||
public PushoverClient(PushoverConfiguration pushoverConfiguration) | ||
{ | ||
_pushoverConfiguration = pushoverConfiguration; | ||
_httpClient = new HttpClient(); | ||
} | ||
public async Task SendAlertAsync(Alert alert) | ||
{ | ||
var pushUrl = PushOverApiUrl + $"?token={_pushoverConfiguration.AppToken}&user={_pushoverConfiguration.UserKey}&message={alert.PlateNumber}"; | ||
|
||
await _httpClient.PostAsync(pushUrl, null); | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
OpenAlprWebhookProcessor/Alerts/Pushover/PushoverConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace OpenAlprWebhookProcessor.Alerts.Pushover | ||
{ | ||
public class PushoverConfiguration | ||
{ | ||
public string AppToken { get; set; } | ||
|
||
public string UserKey { get; set; } | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
OpenAlprWebhookProcessor/Alerts/Pushover/UpsertPushoverRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace OpenAlprWebhookProcessor.Alerts.Pushover | ||
{ | ||
public class UpsertPushoverRequest | ||
{ | ||
public bool IsEnabled { get; set; } | ||
|
||
public string UserKey { get; set; } | ||
|
||
public string ApiToken { get; set; } | ||
|
||
public bool SendPlatePreview { get; set; } | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
OpenAlprWebhookProcessor/Alerts/Pushover/UpsertPushoverRequestHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
using OpenAlprWebhookProcessor.Data; | ||
using System.Threading.Tasks; | ||
|
||
namespace OpenAlprWebhookProcessor.Alerts.Pushover | ||
{ | ||
public class UpsertPushoverRequestHandler | ||
{ | ||
private readonly ProcessorContext _processorContext; | ||
|
||
public UpsertPushoverRequestHandler(ProcessorContext processorContext) | ||
{ | ||
_processorContext = processorContext; | ||
} | ||
|
||
public async Task HandleAsync(UpsertPushoverRequest request) | ||
{ | ||
var pushoverClient = await _processorContext.PushoverAlertClients.FirstOrDefaultAsync(); | ||
|
||
bool isAdding = false; | ||
|
||
if (pushoverClient == null) | ||
{ | ||
isAdding = true; | ||
|
||
pushoverClient = new Data.Pushover() | ||
{ | ||
ApiToken = request.ApiToken, | ||
IsEnabled = request.IsEnabled, | ||
SendPlatePreview = request.SendPlatePreview, | ||
UserKey = request.UserKey, | ||
}; | ||
} | ||
else | ||
{ | ||
pushoverClient.ApiToken = request.ApiToken; | ||
pushoverClient.IsEnabled = request.IsEnabled; | ||
pushoverClient.SendPlatePreview = request.SendPlatePreview; | ||
pushoverClient.UserKey = request.UserKey; | ||
} | ||
|
||
if (isAdding) | ||
{ | ||
_processorContext.PushoverAlertClients.Add(pushoverClient); | ||
} | ||
|
||
await _processorContext.SaveChangesAsync(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,6 @@ | |
margin: 0px; | ||
} | ||
|
||
.item { | ||
flex-grow: 1; | ||
margin-top: 15px; | ||
} | ||
|
||
.alert { | ||
background-color: #FFEB3B; | ||
} | ||
|
2 changes: 2 additions & 0 deletions
2
OpenAlprWebhookProcessor/ClientApp/src/app/settings/alerts/alerts.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
OpenAlprWebhookProcessor/ClientApp/src/app/settings/alerts/pushover/pushover.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<div style="margin:16px;" fxLayout="row wrap" fxLayout="row wrap" fxLayoutGap=20px> | ||
<mat-card> | ||
<mat-card-header style="justify-content: space-between;"> | ||
<mat-card-title>Pushover</mat-card-title> | ||
<mat-card-subtitle>https://pushover.net/</mat-card-subtitle> | ||
<mat-slide-toggle | ||
style="padding-top: 10px;" | ||
[(ngModel)]="isEnabled"></mat-slide-toggle> | ||
</mat-card-header> | ||
<mat-card-content *ngIf="isEnabled" [@inOutAnimation]> | ||
<div style="margin:16px;" fxLayout="row wrap" fxLayout="row wrap" fxLayoutGap=20px> | ||
<mat-form-field fxFlex="80"> | ||
<mat-label>User Key</mat-label> | ||
<input matInput [(ngModel)]="userKey"> | ||
<mat-icon matTooltip="The pushover user key, found on the profile page" style="cursor:default" matSuffix>help_center</mat-icon> | ||
</mat-form-field> | ||
<mat-form-field fxFlex="80"> | ||
<mat-label>API Token</mat-label> | ||
<input matInput [(ngModel)]="apiToken"> | ||
<mat-icon matTooltip="The pushover api token, found under 'Your Applications' on the profile page" style="cursor:default" matSuffix>help_center</mat-icon> | ||
</mat-form-field> | ||
<div> | ||
<mat-checkbox [(ngModel)]="sendPlatePreviewEnabled">Send Plate Preview Image</mat-checkbox> | ||
</div> | ||
</div> | ||
</mat-card-content> | ||
<mat-card-actions align="end" *ngIf="isEnabled" [@inOutAnimation]> | ||
<button mat-button>Save</button> | ||
</mat-card-actions> | ||
</mat-card> | ||
</div> |
Empty file.
25 changes: 25 additions & 0 deletions
25
...lprWebhookProcessor/ClientApp/src/app/settings/alerts/pushover/pushover.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { PushoverComponent } from './pushover.component'; | ||
|
||
describe('PushoverComponent', () => { | ||
let component: PushoverComponent; | ||
let fixture: ComponentFixture<PushoverComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [ PushoverComponent ] | ||
}) | ||
.compileComponents(); | ||
}); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(PushoverComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
35 changes: 35 additions & 0 deletions
35
OpenAlprWebhookProcessor/ClientApp/src/app/settings/alerts/pushover/pushover.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { animate, style, transition, trigger } from '@angular/animations'; | ||
import { Component, OnInit } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'app-pushover', | ||
templateUrl: './pushover.component.html', | ||
styleUrls: ['./pushover.component.less'], | ||
animations: [ | ||
trigger( | ||
'inOutAnimation', | ||
[ | ||
transition( | ||
':enter', [ | ||
style({ height: 0, opacity: 0 }), | ||
animate('225ms cubic-bezier(0.4, 0.0, 0.2, 1)', | ||
style({ height: '*', opacity: 1 }))]), | ||
transition( | ||
':leave', [ | ||
style({ height: '*', opacity: 1 }), | ||
animate('225ms cubic-bezier(0.4, 0.0, 0.2, 1)', | ||
style({ height: 0, opacity: 0 }))]) | ||
])] | ||
}) | ||
export class PushoverComponent implements OnInit { | ||
public isEnabled: string; | ||
public userKey: string; | ||
public apiToken: string; | ||
public sendPlatePreviewEnabled: boolean; | ||
|
||
constructor() { } | ||
|
||
ngOnInit(): void { | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
OpenAlprWebhookProcessor/ClientApp/src/app/settings/alerts/pushover/pushover.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { PushoverService } from './pushover.service'; | ||
|
||
describe('PushoverService', () => { | ||
let service: PushoverService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
service = TestBed.inject(PushoverService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
20 changes: 20 additions & 0 deletions
20
OpenAlprWebhookProcessor/ClientApp/src/app/settings/alerts/pushover/pushover.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { HttpClient } from '@angular/common/http'; | ||
import { Injectable } from '@angular/core'; | ||
import { Forward } from '@app/settings/forwards/forward'; | ||
import { Pushover } from './pushover'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class PushoverService { | ||
|
||
constructor(private http: HttpClient) { } | ||
|
||
public upsertPushover(pushover: Pushover) { | ||
return this.http.post('/alerts/pushover', pushover); | ||
} | ||
|
||
public getPushover() { | ||
return this.http.get('/alerts/pushover'); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
OpenAlprWebhookProcessor/ClientApp/src/app/settings/alerts/pushover/pushover.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export class Pushover { | ||
apiToken: string; | ||
userKey: string; | ||
isEnabled: boolean; | ||
sendPlatePreview: boolean; | ||
|
||
constructor(init?:Partial<Pushover>) { | ||
Object.assign(this, init); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.