mirror of
https://github.com/we-promise/sure.git
synced 2026-05-12 07:05:00 +00:00
Merge branch 'main' into copilot/fix-twelvedata-api-limit-bug
Signed-off-by: Juan José Mata <juanjo.mata@gmail.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
class Provider::TwelveData < Provider
|
||||
include ExchangeRateConcept, SecurityConcept
|
||||
extend SslConfigurable
|
||||
|
||||
# Subclass so errors caught in this provider are raised as Provider::TwelveData::Error
|
||||
Error = Class.new(Provider::Error)
|
||||
@@ -7,6 +8,22 @@ class Provider::TwelveData < Provider
|
||||
InvalidSecurityPriceError = Class.new(Error)
|
||||
RateLimitError = Class.new(Error)
|
||||
|
||||
# Pattern to detect plan upgrade errors in API responses
|
||||
PLAN_UPGRADE_PATTERN = /available starting with (\w+)/i
|
||||
|
||||
# Returns true if the error message indicates a plan upgrade is required
|
||||
def self.plan_upgrade_required?(error_message)
|
||||
return false if error_message.blank?
|
||||
PLAN_UPGRADE_PATTERN.match?(error_message)
|
||||
end
|
||||
|
||||
# Extracts the required plan name from an error message, or nil if not found
|
||||
def self.extract_required_plan(error_message)
|
||||
return nil if error_message.blank?
|
||||
match = error_message.match(PLAN_UPGRADE_PATTERN)
|
||||
match ? match[1] : nil
|
||||
end
|
||||
|
||||
def initialize(api_key)
|
||||
@api_key = api_key
|
||||
end
|
||||
@@ -219,7 +236,7 @@ class Provider::TwelveData < Provider
|
||||
end
|
||||
|
||||
def client
|
||||
@client ||= Faraday.new(url: base_url) do |faraday|
|
||||
@client ||= Faraday.new(url: base_url, ssl: self.class.faraday_ssl_options) do |faraday|
|
||||
faraday.request(:retry, {
|
||||
max: 2,
|
||||
interval: 0.05,
|
||||
|
||||
Reference in New Issue
Block a user