-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* GetInfo use case implemented * GetInfo use case implementation has been fixed, no longer messing up all the import statements of everything. * Documentation for GetInfoInteractor improved as requested
- Loading branch information
Showing
7 changed files
with
104 additions
and
3 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,5 @@ | ||
package use_cases.GetInfo; | ||
|
||
public interface GetInfoInputBoundary { | ||
void execute(GetInfoInputData getInfoInputData); | ||
} |
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 @@ | ||
package use_cases.GetInfo; | ||
|
||
public class GetInfoInputData { | ||
public String ticker; | ||
|
||
public GetInfoInputData(String ticker) { | ||
this.ticker = ticker; | ||
} | ||
|
||
public String getTicker() { | ||
return ticker; | ||
} | ||
} |
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,42 @@ | ||
package use_cases.GetInfo; | ||
|
||
import entities.CompanyInformation; | ||
import use_cases.APIAccessInterface; | ||
|
||
public class GetInfoInteractor implements GetInfoInputBoundary { | ||
GetInfoOutputBoundary getInfoPresenter; | ||
APIAccessInterface driverAPI; | ||
|
||
public GetInfoInteractor(GetInfoOutputBoundary getInfoPresenter, APIAccessInterface driverAPI) { | ||
this.getInfoPresenter = getInfoPresenter; | ||
this.driverAPI = driverAPI; | ||
} | ||
|
||
@Override | ||
public void execute(GetInfoInputData getInfoInputData) { | ||
/** | ||
* <p> | ||
* Info is fetched using the drivers.Finnhub.getCompanyProfile() method, which interacts with the API through | ||
* an OKHTTP client. | ||
* The information in the CompanyInformation object generated by the driver when data is taken from the API is | ||
* transferred into a HashMap through the GetInfoOutputData constructor. | ||
* | ||
* @param getInfoInputData an InputData object containing the ticker of the company whose profile we fetch | ||
*/ | ||
String ticker = getInfoInputData.getTicker(); | ||
|
||
try { | ||
// Make API call | ||
CompanyInformation company_info = driverAPI.getCompanyProfile(ticker); | ||
|
||
// Save API output using OutputData format for the GetNews use case | ||
GetInfoOutputData result = new GetInfoOutputData(ticker, company_info); | ||
|
||
getInfoPresenter.prepareSuccessView(result); | ||
|
||
} catch (RuntimeException e) { | ||
// e.printStackTrace(); | ||
getInfoPresenter.prepareFailView("API call failed."); | ||
} | ||
} | ||
} |
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,7 @@ | ||
package use_cases.GetInfo; | ||
|
||
public interface GetInfoOutputBoundary { | ||
void prepareSuccessView(GetInfoOutputData result); | ||
|
||
void prepareFailView(String error); | ||
} |
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,27 @@ | ||
package use_cases.GetInfo; | ||
|
||
import entities.CompanyInformation; | ||
|
||
import java.util.Map; | ||
import java.util.HashMap; | ||
|
||
public class GetInfoOutputData { | ||
String ticker; | ||
Map<String, String> info_map; | ||
|
||
public GetInfoOutputData(String ticker, CompanyInformation company_info) { | ||
this.ticker = ticker; | ||
|
||
// Initialize info_map attribute, then manually put each attribute to the Map from the CompanyInformation object | ||
this.info_map = new HashMap<String, String>(); | ||
info_map.put("country", company_info.getCountry()); | ||
info_map.put("name", company_info.getName()); | ||
info_map.put("ticker", company_info.getTicker()); | ||
info_map.put("weburl", company_info.getWeburl()); | ||
info_map.put("ipo", company_info.getIpo()); | ||
} | ||
|
||
public String getTicker() {return ticker;} | ||
|
||
public Map<String, String> getInfo() {return info_map;} | ||
} |
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