Class: BSV::Transaction::ChainTrackers::WhatsOnChain::RawAuthClient

Inherits:
Object
  • Object
show all
Defined in:
lib/bsv/transaction/chain_trackers/whats_on_chain.rb

Overview

Wraps an injectable HTTP client to set a raw Authorization header value before forwarding the request. This preserves the WoC convention of sending the API key without a Bearer prefix.

Instance Method Summary collapse

Constructor Details

#initialize(api_key, inner_client) ⇒ RawAuthClient

Returns a new instance of RawAuthClient.



83
84
85
86
# File 'lib/bsv/transaction/chain_trackers/whats_on_chain.rb', line 83

def initialize(api_key, inner_client)
  @api_key = api_key
  @inner_client = inner_client
end

Instance Method Details

#request(uri, req) ⇒ Object



88
89
90
91
92
93
94
95
96
97
# File 'lib/bsv/transaction/chain_trackers/whats_on_chain.rb', line 88

def request(uri, req)
  req['Authorization'] = @api_key
  if @inner_client
    @inner_client.request(uri, req)
  else
    Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
      http.request(req)
    end
  end
end