Top Level Namespace

Defined Under Namespace

Modules: LucidHttp

Instance Method Summary collapse

Instance Method Details

#_cleanObject



11
12
13
14
15
# File 'lib/lucid_http.rb', line 11

def _clean
  instance_variables.grep(/@_lucid_http_/).each do |v|
    remove_instance_variable(v)
  end
end

#_setup(url, action: :get, follow: false, form: nil, **opts) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/lucid_http.rb', line 17

def _setup(url, action: :get, follow: false, form: nil, **opts)
  _clean
  @__lucid_http__client = HTTP.persistent("http://localhost:9292")
  if follow
    @__lucid_http__client = @__lucid_http__client.follow
  end
  @__lucid_http__path = @__lucid_http__client.default_options.persistent + url
  @__lucid_http__res = @__lucid_http__client.send(action.to_sym, url, form: form)
end

#bodyObject



27
28
29
# File 'lib/lucid_http.rb', line 27

def body
  @__lucid_http__body ||= response.body.to_s
end

#content_typeObject



35
36
37
# File 'lib/lucid_http.rb', line 35

def content_type
  response.content_type.mime_type
end

#GET(url, **opts) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/lucid_http.rb', line 43

def GET(url, **opts)
  _setup(url, **opts)
  new_body = case status.to_i
             when 200
               body
             when 500
               body.each_line.first
             else
               "ERROR: #{status.to_s}"
             end

  # puts new_body
  new_body
end

#pathObject



39
40
41
# File 'lib/lucid_http.rb', line 39

def path
  @__lucid_http__path
end

#POST(url, **opts) ⇒ Object



58
59
60
61
# File 'lib/lucid_http.rb', line 58

def POST(url, **opts)
  _setup(url, action: :post, **opts)
  body
end

#responseObject



7
8
9
# File 'lib/lucid_http.rb', line 7

def response
  @__lucid_http__res
end

#statusObject



31
32
33
# File 'lib/lucid_http.rb', line 31

def status
  @__lucid_http__status = response.status
end