Class: EcfDgii::FrontendClient
- Inherits:
-
Object
- Object
- EcfDgii::FrontendClient
- Defined in:
- lib/ecf_dgii/frontend_client.rb
Overview
A restricted, read-only client that only exposes GET endpoints. Suitable for use in frontend / browser code where write operations should not be available.
Token lifecycle is handled automatically:
-
On each request, checks get_cached_token. If nil, calls get_token then cache_token.
-
On 401 responses, calls get_token again, updates the cache, and retries the request.
Mirrors the TypeScript EcfFrontendClient 1:1.
Constant Summary collapse
- ENVIRONMENT_URLS =
{ test: "https://api.test.ecfx.ssd.com.do", cert: "https://api.cert.ecfx.ssd.com.do", prod: "https://api.prod.ecfx.ssd.com.do" }.freeze
Instance Attribute Summary collapse
-
#api_client ⇒ EcfDgii::Generated::ApiClient
readonly
The underlying generated API client.
-
#environment ⇒ Symbol
readonly
The configured environment.
Instance Method Summary collapse
- #company_api ⇒ Object
-
#ecf_api ⇒ Object
————————————————————————— Base API clients (lazy-loaded) —————————————————————————.
-
#get_companies(opts = {}) ⇒ Object
List companies with optional filters.
-
#get_company_by_rnc(rnc) ⇒ Object
Get a company by RNC.
-
#get_ecf_by_id(rnc, id) ⇒ Object
Get a specific ECF by message ID.
-
#initialize(get_token:, cache_token: nil, get_cached_token: nil, base_url: nil, environment: :test, timeout: 30) ⇒ FrontendClient
constructor
Create a new frontend client.
-
#query_ecf(rnc, encf, opts = {}) ⇒ Object
Query ECFs by RNC and eNCF.
-
#search_all_ecfs(opts = {}) ⇒ Object
Search all ECFs across all companies.
-
#search_ecfs(rnc, opts = {}) ⇒ Object
Search ECFs for a specific RNC.
Constructor Details
#initialize(get_token:, cache_token: nil, get_cached_token: nil, base_url: nil, environment: :test, timeout: 30) ⇒ FrontendClient
Create a new frontend client.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/ecf_dgii/frontend_client.rb', line 48 def initialize(get_token:, cache_token: nil, get_cached_token: nil, base_url: nil, environment: :test, timeout: 30) raise ArgumentError, "get_token is required for EcfDgii::FrontendClient" unless get_token resolved_url = base_url || ENVIRONMENT_URLS[environment.to_sym] raise ArgumentError, "Invalid environment or base URL" if resolved_url.nil? || resolved_url.empty? @get_token = get_token @cache_token = cache_token || method(:default_cache_token) @get_cached_token = get_cached_token || method(:default_get_cached_token) config = EcfDgii::Generated::Configuration.new uri = URI.parse(resolved_url) config.scheme = uri.scheme config.host = uri.host config.base_path = uri.path.empty? ? "" : uri.path config.timeout = timeout @api_client = EcfDgii::Generated::ApiClient.new(config) @environment = environment.to_sym end |
Instance Attribute Details
#api_client ⇒ EcfDgii::Generated::ApiClient (readonly)
Returns The underlying generated API client.
31 32 33 |
# File 'lib/ecf_dgii/frontend_client.rb', line 31 def api_client @api_client end |
#environment ⇒ Symbol (readonly)
Returns The configured environment.
34 35 36 |
# File 'lib/ecf_dgii/frontend_client.rb', line 34 def environment @environment end |
Instance Method Details
#company_api ⇒ Object
79 80 81 |
# File 'lib/ecf_dgii/frontend_client.rb', line 79 def company_api @company_api ||= EcfDgii::Generated::CompanyApi.new(token_api_client) end |
#ecf_api ⇒ Object
Base API clients (lazy-loaded)
75 76 77 |
# File 'lib/ecf_dgii/frontend_client.rb', line 75 def ecf_api @ecf_api ||= EcfDgii::Generated::EcfApi.new(token_api_client) end |
#get_companies(opts = {}) ⇒ Object
List companies with optional filters.
112 113 114 |
# File 'lib/ecf_dgii/frontend_client.rb', line 112 def get_companies(opts = {}) company_api.get_companies(opts) end |
#get_company_by_rnc(rnc) ⇒ Object
Get a company by RNC.
117 118 119 |
# File 'lib/ecf_dgii/frontend_client.rb', line 117 def get_company_by_rnc(rnc) company_api.get_company_by_rnc(rnc) end |
#get_ecf_by_id(rnc, id) ⇒ Object
Get a specific ECF by message ID.
103 104 105 |
# File 'lib/ecf_dgii/frontend_client.rb', line 103 def get_ecf_by_id(rnc, id) ecf_api.get_ecf_by_id(rnc, id) end |
#query_ecf(rnc, encf, opts = {}) ⇒ Object
Query ECFs by RNC and eNCF.
88 89 90 |
# File 'lib/ecf_dgii/frontend_client.rb', line 88 def query_ecf(rnc, encf, opts = {}) ecf_api.query_ecf(rnc, encf, opts) end |
#search_all_ecfs(opts = {}) ⇒ Object
Search all ECFs across all companies.
98 99 100 |
# File 'lib/ecf_dgii/frontend_client.rb', line 98 def search_all_ecfs(opts = {}) ecf_api.search_all_ecfs(opts) end |
#search_ecfs(rnc, opts = {}) ⇒ Object
Search ECFs for a specific RNC.
93 94 95 |
# File 'lib/ecf_dgii/frontend_client.rb', line 93 def search_ecfs(rnc, opts = {}) ecf_api.search_ecfs(rnc, opts) end |