Class: FoucaultHttp::Net
- Inherits:
-
Object
- Object
- FoucaultHttp::Net
- Extended by:
- Dry::Monads::Try::Mixin
- Defined in:
- lib/foucault_http/net.rb
Class Method Summary collapse
-
.basic_auth_header ⇒ Hash{Symbol=>String}
(a -> a) -> Hash.
- .bearer_token_header ⇒ Object
- .decode_basic_auth ⇒ Object
- .delete ⇒ Object
-
.get ⇒ Object
Example > get.(@env, “/userinfo”, {authorization: “Bearer <token> }, :url_encoded, {} ).
- .header_builder ⇒ Hash{Symbol=>String}
- .json_body_fn ⇒ Object
-
.post ⇒ Object
Client interface.
-
.retryer ⇒ Object
That is, not a circuit breaker.
Class Method Details
.basic_auth_header ⇒ Hash{Symbol=>String}
(a -> a) -> Hash
61 62 63 64 65 |
# 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 ⇒ Object
52 53 54 55 56 |
# File 'lib/foucault_http/net.rb', line 52 def bearer_token_header -> token { { authorization: "Bearer #{token}"} } end |
.decode_basic_auth ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 |
# 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 ⇒ Object
19 20 21 22 23 |
# File 'lib/foucault_http/net.rb', line 19 def delete -> correlation, service, resource, hdrs { HttpPort.delete.(correlation, service, resource, hdrs) }.curry end |
.get ⇒ Object
Example > get.(@env, “/userinfo”, {authorization: “Bearer <token> }, :url_encoded, {} )
33 34 35 36 37 |
# 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 ⇒ Hash{Symbol=>String}
81 82 83 |
# File 'lib/foucault_http/net.rb', line 81 def header_builder -> *hdrs { Fn.inject.({}).(Fn.merge).(hdrs) } end |
.json_body_fn ⇒ Object
85 86 87 |
# File 'lib/foucault_http/net.rb', line 85 def json_body_fn -> body { JSON.generate(body) } end |
.post ⇒ Object
Client interface
13 14 15 16 17 |
# 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 ⇒ Object
That is, not a circuit breaker
43 44 45 46 47 48 49 50 |
# 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 |