From 5ec89ac1af73f40cdd237fb761f5ad02e6177416 Mon Sep 17 00:00:00 2001 From: programmingPug <36635276+programmingPug@users.noreply.github.com> Date: Tue, 11 Sep 2018 15:25:41 -0400 Subject: [PATCH] More cleaning... --- src/app/_services/emitcom.service.ts | 5 +++++ src/app/_services/nasdaq-search.service.ts | 9 ++++++++- src/app/_services/stock.service.ts | 22 ++++++++++++++++++---- src/app/_services/watcher.service.ts | 7 ++++--- src/index.html | 5 ++++- 5 files changed, 39 insertions(+), 9 deletions(-) diff --git a/src/app/_services/emitcom.service.ts b/src/app/_services/emitcom.service.ts index 34a57bf..9087fad 100644 --- a/src/app/_services/emitcom.service.ts +++ b/src/app/_services/emitcom.service.ts @@ -5,6 +5,11 @@ export class EmitcomService { @Output() change: EventEmitter = 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) { let sendData = { type: "ipo", diff --git a/src/app/_services/nasdaq-search.service.ts b/src/app/_services/nasdaq-search.service.ts index 58a9acc..795cf00 100644 --- a/src/app/_services/nasdaq-search.service.ts +++ b/src/app/_services/nasdaq-search.service.ts @@ -1,12 +1,19 @@ import { Injectable } from '@angular/core'; import { HttpClient, HttpHeaders } from '@angular/common/http'; - 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({ providedIn: 'root' }) export class NasdaqSearchService { + + /* URL to the mock DB to be intercepted by the web-api in memory data service */ private loginUrl = "api/nasdaq"; constructor( diff --git a/src/app/_services/stock.service.ts b/src/app/_services/stock.service.ts index da66726..f17353f 100644 --- a/src/app/_services/stock.service.ts +++ b/src/app/_services/stock.service.ts @@ -12,6 +12,8 @@ const httpOptions = { }) export class StockService { + private baseUrl = "https://api.iextrading.com/1.0/stock/"; + constructor( private http: HttpClient, private jsonp: Jsonp @@ -19,6 +21,7 @@ export class StockService { getLogos(symbols) { + /* Before we can get the logos we need to turn the data into comma delimited string */ var symbolsComma = ""; 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) .map(logos => { + /* return just the responce body we don't need anything else */ return logos["_body"]; }); } getCharByTime(symbol, timeFrame) { - const url2 = "https://api.iextrading.com/1.0/stock/" + symbol + "/chart/1m?callback=JSONP_CALLBACK"; - return this.jsonp.request(url2) + const url = this.baseUrl + symbol + "/chart/1m?callback=JSONP_CALLBACK"; + return this.jsonp.request(url) .map(chartData => { + /* return just the responce body we don't need anything else */ return chartData["_body"]; }); } getIpoBulkData(symbols) { + + /* Before we can get the logos we need to turn the data into comma delimited string */ var symbolsComma = ""; 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) .map(logos => { + /* return just the responce body we don't need anything else */ return logos["_body"]; }); } diff --git a/src/app/_services/watcher.service.ts b/src/app/_services/watcher.service.ts index 4d1cbb6..3f09bba 100644 --- a/src/app/_services/watcher.service.ts +++ b/src/app/_services/watcher.service.ts @@ -1,6 +1,5 @@ import { Injectable } from '@angular/core'; import { HttpClient, HttpHeaders } from '@angular/common/http'; - import 'rxjs/add/operator/map'; @Injectable({ @@ -8,9 +7,9 @@ import 'rxjs/add/operator/map'; }) - export class WatcherService { + /* URL to the mock DB to be intercepted by the web-api in memory data service */ private apiUrl = "api/watching/"; constructor( @@ -18,7 +17,7 @@ export class WatcherService { ) { } - +/* Simple method to return all data within the mock DB */ getWatching() { const url = this.apiUrl return this.http.get(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) { let newWatchingSymbol = { 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) { let apiUrl = "api/watching/" + id; const httpOptions = { diff --git a/src/index.html b/src/index.html index 5109875..c804351 100644 --- a/src/index.html +++ b/src/index.html @@ -1,5 +1,6 @@ + Waters @@ -8,7 +9,9 @@ + - + + \ No newline at end of file