add endpointUrl to NetworkRequestFactory

This commit is contained in:
Inhji 2023-06-10 08:35:23 +02:00
parent c0e995819b
commit c6bb750c92
2 changed files with 21 additions and 7 deletions

View File

@ -36,9 +36,11 @@ export class MicroPluginContainer implements MicroPluginContainerInterface {
) {
this.settings = settings
this.plugin = plugin
this.networkRequestFactory = new NetworkRequestFactory()
this.networkClient = new NetworkClient(() => {
return this.settings.appToken
})
this.networkRequestFactory = new NetworkRequestFactory(
() => this.settings.micropubEndpoint
)
this.networkClient = new NetworkClient(
() => this.settings.appToken
)
}
}

View File

@ -30,6 +30,18 @@ export interface NetworkRequestFactoryInterface {
*/
export class NetworkRequestFactory implements NetworkRequestFactoryInterface {
// Properties
private endpointUrl: () => string
// Life cycle
constructor(
endpointUrl: () => string,
) {
this.endpointUrl = endpointUrl
}
// Public
public makePublishRequest(
@ -65,7 +77,7 @@ export class NetworkRequestFactory implements NetworkRequestFactoryInterface {
})
return {
path: '/micropub',
url: this.endpointUrl(),
parameters: parameters,
method: 'POST'
}
@ -73,7 +85,7 @@ export class NetworkRequestFactory implements NetworkRequestFactoryInterface {
public makeConfigRequest(): NetworkRequest {
return {
path: '/micropub',
url: this.endpointUrl(),
parameters: new URLSearchParams([
['q', 'config']
]),
@ -83,7 +95,7 @@ export class NetworkRequestFactory implements NetworkRequestFactoryInterface {
public makeCategoriesRequest(): NetworkRequest {
return {
path: '/micropub',
url: this.endpointUrl(),
parameters: new URLSearchParams([
['q', 'category']
]),