Skip to content

Commit 908be3e

Browse files
committed
Remove double try
1 parent 96157d8 commit 908be3e

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

Sources/AlphaSwiftage/Private/AlphaVantageAPI.swift

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ enum AlphaVantageAPI: URLConvertible {
99
case symbolSearch(keywords: String, apiKey: String)
1010
case dailyAdjustedTimeSeries(symbol: String, apiKey: String)
1111

12+
private var functionName: String {
13+
switch self {
14+
case .globalQuote: "GLOBAL_QUOTE"
15+
case .currencyExchangeRate: "CURRENCY_EXCHANGE_RATE"
16+
case .symbolSearch: "SYMBOL_SEARCH"
17+
case .dailyAdjustedTimeSeries: "TIME_SERIES_DAILY_ADJUSTED"
18+
}
19+
}
20+
1221
fileprivate enum Parameter: String {
1322
case symbol
1423
case apiKey = "apikey"
@@ -23,23 +32,23 @@ enum AlphaVantageAPI: URLConvertible {
2332

2433
switch self {
2534
case .globalQuote(let symbol, let apiKey):
26-
return url.appendingParameter(.function, value: "GLOBAL_QUOTE")
35+
return url.appendingParameter(.function, value: functionName)
2736
.appendingParameter(.symbol, value: symbol)
2837
.appendingParameter(.apiKey, value: apiKey)
2938

3039
case .currencyExchangeRate(let base, let target, let apiKey):
31-
return url.appendingParameter(.function, value: "CURRENCY_EXCHANGE_RATE")
40+
return url.appendingParameter(.function, value: functionName)
3241
.appendingParameter(.fromCurrency, value: base)
3342
.appendingParameter(.toCurrency, value: target)
3443
.appendingParameter(.apiKey, value: apiKey)
3544

3645
case .symbolSearch(let keywords, let apiKey):
37-
return url.appendingParameter(.function, value: "SYMBOL_SEARCH")
46+
return url.appendingParameter(.function, value: functionName)
3847
.appendingParameter(.keywords, value: keywords)
3948
.appendingParameter(.apiKey, value: apiKey)
4049

4150
case .dailyAdjustedTimeSeries(let symbol, let apiKey):
42-
return url.appendingParameter(.function, value: "TIME_SERIES_DAILY_ADJUSTED")
51+
return url.appendingParameter(.function, value: functionName)
4352
.appendingParameter(.symbol, value: symbol)
4453
.appendingParameter(.apiKey, value: apiKey)
4554
}

Sources/AlphaSwiftage/Public/Model/EquityDailyData.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public struct EquityDailyData: Codable, Equatable {
3939
low = try container.decodeUSDecimal(forKey: .low)
4040
close = try container.decodeUSDecimal(forKey: .close)
4141
adjustedClose = try container.decodeUSDecimal(forKey: .adjustedClose)
42-
volume = try try container.decodeUSInt(forKey: .volume)
42+
volume = try container.decodeUSInt(forKey: .volume)
4343
dividendAmount = try container.decodeUSDecimal(forKey: .dividendAmount)
4444
splitCoefficient = try container.decodeUSDecimal(forKey: .splitCoefficient)
4545
}

0 commit comments

Comments
 (0)