Sha256: 9a0d0b3db65d815be7a4fe78ffc4d23f15657999de02dc4db90d08c4b3646d2f
Contents?: true
Size: 1.23 KB
Versions: 3
Compression:
Stored size: 1.23 KB
Contents
# typed: strict # frozen_string_literal: true require_relative "client/response" require "httpx" module Httpsensible class Client attr_reader :client def initialize(user_agent: nil) headers = { "content-type" => "application/json", "accept" => "application/json", } if !user_agent.nil? && !user_agent.empty? headers["user-agent"] = user_agent end @client = HTTPX.plugin(:persistent) .plugin(:retries, max_retries: 3) .with_headers(headers) end # TODO: test this def with_plugin(plugin) @client = @client.plugin(plugin) self end # TODO: test this def with_authentication(authentication) @client = @client.authentication(authentication) self end def with_headers(headers) @client = @client.with(headers: headers) self end ["head", "get", "post", "put", "delete", "trace", "options", "connect", "patch"].each do |meth| class_eval(<<-MOD, __FILE__, __LINE__ + 1) def #{meth}(*uri, **options) @last_response = Httpsensible::Client::Response.new(@client.#{meth}(*uri, **options)) # @last_response = @client.get(*uri, **options) end MOD end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
httpsensible-0.2.2 | lib/httpsensible/client.rb |
httpsensible-0.2.1 | lib/httpsensible/client.rb |
httpsensible-0.2.0 | lib/httpsensible/client.rb |