Last active
November 12, 2018 15:19
-
-
Save rubenCodeforges/5c6c62d8d52359ffbad77b47d999fb3e to your computer and use it in GitHub Desktop.
Almost abstract Begging app
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
class BeggingApp { | |
private static readonly defaultMessage = ''; | |
private static readonly reason = 'because its so awesome and i would like to take part at testing it'; | |
private static readonly responseOnSuccess = 'Thank you dear very much for the key !'; | |
private static serviceBag: Collection<Injectable[]>; | |
public static main(param: MainParams): void { | |
const beggar = new Beggar(BeggingApp.serviceBag.getItem(BeggingService)); | |
timer(0, 2000) | |
.pipe( | |
switchMap(() => beggar.begForKeys(param.message || BeggingApp.defaultMessage, BeggingApp.reason)), | |
takeWhile((res) => res.responseMessage !== 'Ok Ok, Here is the key') | |
) | |
.subscribe((response) => { | |
const fs = BeggingApp.serviceBag.getItem(FileSystem); | |
const mailer = BeggingApp.serviceBag.getItem(Mailer); | |
fs.save(response.key); | |
mailer.sendMail(DEVS_EMAIL, BeggingApp.responseOnSuccess); | |
}); | |
} | |
} | |
class Beggar { | |
constructor(private beggingService: BeggingService) { | |
} | |
public begForKeys(requestMessage: string, reason: string): Observable<BeggarResponse> { | |
return this.beggingService.sendRequest({ | |
requestMessage: requestMessage, | |
reason: reason | |
}); | |
} | |
} | |
@Service() | |
class BeggingService { | |
private beggingProtocol; | |
sendRequest(request: BeggarRequest): Observable<BeggarResponse> { | |
return this.beggingProtocol.send(request); | |
} | |
} | |
interface MainParams { | |
message: string; | |
} | |
interface BeggarRequest { | |
requestMessage: string; | |
reason: string; | |
} | |
interface BeggarResponse { | |
responseMessage: string; | |
key?: string; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment