class FoucaultHttp::Net
Public Class Methods
basic_auth_header()
click to toggle source
(a -> a) -> Hash @param c [String] : Client or user @param s [String] : secret or password @return [Hash{Symbol=>String}]
# File lib/foucault_http/net.rb, line 61 def basic_auth_header -> c, s { { authorization: ("Basic " + Base64::strict_encode64("#{c}:#{s}")).chomp } }.curry end
bearer_token_header()
click to toggle source
# File lib/foucault_http/net.rb, line 52 def bearer_token_header -> token { { authorization: "Bearer #{token}"} } end
decode_basic_auth()
click to toggle source
# File lib/foucault_http/net.rb, line 67 def decode_basic_auth -> encoded_auth { result = Try { Base64::strict_decode64(encoded_auth.split(/\s+/).last) } case result.success? when true Try { result.value_or.split(":") } else result end } end
delete()
click to toggle source
# File lib/foucault_http/net.rb, line 19 def delete -> correlation, service, resource, hdrs { HttpPort.delete.(correlation, service, resource, hdrs) }.curry end
get()
click to toggle source
@param service String @param resource String @param hdrs [] @param enc String @param query @return Result(NetResponseValue
) Example > get.(@env, “/userinfo”, {authorization: “Bearer <token> }, :url_encoded, {} )
# File lib/foucault_http/net.rb, line 33 def get -> correlation, service, resource, opts, hdrs, enc, query { HttpPort.get.(correlation, service, resource, opts, hdrs, enc, query) }.curry end
header_builder()
click to toggle source
@param Array @return [Hash{Symbol=>String}]
# File lib/foucault_http/net.rb, line 81 def header_builder -> *hdrs { Fn.inject.({}).(Fn.merge).(hdrs) } end
json_body_fn()
click to toggle source
# File lib/foucault_http/net.rb, line 85 def json_body_fn -> body { JSON.generate(body) } end
post()
click to toggle source
Client interface
# File lib/foucault_http/net.rb, line 13 def post -> correlation, service, resource, opts, hdrs, enc, body_fn, body { HttpPort.post.(correlation, service, resource, opts, hdrs, body_fn, enc, body) }.curry end
retryer()
click to toggle source
That is, not a circuit breaker @param fn(Llambda) : A partially applied fn @param args : The function's arguments as either an array or hash @param retries(Integer) : The max number of retries
# File lib/foucault_http/net.rb, line 43 def retryer -> fn, args, retries { result = fn.(*args) return result if result.success? return result if retries == 0 retryer.(fn, args, retries - 1) }.curry end