Class: RequestVia::Client

Inherits:
Object
  • Object
show all
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 {
  -> (options) {
    {
      params: options[:params],
      headers: options[:headers],
      net_http: net_http
    }
  }
})

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#addressObject (readonly)

Returns the value of attribute address.



6
7
8
# File 'lib/request_via/client.rb', line 6

def address
  @address
end

#net_httpObject (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 = '/', **options)
  fetch(RequestVia::Delete, path, options)
end

#get(path = '/', **options) ⇒ Object



40
41
42
# File 'lib/request_via/client.rb', line 40

def get(path = '/', **options)
  fetch(RequestVia::Get, path, options)
end

#head(path = '/', **options) ⇒ Object



44
45
46
# File 'lib/request_via/client.rb', line 44

def head(path = '/', **options)
  fetch(RequestVia::Head, path, options)
end

#options(path = '/', **options) ⇒ Object



60
61
62
# File 'lib/request_via/client.rb', line 60

def options(path = '/', **options)
  fetch(RequestVia::Options, path, options)
end

#patch(path = '/', **options) ⇒ Object



68
69
70
# File 'lib/request_via/client.rb', line 68

def patch(path = '/', **options)
  fetch(RequestVia::Patch, path, options)
end

#post(path = '/', **options) ⇒ Object



48
49
50
# File 'lib/request_via/client.rb', line 48

def post(path = '/', **options)
  fetch(RequestVia::Post, path, options)
end

#put(path = '/', **options) ⇒ Object



52
53
54
# File 'lib/request_via/client.rb', line 52

def put(path = '/', **options)
  fetch(RequestVia::Put, path, options)
end

#trace(path = '/', **options) ⇒ Object



64
65
66
# File 'lib/request_via/client.rb', line 64

def trace(path = '/', **options)
  fetch(RequestVia::Trace, path, options)
end