Sha256: 76349fac9ac1a0affcbdaeab2057702d235b92e738ca234f6c30795749defb6f
Contents?: true
Size: 1.14 KB
Versions: 2
Compression:
Stored size: 1.14 KB
Contents
# frozen_string_literal: true class Zilla::Versions::V20::Executor include Memery attr_reader :scheme, :host def initialize(scheme, host, faraday_config_block:) @scheme = scheme @host = host @faraday_config_block = faraday_config_block || ->(_, _target) {} end def call(endpoint, *args, **params) normalized = endpoint.parameters.normalize!(*args, **params) path = endpoint.path_template.render(*args, **normalized[:path]) response = connection.public_send(endpoint.method, path, **normalized[:query]) validate_response!(endpoint, response) end private memoize def connection Faraday.new("#{scheme}://#{host}") do |f| @faraday_config_block.call(f, :client) f.response :raise_error end end def validate_path_params!(endpoint, params) params.each do |k, v| endpoint.parameters[k].validate!(v) end end def validate_response!(endpoint, response) schema = endpoint.responses[response.status.to_s] parsed_body = JSON.parse(response.body) errors = schema.validate(parsed_body) raise ArgumentError, errors.to_a.to_s if errors.any? parsed_body end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
zilla-0.1.3 | lib/zilla/versions/v20/executor.rb |
zilla-0.1.2 | lib/zilla/versions/v20/executor.rb |