class Object

Public Instance Methods

__lucid_http__clean() click to toggle source
# File lib/lucid_http.rb, line 26
def __lucid_http__clean
  instance_variables.grep(/@__lucid_http__/).each do |v|
    remove_instance_variable(v.to_sym)
  end
end
__lucid_http__get_body() click to toggle source
# File lib/lucid_http.rb, line 51
def __lucid_http__get_body
  original_body = response.body.to_s
  if !@__lucid_http__json
    original_body
  else
    JSON.parse(original_body)
  end
end
__lucid_http__setup(url, action: :get, follow: false, form: nil, json: false, **opts) click to toggle source
# File lib/lucid_http.rb, line 32
def __lucid_http__setup(url, action: :get, follow: false, form: nil, json: false, **opts)
  __lucid_http__clean
  @__lucid_http__client = HTTP.persistent(LucidHttp.target_url)
  if json
    @__lucid_http__client = @__lucid_http__client.accept("application/json")
  end
  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)
  @__lucid_http__json = json
end
body() click to toggle source
# File lib/lucid_http.rb, line 47
def body
  @__lucid_http__body ||= __lucid_http__get_body
end
content_type() click to toggle source
# File lib/lucid_http.rb, line 64
def content_type
  response.content_type.mime_type
end
error() click to toggle source
# File lib/lucid_http.rb, line 72
def error
  if status.to_i == 500
    body.split("\n").first
  else
    "No 500 error found."
  end
end
path() click to toggle source
# File lib/lucid_http.rb, line 68
def path
  @__lucid_http__path
end
response() click to toggle source
# File lib/lucid_http.rb, line 22
def response
  @__lucid_http__res
end
status() click to toggle source
# File lib/lucid_http.rb, line 60
def status
  @__lucid_http__status = LucidHttp::PrettyStatus.new(response.status)
end