module KisHttp
All the HTTP things
TLD
TLD
Constants
- VERSION
Public Class Methods
Headers(obj)
click to toggle source
# File lib/kis_http/headers.rb, line 72 def self.Headers(obj) if obj.is_a? KisHttp::Headers obj elsif obj.is_a? Hash KisHttp::Headers.new(**obj) elsif obj.is_a? Array KisHttp::Headers.new(**obj.to_h) else raise 'Invalid object type for Headers!' end end
delete(url, **kwargs)
click to toggle source
# File lib/kis_http.rb, line 31 def delete(url, **kwargs) request(url, **kwargs) do |uri| Net::HTTP::Delete.new(uri) end end
get(url, **kwargs)
click to toggle source
# File lib/kis_http.rb, line 13 def get(url, **kwargs) request(url, **kwargs) do |uri| Net::HTTP::Get.new(uri) end end
post(url, **kwargs)
click to toggle source
# File lib/kis_http.rb, line 19 def post(url, **kwargs) request(url, **kwargs) do |uri| Net::HTTP::Post.new(uri) end end
put(url, **kwargs)
click to toggle source
# File lib/kis_http.rb, line 25 def put(url, **kwargs) request(url, **kwargs) do |uri| Net::HTTP::Put.new(uri) end end
Private Class Methods
request(url, body: nil, headers: nil, options: nil) { |request_uri| ... }
click to toggle source
# File lib/kis_http.rb, line 39 def request(url, body: nil, headers: nil, options: nil) options = KisHttp.Options(options) if options uri = URI("#{url}#{options}") request = yield uri.request_uri KisHttp.Headers(headers).assign_each_to(request) if headers request.body = body http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = (uri.scheme == 'https') http.request(request) end
Public Instance Methods
parse(other)
click to toggle source
# File lib/kis_http/options.rb, line 124 def parse(other) return other.split('&').map(&split).to_h if other.is_a? String other.map(&split).to_h end
update(other)
click to toggle source
# File lib/kis_http/options.rb, line 130 def update(other) return self unless other build(parse(other)) end