Class: SharedBroker::SchemaRegistry::Providers::Http
- Inherits:
-
Object
- Object
- SharedBroker::SchemaRegistry::Providers::Http
- Defined in:
- lib/shared_broker/schema_registry/providers/http.rb
Instance Method Summary collapse
- #clear_cache ⇒ Object
-
#initialize(url:, headers: {}, cache_ttl: 300) ⇒ Http
constructor
A new instance of Http.
- #validate!(topic, payload) ⇒ Object
Constructor Details
#initialize(url:, headers: {}, cache_ttl: 300) ⇒ Http
Returns a new instance of Http.
11 12 13 14 15 16 |
# File 'lib/shared_broker/schema_registry/providers/http.rb', line 11 def initialize(url:, headers: {}, cache_ttl: 300) @base_url = url.chomp("/") @headers = headers @cache_ttl = cache_ttl @cache = {} end |
Instance Method Details
#clear_cache ⇒ Object
30 31 32 |
# File 'lib/shared_broker/schema_registry/providers/http.rb', line 30 def clear_cache @cache.clear end |
#validate!(topic, payload) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/shared_broker/schema_registry/providers/http.rb', line 18 def validate!(topic, payload) schema = fetch_schema(topic) return unless schema begin JSON::Validator.validate!(schema, payload) rescue JSON::Schema::ValidationError => e raise SharedBroker::Validation::ValidationError, "Schema validation failed for topic #{topic.inspect} against schema #{schema.inspect}. Offending payload: #{payload.inspect}. Error: #{e.}" end end |