Class: AtlasRb::Transport::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/atlas_rb/transport.rb

Overview

Per-request view onto a shared, cached Faraday connection.

It exists because the state a request needs — the signed assertion (30s TTL), the Idempotency-Key, the query params — used to be baked into the connection at build time, and a connection that outlives the request cannot carry any of it. The proxy holds that state and applies it to each request instead.

The caller-supplied block is forwarded, not swallowed: call sites that need per-request control already use Faraday's block form (a Range header, an on_data streaming handler), and those must keep working. The block runs last so a call site can override anything set here.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, headers, params = {}) ⇒ Proxy

Returns a new instance of Proxy.

Parameters:

  • the shared, cached connection.

  • per-request headers (auth, content type, idempotency key).

  • (defaults to: {})

    per-request query/body params.



107
108
109
110
111
# File 'lib/atlas_rb/transport.rb', line 107

def initialize(connection, headers, params = {})
  @connection = connection
  @headers    = headers
  @params     = params || {}
end

Instance Attribute Details

#connectionObject (readonly)

The shared connection behind this proxy, for reading its middleware stack or adapter. Do not mutate it — it is shared across every request of this shape, including ones in flight on other threads.



101
102
103
# File 'lib/atlas_rb/transport.rb', line 101

def connection
  @connection
end

#headersObject (readonly)

Per-request headers and params, exposed so a caller (and the gem's own transport specs) can read what a request will send without making one.



96
97
98
# File 'lib/atlas_rb/transport.rb', line 96

def headers
  @headers
end

#paramsObject (readonly)

Per-request headers and params, exposed so a caller (and the gem's own transport specs) can read what a request will send without making one.



96
97
98
# File 'lib/atlas_rb/transport.rb', line 96

def params
  @params
end

Instance Method Details

#delete(path, params = nil, headers = nil, &block) ⇒ Object

Bodyless verbs — a second positional argument is query params, matching Faraday::Connection.



117
118
119
120
121
# File 'lib/atlas_rb/transport.rb', line 117

%i[get delete].each do |verb|
  define_method(verb) do |path, params = nil, headers = nil, &block|
    run(verb, path, nil, headers, params, &block)
  end
end

#get(path, params = nil, headers = nil, &block) ⇒ Object

Bodyless verbs — a second positional argument is query params, matching Faraday::Connection.



117
118
119
120
121
# File 'lib/atlas_rb/transport.rb', line 117

%i[get delete].each do |verb|
  define_method(verb) do |path, params = nil, headers = nil, &block|
    run(verb, path, nil, headers, params, &block)
  end
end

#patch(path, body = nil, headers = nil, &block) ⇒ Object

Body-carrying verbs — a second positional argument is the body, matching Faraday::Connection.



128
129
130
131
132
# File 'lib/atlas_rb/transport.rb', line 128

%i[post patch put].each do |verb|
  define_method(verb) do |path, body = nil, headers = nil, &block|
    run(verb, path, body, headers, nil, &block)
  end
end

#post(path, body = nil, headers = nil, &block) ⇒ Object

Body-carrying verbs — a second positional argument is the body, matching Faraday::Connection.



128
129
130
131
132
# File 'lib/atlas_rb/transport.rb', line 128

%i[post patch put].each do |verb|
  define_method(verb) do |path, body = nil, headers = nil, &block|
    run(verb, path, body, headers, nil, &block)
  end
end

#put(path, body = nil, headers = nil, &block) ⇒ Object

Body-carrying verbs — a second positional argument is the body, matching Faraday::Connection.



128
129
130
131
132
# File 'lib/atlas_rb/transport.rb', line 128

%i[post patch put].each do |verb|
  define_method(verb) do |path, body = nil, headers = nil, &block|
    run(verb, path, body, headers, nil, &block)
  end
end

#run_request(method, path, body, headers, &block) ⇒ Faraday::Response

Escape hatch for a verb the five above don't cover, with the same per-request header/param application.

Returns:



138
139
140
# File 'lib/atlas_rb/transport.rb', line 138

def run_request(method, path, body, headers, &block)
  run(method, path, body, headers, nil, &block)
end