Skip to content

Commit

Permalink
Added mic_code support
Browse files Browse the repository at this point in the history
  • Loading branch information
soulgarden committed Oct 15, 2022
1 parent 3e715d0 commit b8824c2
Show file tree
Hide file tree
Showing 16 changed files with 80 additions and 156 deletions.
2 changes: 0 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,4 @@ linters:
- exhaustivestruct
- gci
- gofumpt
- nonamedreturns
- exhaustruct

83 changes: 18 additions & 65 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,13 @@ func (c *Cli) GetTimeSeries(
return nil, 0, 0, err
}

errResp, err := c.CheckErrorInResponse(resp)
if err != nil {
// nolint: nestif
if errResp, err := c.CheckErrorInResponse(resp); err != nil {
if errResp != nil && errResp.Code == http.StatusBadRequest {
if strings.Contains(errResp.Message, dictionary.SymbolNotFoundMsg) ||
strings.Contains(errResp.Message, dictionary.NewSymbolNotFoundMsg) {
return nil, creditsLeft, creditsUsed, dictionary.ErrNotFound
}

if strings.Contains(errResp.Message, dictionary.IsNotAvailableWithYourPlanMsg) {
} else if strings.Contains(errResp.Message, dictionary.IsNotAvailableWithYourPlanMsg) {
return nil, creditsLeft, creditsUsed, dictionary.ErrIsNotAvailableWithYourPlan
}
}
Expand All @@ -111,10 +109,6 @@ func (c *Cli) GetTimeSeries(
return nil, creditsLeft, creditsUsed, err
}

if errResp.Code == http.StatusNotFound {
return nil, creditsLeft, creditsUsed, dictionary.ErrNotFound
}

if err := json.Unmarshal(resp.Body(), &seriesResp); err != nil {
c.logger.Err(err).Bytes("body", resp.Body()).Msg("unmarshall")

Expand Down Expand Up @@ -143,7 +137,7 @@ func (c *Cli) GetProfile(symbol, exchange, country string) (
return nil, 0, 0, err
}

errResp, err := c.CheckErrorInResponse(resp)
_, err = c.CheckErrorInResponse(resp)
if err != nil {
if !errors.Is(err, dictionary.ErrTooManyRequests) {
c.logger.Err(err).Msg("check error in response")
Expand All @@ -152,10 +146,6 @@ func (c *Cli) GetProfile(symbol, exchange, country string) (
return nil, creditsLeft, creditsUsed, err
}

if errResp.Code == http.StatusNotFound {
return nil, creditsLeft, creditsUsed, dictionary.ErrNotFound
}

if err := json.Unmarshal(resp.Body(), &profileResp); err != nil {
c.logger.Err(err).Bytes("body", resp.Body()).Msg("unmarshall")

Expand Down Expand Up @@ -184,7 +174,7 @@ func (c *Cli) GetInsiderTransactions(symbol, exchange, country string) (
return nil, 0, 0, err
}

errResp, err := c.CheckErrorInResponse(resp)
_, err = c.CheckErrorInResponse(resp)
if err != nil {
if !errors.Is(err, dictionary.ErrTooManyRequests) {
c.logger.Err(err).Msg("check error in response")
Expand All @@ -193,10 +183,6 @@ func (c *Cli) GetInsiderTransactions(symbol, exchange, country string) (
return nil, creditsLeft, creditsUsed, err
}

if errResp.Code == http.StatusNotFound {
return nil, creditsLeft, creditsUsed, dictionary.ErrNotFound
}

if err := json.Unmarshal(resp.Body(), &insiderTransactionsResp); err != nil {
c.logger.Err(err).Bytes("body", resp.Body()).Msg("unmarshall")

Expand Down Expand Up @@ -229,7 +215,7 @@ func (c *Cli) GetDividends(symbol, exchange, country, r, startDate, endDate stri
return nil, 0, 0, err
}

errResp, err := c.CheckErrorInResponse(resp)
_, err = c.CheckErrorInResponse(resp)
if err != nil {
if !errors.Is(err, dictionary.ErrTooManyRequests) {
c.logger.Err(err).Msg("check error in response")
Expand All @@ -238,10 +224,6 @@ func (c *Cli) GetDividends(symbol, exchange, country, r, startDate, endDate stri
return nil, creditsLeft, creditsUsed, err
}

if errResp.Code == http.StatusNotFound {
return nil, creditsLeft, creditsUsed, dictionary.ErrNotFound
}

if err := json.Unmarshal(resp.Body(), &dividendsResp); err != nil {
c.logger.Err(err).Bytes("body", resp.Body()).Msg("unmarshall")

Expand Down Expand Up @@ -270,7 +252,7 @@ func (c *Cli) GetStatistics(symbol, exchange, country string) (
return nil, 0, 0, err
}

errResp, err := c.CheckErrorInResponse(resp)
_, err = c.CheckErrorInResponse(resp)
if err != nil {
if !errors.Is(err, dictionary.ErrTooManyRequests) {
c.logger.Err(err).Msg("check error in response")
Expand All @@ -279,10 +261,6 @@ func (c *Cli) GetStatistics(symbol, exchange, country string) (
return nil, creditsLeft, creditsUsed, err
}

if errResp.Code == http.StatusNotFound {
return nil, creditsLeft, creditsUsed, dictionary.ErrNotFound
}

if err := json.Unmarshal(resp.Body(), &statisticsResp); err != nil {
c.logger.Err(err).Bytes("body", resp.Body()).Msg("unmarshall")

Expand Down Expand Up @@ -449,7 +427,7 @@ func (c *Cli) GetUsage() (
return nil, 0, 0, err
}

errResp, err := c.CheckErrorInResponse(resp)
_, err = c.CheckErrorInResponse(resp)
if err != nil {
if !errors.Is(err, dictionary.ErrTooManyRequests) {
c.logger.Err(err).Msg("check error in response")
Expand All @@ -458,10 +436,6 @@ func (c *Cli) GetUsage() (
return nil, creditsLeft, creditsUsed, err
}

if errResp.Code == http.StatusNotFound {
return nil, creditsLeft, creditsUsed, dictionary.ErrNotFound
}

if err := json.Unmarshal(resp.Body(), &usageResp); err != nil {
c.logger.Err(err).Bytes("body", resp.Body()).Msg("unmarshall")

Expand Down Expand Up @@ -544,10 +518,6 @@ func (c *Cli) GetExchangeRate(
return nil, creditsLeft, creditsUsed, err
}

if errResp.Code == http.StatusNotFound {
return nil, creditsLeft, creditsUsed, dictionary.ErrNotFound
}

if err := json.Unmarshal(resp.Body(), &exchangeRate); err != nil {
c.logger.Err(err).Bytes("body", resp.Body()).Msg("unmarshall")

Expand Down Expand Up @@ -579,7 +549,7 @@ func (c *Cli) GetIncomeStatement(symbol, exchange, country, period, startDate, e
return nil, 0, 0, err
}

errResp, err := c.CheckErrorInResponse(resp)
_, err = c.CheckErrorInResponse(resp)
if err != nil {
if !errors.Is(err, dictionary.ErrTooManyRequests) {
c.logger.Err(err).Msg("check error in response")
Expand All @@ -588,10 +558,6 @@ func (c *Cli) GetIncomeStatement(symbol, exchange, country, period, startDate, e
return nil, creditsLeft, creditsUsed, err
}

if errResp.Code == http.StatusNotFound {
return nil, creditsLeft, creditsUsed, dictionary.ErrNotFound
}

if err := json.Unmarshal(resp.Body(), &incomeStatementResp); err != nil {
c.logger.Err(err).Bytes("body", resp.Body()).Msg("unmarshall")

Expand Down Expand Up @@ -623,7 +589,7 @@ func (c *Cli) GetBalanceSheet(symbol, exchange, country, startDate, endDate, per
return nil, 0, 0, err
}

errResp, err := c.CheckErrorInResponse(resp)
_, err = c.CheckErrorInResponse(resp)
if err != nil {
if !errors.Is(err, dictionary.ErrTooManyRequests) {
c.logger.Err(err).Msg("check error in response")
Expand All @@ -632,10 +598,6 @@ func (c *Cli) GetBalanceSheet(symbol, exchange, country, startDate, endDate, per
return nil, creditsLeft, creditsUsed, err
}

if errResp.Code == http.StatusNotFound {
return nil, creditsLeft, creditsUsed, dictionary.ErrNotFound
}

if err := json.Unmarshal(resp.Body(), &balanceSheetResp); err != nil {
c.logger.Err(err).Bytes("body", resp.Body()).Msg("unmarshall")

Expand Down Expand Up @@ -667,7 +629,7 @@ func (c *Cli) GetCashFlow(symbol, exchange, country, startDate, endDate, period
return nil, 0, 0, err
}

errResp, err := c.CheckErrorInResponse(resp)
_, err = c.CheckErrorInResponse(resp)
if err != nil {
if !errors.Is(err, dictionary.ErrTooManyRequests) {
c.logger.Err(err).Msg("check error in response")
Expand All @@ -676,10 +638,6 @@ func (c *Cli) GetCashFlow(symbol, exchange, country, startDate, endDate, period
return nil, creditsLeft, creditsUsed, err
}

if errResp.Code == http.StatusNotFound {
return nil, creditsLeft, creditsUsed, dictionary.ErrNotFound
}

if err := json.Unmarshal(resp.Body(), &cashFlowResp); err != nil {
c.logger.Err(err).Bytes("body", resp.Body()).Msg("unmarshall")

Expand Down Expand Up @@ -710,7 +668,7 @@ func (c *Cli) GetMarketMovers(instrument, direction string, outputSize int, coun
return nil, 0, 0, err
}

errResp, err := c.CheckErrorInResponse(resp)
_, err = c.CheckErrorInResponse(resp)
if err != nil {
if !errors.Is(err, dictionary.ErrTooManyRequests) {
c.logger.Err(err).Msg("check error in response")
Expand All @@ -719,10 +677,6 @@ func (c *Cli) GetMarketMovers(instrument, direction string, outputSize int, coun
return nil, creditsLeft, creditsUsed, err
}

if errResp.Code == http.StatusNotFound {
return nil, creditsLeft, creditsUsed, dictionary.ErrNotFound
}

if err := json.Unmarshal(resp.Body(), &marketMoversResp); err != nil {
c.logger.Err(err).Bytes("body", resp.Body()).Msg("unmarshall")

Expand Down Expand Up @@ -867,16 +821,15 @@ func (c *Cli) CheckErrorInResponse(resp *fasthttp.Response) (*response.Error, er
return nil, dictionary.ErrUnmarshalResponse
}

if errResp.Code == http.StatusBadRequest {
switch {
case errResp.Code == http.StatusBadRequest:
return errResp, dictionary.ErrInvalidTwelveDataResponse
}

if errResp.Code == http.StatusTooManyRequests {
case errResp.Code == http.StatusTooManyRequests:
return nil, dictionary.ErrTooManyRequests
}

if errResp.Code == http.StatusForbidden {
case errResp.Code == http.StatusForbidden:
return errResp, dictionary.ErrForbidden
case errResp.Code == http.StatusNotFound:
return errResp, dictionary.ErrNotFound
}

return errResp, nil
Expand Down
Loading

0 comments on commit b8824c2

Please sign in to comment.