Module: Fizzy
- Defined in:
- lib/fizzy.rb,
lib/fizzy/http.rb,
lib/fizzy/cache.rb,
lib/fizzy/hooks.rb,
lib/fizzy/client.rb,
lib/fizzy/config.rb,
lib/fizzy/errors.rb,
lib/fizzy/version.rb,
lib/fizzy/bulkhead.rb,
lib/fizzy/security.rb,
lib/fizzy/noop_hooks.rb,
lib/fizzy/resilience.rb,
lib/fizzy/chain_hooks.rb,
lib/fizzy/cookie_auth.rb,
lib/fizzy/logger_hooks.rb,
lib/fizzy/rate_limiter.rb,
lib/fizzy/request_info.rb,
lib/fizzy/auth_strategy.rb,
lib/fizzy/operation_info.rb,
lib/fizzy/request_result.rb,
lib/fizzy/token_provider.rb,
lib/fizzy/circuit_breaker.rb,
lib/fizzy/generated/types.rb,
lib/fizzy/magic_link_flow.rb,
lib/fizzy/webhooks/verify.rb,
lib/fizzy/services/base_service.rb,
lib/fizzy/static_token_provider.rb,
lib/fizzy/generated/services/pins_service.rb,
lib/fizzy/generated/services/tags_service.rb,
lib/fizzy/generated/services/cards_service.rb,
lib/fizzy/generated/services/steps_service.rb,
lib/fizzy/generated/services/users_service.rb,
lib/fizzy/generated/services/boards_service.rb,
lib/fizzy/generated/services/columns_service.rb,
lib/fizzy/generated/services/devices_service.rb,
lib/fizzy/generated/services/uploads_service.rb,
lib/fizzy/generated/services/comments_service.rb,
lib/fizzy/generated/services/identity_service.rb,
lib/fizzy/generated/services/sessions_service.rb,
lib/fizzy/generated/services/webhooks_service.rb,
lib/fizzy/generated/services/reactions_service.rb,
lib/fizzy/generated/services/miscellaneous_service.rb,
lib/fizzy/generated/services/notifications_service.rb
Overview
These types provide structured access to API response data. Each type is a Data.define (Ruby 3.2+) with keyword initialization.
Defined Under Namespace
Modules: AuthStrategy, ErrorCode, ExitCode, Hooks, Security, Services, TokenProvider, Types, Webhooks Classes: APIError, AmbiguousError, AuthError, BearerAuth, Bulkhead, Cache, ChainHooks, CircuitBreaker, Client, Config, CookieAuth, Error, ForbiddenError, Http, LoggerHooks, MagicLinkFlow, NetworkError, NoopHooks, NotFoundError, OperationInfo, OperationResult, RateLimitError, RateLimiter, RequestInfo, RequestResult, ResilienceConfig, Response, StaticTokenProvider, UsageError, ValidationError
Constant Summary collapse
- VERSION =
"0.1.3"- API_VERSION =
"2026-03-01"
Class Method Summary collapse
-
.client(access_token: nil, auth: nil, base_url: Config::DEFAULT_BASE_URL, hooks: nil) ⇒ Client
Creates a new Fizzy client.
-
.error_from_response(status, body = nil, retry_after: nil) ⇒ Error
Maps an HTTP response to the appropriate error class.
-
.parse_error_message(body) ⇒ String?
Parses error message from response body.
Class Method Details
.client(access_token: nil, auth: nil, base_url: Config::DEFAULT_BASE_URL, hooks: nil) ⇒ Client
Creates a new Fizzy client.
This is a convenience method that creates a Client with the given options.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/fizzy.rb', line 77 def self.client( access_token: nil, auth: nil, base_url: Config::DEFAULT_BASE_URL, hooks: nil ) raise ArgumentError, "provide either access_token or auth, not both" if access_token && auth raise ArgumentError, "provide access_token or auth" if !access_token && !auth config = Config.new(base_url: base_url) if auth Client.new(config: config, auth_strategy: auth, hooks: hooks) else token_provider = StaticTokenProvider.new(access_token) Client.new(config: config, token_provider: token_provider, hooks: hooks) end end |
.error_from_response(status, body = nil, retry_after: nil) ⇒ Error
Maps an HTTP response to the appropriate error class.
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
# File 'lib/fizzy/errors.rb', line 252 def self.error_from_response(status, body = nil, retry_after: nil) = (body) || "Request failed" case status when 400, 422 ValidationError.new(, http_status: status) when 401 AuthError.new() when 403 ForbiddenError.new() when 404 NotFoundError.new("Resource", "unknown") when 429 RateLimitError.new(retry_after: retry_after) when 500 APIError.new("Server error (500)", http_status: 500, retryable: true) when 502, 503, 504 APIError.new("Gateway error (#{status})", http_status: status, retryable: true) else APIError.from_status(status, ) end end |
.parse_error_message(body) ⇒ String?
Parses error message from response body.
278 279 280 281 282 283 284 285 286 287 288 289 290 |
# File 'lib/fizzy/errors.rb', line 278 def self.(body) return nil if body.nil? || body.empty? # Guard against oversized error bodies before parsing Fizzy::Security.check_body_size!(body, Fizzy::Security::MAX_ERROR_BODY_BYTES, "Error") data = JSON.parse(body) msg = data["error"] || data["message"] msg ? Fizzy::Security.truncate(msg) : nil rescue JSON::ParserError, Fizzy::APIError # Return nil on parse errors or oversized bodies to preserve normal error type mapping nil end |