Class: RequestVia::Client
- Inherits:
-
Object
- Object
- RequestVia::Client
- Defined in:
- lib/request_via/client.rb
Constant Summary collapse
- BuildURL =
Freeze.(-> (address, path) { "#{address}#{path.start_with?('/') ? path : "/#{path}"}" }.curry)
- BuildAddress =
-> (uri, address) { has_port = uri.port && address =~ /:\d+/ Freeze.(%{#{uri.scheme}://#{uri.host}#{":#{uri.port}" if has_port}}.chomp('/')) }
- OptionsBuilder =
Freeze.(-> net_http { -> () { { params: [:params], headers: [:headers], net_http: net_http } } })
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
Returns the value of attribute address.
-
#net_http ⇒ Object
readonly
Returns the value of attribute net_http.
Class Method Summary collapse
Instance Method Summary collapse
- #delete(path = '/', **options) ⇒ Object
- #get(path = '/', **options) ⇒ Object
- #head(path = '/', **options) ⇒ Object
-
#initialize(address, port, open_timeout, read_timeout) ⇒ Client
constructor
A new instance of Client.
- #options(path = '/', **options) ⇒ Object
- #patch(path = '/', **options) ⇒ Object
- #post(path = '/', **options) ⇒ Object
- #put(path = '/', **options) ⇒ Object
- #trace(path = '/', **options) ⇒ Object
Constructor Details
#initialize(address, port, open_timeout, read_timeout) ⇒ Client
Returns a new instance of Client.
31 32 33 34 35 36 37 38 |
# File 'lib/request_via/client.rb', line 31 def initialize(address, port, open_timeout, read_timeout) uri = Freeze.(Func::ParseURI.(address)) @address = BuildAddress.(uri, address) @build_url = BuildURL.(@address) @net_http = NetHTTP.(uri, port, open_timeout, read_timeout) @options = OptionsBuilder.(@net_http) end |
Instance Attribute Details
#address ⇒ Object (readonly)
Returns the value of attribute address.
6 7 8 |
# File 'lib/request_via/client.rb', line 6 def address @address end |
#net_http ⇒ Object (readonly)
Returns the value of attribute net_http.
6 7 8 |
# File 'lib/request_via/client.rb', line 6 def net_http @net_http end |
Class Method Details
.call(address, port: nil, open_timeout: nil, read_timeout: nil) ⇒ Object
27 28 29 |
# File 'lib/request_via/client.rb', line 27 def self.call(address, port: nil, open_timeout: nil, read_timeout: nil) self.new(address, port, open_timeout, read_timeout) end |
Instance Method Details
#delete(path = '/', **options) ⇒ Object
56 57 58 |
# File 'lib/request_via/client.rb', line 56 def delete(path = '/', **) fetch(RequestVia::Delete, path, ) end |
#get(path = '/', **options) ⇒ Object
40 41 42 |
# File 'lib/request_via/client.rb', line 40 def get(path = '/', **) fetch(RequestVia::Get, path, ) end |
#head(path = '/', **options) ⇒ Object
44 45 46 |
# File 'lib/request_via/client.rb', line 44 def head(path = '/', **) fetch(RequestVia::Head, path, ) end |
#options(path = '/', **options) ⇒ Object
60 61 62 |
# File 'lib/request_via/client.rb', line 60 def (path = '/', **) fetch(RequestVia::Options, path, ) end |
#patch(path = '/', **options) ⇒ Object
68 69 70 |
# File 'lib/request_via/client.rb', line 68 def patch(path = '/', **) fetch(RequestVia::Patch, path, ) end |
#post(path = '/', **options) ⇒ Object
48 49 50 |
# File 'lib/request_via/client.rb', line 48 def post(path = '/', **) fetch(RequestVia::Post, path, ) end |
#put(path = '/', **options) ⇒ Object
52 53 54 |
# File 'lib/request_via/client.rb', line 52 def put(path = '/', **) fetch(RequestVia::Put, path, ) end |
#trace(path = '/', **options) ⇒ Object
64 65 66 |
# File 'lib/request_via/client.rb', line 64 def trace(path = '/', **) fetch(RequestVia::Trace, path, ) end |