Module: Linzer::HTTP
- Extended by:
- HTTP
- Included in:
- HTTP
- Defined in:
- lib/linzer/http.rb,
lib/linzer/http/bootstrap.rb,
lib/linzer/http/signature_feature.rb
Overview
Simple HTTP client with automatic request signing.
This module provides convenience methods for making signed HTTP requests using Net::HTTP. It automatically signs outgoing requests with the provided key.
For each standard HTTP method (GET, POST, PUT, DELETE, etc.), a corresponding method is dynamically defined.
Defined Under Namespace
Modules: Bootstrap Classes: SignatureFeature
Class Method Summary collapse
-
.known_http_methods ⇒ Array<String>
Returns the list of known HTTP methods from Net::HTTP.
-
.register_adapter ⇒ Object
private
Registers the HTTP gem request adapter.
Instance Method Summary collapse
-
#get(uri, options) ⇒ Net::HTTPResponse
Makes a signed GET request.
-
#post(uri, options) ⇒ Net::HTTPResponse
Makes a signed POST request.
Class Method Details
.known_http_methods ⇒ Array<String>
Returns the list of known HTTP methods from Net::HTTP.
38 39 40 41 42 43 44 45 |
# File 'lib/linzer/http.rb', line 38 def self.known_http_methods Net::HTTP .constants .map { |const| Net::HTTP.const_get(const) } .select { |klass| klass.is_a?(Class) && klass.const_defined?(:METHOD) } .map { |klass| klass::METHOD } .freeze end |
.register_adapter ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Registers the HTTP gem request adapter.
10 11 12 13 14 |
# File 'lib/linzer/http/signature_feature.rb', line 10 def register_adapter request_class = ::HTTP::Request adapter_class = Linzer::Message::Adapter::HTTPGem::Request Linzer::Message.register_adapter(request_class, adapter_class) end |
Instance Method Details
#get(uri, options) ⇒ Net::HTTPResponse
Makes a signed GET request.
70 71 72 73 74 75 76 |
# File 'lib/linzer/http.rb', line 70 known_http_methods.each do |http_method| # e.g.: method = http_method.downcase.to_sym # define_method(method) do |uri, | # def post(uri, **options) ||= {} # request :post, uri, options request method, uri, # end end end |
#post(uri, options) ⇒ Net::HTTPResponse
Makes a signed POST request.
70 71 72 73 74 75 76 |
# File 'lib/linzer/http.rb', line 70 known_http_methods.each do |http_method| # e.g.: method = http_method.downcase.to_sym # define_method(method) do |uri, | # def post(uri, **options) ||= {} # request :post, uri, options request method, uri, # end end end |