More cleaning...

This commit is contained in:
programmingPug
2018-09-11 15:25:41 -04:00
parent d7f47d245e
commit 5ec89ac1af
5 changed files with 39 additions and 9 deletions

View File

@@ -5,6 +5,11 @@ export class EmitcomService {
@Output() change: EventEmitter<any> = new EventEmitter(); @Output() change: EventEmitter<any> = new EventEmitter();
/*
For communication between components i've used an event emitter service that uses simple JSON objects
I could compact everything into one simple method that accepts an object parameter however I wanted to keep the action
separate incase I wanted to expand on them later.
*/
sendData(data: string) { sendData(data: string) {
let sendData = { let sendData = {
type: "ipo", type: "ipo",

View File

@@ -1,12 +1,19 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http'; import { HttpClient, HttpHeaders } from '@angular/common/http';
import 'rxjs/add/operator/map' import 'rxjs/add/operator/map'
/*
Works much on the same principle as the login service the only difference is we are searching for anything that starts with
the provided string.
*/
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
export class NasdaqSearchService { export class NasdaqSearchService {
/* URL to the mock DB to be intercepted by the web-api in memory data service */
private loginUrl = "api/nasdaq"; private loginUrl = "api/nasdaq";
constructor( constructor(

View File

@@ -12,6 +12,8 @@ const httpOptions = {
}) })
export class StockService { export class StockService {
private baseUrl = "https://api.iextrading.com/1.0/stock/";
constructor( constructor(
private http: HttpClient, private http: HttpClient,
private jsonp: Jsonp private jsonp: Jsonp
@@ -19,6 +21,7 @@ export class StockService {
getLogos(symbols) { getLogos(symbols) {
/* Before we can get the logos we need to turn the data into comma delimited string */
var symbolsComma = ""; var symbolsComma = "";
var commaCheck = false; var commaCheck = false;
@@ -31,23 +34,33 @@ export class StockService {
} }
const url = "https://api.iextrading.com/1.0/stock/market/batch?symbols=" + symbolsComma + "&types=logo&callback=JSONP_CALLBACK"; /*
As we are accessing resources from a 3rd party it is best to use padding with the request
...that and it's required by the API
*/
const url = this.baseUrl + "market/batch?symbols=" + symbolsComma + "&types=logo&callback=JSONP_CALLBACK";
return this.jsonp.request(url) return this.jsonp.request(url)
.map(logos => { .map(logos => {
/* return just the responce body we don't need anything else */
return logos["_body"]; return logos["_body"];
}); });
} }
getCharByTime(symbol, timeFrame) { getCharByTime(symbol, timeFrame) {
const url2 = "https://api.iextrading.com/1.0/stock/" + symbol + "/chart/1m?callback=JSONP_CALLBACK"; const url = this.baseUrl + symbol + "/chart/1m?callback=JSONP_CALLBACK";
return this.jsonp.request(url2) return this.jsonp.request(url)
.map(chartData => { .map(chartData => {
/* return just the responce body we don't need anything else */
return chartData["_body"]; return chartData["_body"];
}); });
} }
getIpoBulkData(symbols) { getIpoBulkData(symbols) {
/* Before we can get the logos we need to turn the data into comma delimited string */
var symbolsComma = ""; var symbolsComma = "";
var commaCheck = false; var commaCheck = false;
@@ -60,9 +73,10 @@ export class StockService {
} }
const url = "https://api.iextrading.com/1.0/stock/market/batch?symbols=" + symbolsComma + "&types=quote,logo&callback=JSONP_CALLBACK"; const url = this.baseUrl + "market/batch?symbols=" + symbolsComma + "&types=quote,logo&callback=JSONP_CALLBACK";
return this.jsonp.request(url) return this.jsonp.request(url)
.map(logos => { .map(logos => {
/* return just the responce body we don't need anything else */
return logos["_body"]; return logos["_body"];
}); });
} }

View File

@@ -1,6 +1,5 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http'; import { HttpClient, HttpHeaders } from '@angular/common/http';
import 'rxjs/add/operator/map'; import 'rxjs/add/operator/map';
@Injectable({ @Injectable({
@@ -8,9 +7,9 @@ import 'rxjs/add/operator/map';
}) })
export class WatcherService { export class WatcherService {
/* URL to the mock DB to be intercepted by the web-api in memory data service */
private apiUrl = "api/watching/"; private apiUrl = "api/watching/";
constructor( constructor(
@@ -18,7 +17,7 @@ export class WatcherService {
) { } ) { }
/* Simple method to return all data within the mock DB */
getWatching() { getWatching() {
const url = this.apiUrl const url = this.apiUrl
return this.http.get<any>(url) return this.http.get<any>(url)
@@ -27,6 +26,7 @@ export class WatcherService {
}); });
} }
/* Add to Mock DB, keep in mind this is only going to work with the current instince */
addWatching(symbol) { addWatching(symbol) {
let newWatchingSymbol = { let newWatchingSymbol = {
symbol: symbol symbol: symbol
@@ -43,6 +43,7 @@ export class WatcherService {
} }
/* Remove from Mock DB, keep in mind this is only going to work with the current instince */
removeFromWatching(id) { removeFromWatching(id) {
let apiUrl = "api/watching/" + id; let apiUrl = "api/watching/" + id;
const httpOptions = { const httpOptions = {

View File

@@ -1,5 +1,6 @@
<!doctype html> <!doctype html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>Waters</title> <title>Waters</title>
@@ -8,7 +9,9 @@
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico"> <link rel="icon" type="image/x-icon" href="favicon.ico">
</head> </head>
<body> <body>
<app-root></app-root> <app-root></app-root>
</body> </body>
</html>
</html>