Added abstraction layer to move out config

This commit is contained in:
Marvin Scham
2023-06-28 02:56:54 +02:00
parent 187db7e6f5
commit 0613e261e1
2 changed files with 110 additions and 0 deletions

View File

@@ -0,0 +1,55 @@
package de.rwu.easydrop.api.client;
import javax.naming.ConfigurationException;
import de.rwu.easydrop.util.Config;
/**
* Factory for Buyer API accessors.
*
* @since 0.3.0
*/
public class PurchaserFactory {
/**
* The data source config.
*/
private Config config;
/**
* @param newConfig the config to set
*/
public void setConfig(final Config newConfig) throws ConfigurationException {
this.config = newConfig;
this.config.loadConfig();
}
/**
* @param newConfig
*/
public PurchaserFactory(final Config newConfig) throws ConfigurationException {
this.setConfig(newConfig);
}
/**
* Creates an Amazon purchaser.
*
* @return AmazonPurchaser
*/
public AmazonPurchaser createAmazonPurchaser() {
String apiUrl = config.getProperty("AMAZON_API_URL");
String apiKey = config.getProperty("AMAZON_API_KEY");
return new AmazonPurchaser(apiUrl, apiKey);
}
/**
* Creates an eBay purchaser.
*
* @return EbayPurchaser
*/
public EbayPurchaser createEbayPurchaser() {
String apiUrl = config.getProperty("EBAY_API_URL");
String apiKey = config.getProperty("EBAY_API_KEY");
return new EbayPurchaser(apiUrl, apiKey);
}
}

View File

@@ -0,0 +1,55 @@
package de.rwu.easydrop.api.client;
import javax.naming.ConfigurationException;
import de.rwu.easydrop.util.Config;
/**
* Factory for Sales API accessors.
*
* @since 0.3.0
*/
public class SellerFactory {
/**
* The data source config.
*/
private Config config;
/**
* @param newConfig the config to set
*/
public void setConfig(final Config newConfig) throws ConfigurationException {
this.config = newConfig;
this.config.loadConfig();
}
/**
* @param newConfig
*/
public SellerFactory(final Config newConfig) throws ConfigurationException {
this.setConfig(newConfig);
}
/**
* Creates an Amazon Seller.
*
* @return AmazonSeller
*/
public AmazonSeller createAmazonSeller() {
String apiUrl = config.getProperty("AMAZON_API_URL");
String apiKey = config.getProperty("AMAZON_API_KEY");
return new AmazonSeller(apiUrl, apiKey);
}
/**
* Creates an eBay Seller.
*
* @return EbaySeller
*/
public EbaySeller createEbaySeller() {
String apiUrl = config.getProperty("EBAY_API_URL");
String apiKey = config.getProperty("EBAY_API_KEY");
return new EbaySeller(apiUrl, apiKey);
}
}