Skip to content

Commit

Permalink
add appropriate function for getting data
Browse files Browse the repository at this point in the history
  • Loading branch information
BinarySoftware committed Jun 24, 2019
1 parent b0ed3c3 commit a4478f6
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions Main.scala
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
import scala.io.Source

object Main {
def getDataFromURLWithSymbols(urlString: String, symbols: Array[String]) : String = {
val stringOfSymbols = symbols.mkString(",")
val concatenatedURL = urlString.concat(stringOfSymbols)

try {
Source.fromURL(concatenatedURL).mkString
}
catch {
case _ : Throwable => "An error has occurred"
}
}

def main(args: Array[String]) : Unit = {
val stocksAPIURL = "https://ws-api.iextrading.com/1.0/tops/last?symbols="
val symbols = Array("AAPL","SNAP","FB")
val combinedURL = stocksAPIURL.concat(symbols.mkString(","))


println(combinedURL)
val stocksData = getDataFromURLWithSymbols(stocksAPIURL, symbols)

val stocksData = Source.fromURL(combinedURL).mkString
println(stocksData)
}
}

0 comments on commit a4478f6

Please sign in to comment.