Sha256: 106a256528315735da53d14aef4dffb1dc40799136dae697166c8ee5c1c61f7f

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

require "lucid_http/version"
require "http"
require "lucid_http/followers"
require "lucid_http/formatters"
require "lucid_http/response"

module LucidHttp
  class Client
    attr_reader :base_url

    def initialize(base_url:)
      @base_url = base_url
    end

    %i[get post put patch delete options].each do |verb|
      define_method(verb.upcase) do |path, formatter: :plain, follower: :no_follow, form: {}|
        do_verb(
          verb: verb, path: path,
          formatter: formatter, follower: follower,
          form: form,
        )
      end
    end

    def do_verb(verb:, path:, formatter:, follower:, form:)
      LucidHttp::Response.new(
        base_url: base_url, path: path, verb: verb,
        formatter: formatter, follower: follower,
        form: form,
      )
    end
  end
end

%i[get post put patch delete options].each do |verb|
  define_method(verb.upcase) do |path, formatter: :plain, follower: :no_follow, form: {}|
    @__response = LucidHttp::Client.new(base_url: "http://localhost:9292").do_verb(
      verb: verb, path: path,
      formatter: formatter, follower: follower,
      form: form,
    )
  end
end

def body
  @__response.body
end

def verb
  @__response.verb
end

def status
  @__response.status
end

def content_type
  @__response.content_type
end

def url
  @__response.url
end

def path
  @__response.path
end

def error
  @__response.error
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lucid_http-1.0.0 lib/lucid_http.rb