Class: ProconBypassMan::HttpClient

Inherits:
Object
  • Object
show all
Defined in:
lib/procon_bypass_man/support/http_client.rb

Defined Under Namespace

Classes: HttpRequest

Instance Method Summary collapse

Constructor Details

#initialize(path:, server:, retry_on_connection_error: false) ⇒ HttpClient

Returns a new instance of HttpClient.



29
30
31
32
33
# File 'lib/procon_bypass_man/support/http_client.rb', line 29

def initialize(path: , server: , retry_on_connection_error: false)
  @server = server
  @uri = URI.parse("#{server}#{path}")
  @retry_on_connection_error = retry_on_connection_error
end

Instance Method Details

#getObject



35
36
37
38
39
40
41
42
43
# File 'lib/procon_bypass_man/support/http_client.rb', line 35

def get
  handle_request do
    ProconBypassMan.logger.info "[HTTP] GET #{@uri}"
    response = HttpRequest::Get.request!(
      uri: @uri,
    )
    break process_response(response)
  end
end

#post(request_body:) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/procon_bypass_man/support/http_client.rb', line 45

def post(request_body: )
  handle_request do
    body = {}.merge!(request_body)
    ProconBypassMan.logger.info "[HTTP] POST #{@uri}"
    response = HttpRequest::Post.request!(
      uri: @uri,
      request_body: body,
    )
    break process_response(response)
  end
end

#put(request_body:) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/procon_bypass_man/support/http_client.rb', line 57

def put(request_body: )
  handle_request do
    body = {
      hostname: `hostname`.chomp,
    }.merge!(request_body)
    ProconBypassMan.logger.info "[HTTP] PUT #{@uri}"
    response = HttpRequest::Put.request!(
      uri: @uri,
      request_body: body,
    )
    break process_response(response)
  end
end