Class: Zold::Http

Inherits:
Object
  • Object
show all
Defined in:
lib/zold/http.rb

Overview

Http page

Constant Summary collapse

SCORE_HEADER =
'X-Zold-Score'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(uri, score = Score::ZERO) ⇒ Http

Returns a new instance of Http.



35
36
37
38
# File 'lib/zold/http.rb', line 35

def initialize(uri, score = Score::ZERO)
  @uri = uri
  @score = score
end

Instance Method Details

#getObject



40
41
42
43
44
45
46
# File 'lib/zold/http.rb', line 40

def get
  http = Net::HTTP.new(@uri.host, @uri.port)
  http.read_timeout = 5
  return http.request_get(@uri.path, headers)
rescue StandardError => e
  return Net::HTTPServerError.new('1.1', '599', e.message)
end

#put(body) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/zold/http.rb', line 48

def put(body)
  http = Net::HTTP.new(@uri.host, @uri.port)
  http.read_timeout = 60
  return http.request_put(
    @uri.path, body,
    headers.merge(
      'Content-Type': 'text/plain',
      'Content-Length': body.length.to_s
    )
  )
rescue StandardError => e
  return Net::HTTPServerError.new('1.1', '599', e.message)
end