Class: SharedBroker::SchemaRegistry::Providers::Http

Inherits:
Object
  • Object
show all
Defined in:
lib/shared_broker/schema_registry/providers/http.rb

Instance Method Summary collapse

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_cacheObject



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.message}"
  end
end