module Gems
A Ruby wrapper for the RubyGems.org API
Every public method of {API} is a method of this module too, delegated to {.client}: {API::GemEndpoints#rubygem} is ‘Gems.rubygem`, {API::VersionEndpoints#versions} is `Gems.versions`, and so on for every endpoint. They are delegated as the module is loaded rather than written out, so they are not listed among the methods below; {API} groups them into one mixin per topic, and each is documented there.
The raw request methods, {Client#get} and the rest, are on the client rather than on this module, since a request of your own is made with {.client}.
@api public @see API The endpoints, grouped into one mixin per topic
Constants
Public Class Methods
The client the API methods of the module delegate to
The client is built from the global configuration, and a change to that configuration is applied to the client it has rather than building another one, which would throw away what the client learned: the API key a trusted publishing ID token is exchanged for, which RubyGems.org issues once per token. A configured credential is applied through the setter the client has for it, as the user agent and the timeouts are, so that assigning a passcode or a password after a token has been exchanged keeps the key it was exchanged for.
Another client is built only for what a client cannot be given: the host, the ID token, and the fallback resolved for a key that has not been assigned (see {.client_values}).
@api public @return [Client] the client @example Perform a raw request with the module’s client
Gems.client.get("/api/v1/gems/rails.json")
# File lib/gems.rb, line 71 def self.client CLIENT_MUTEX.synchronize do rebuild_client unless client_values.eql?(@client_values) apply_credential_values unless credential_values.eql?(@credential_values) apply_connection_values unless connection_values.eql?(@connection_values) @client end end
Reset the global configuration and forget the client
The client is forgotten as well as the configuration it was built from, so that what it learned from credentials that have been reset, such as the API key an ID token was exchanged for, is not kept. Its connections are closed, since no request of the module will be sent on them again.
The configuration is reset while the client is forgotten rather than afterwards, so that a thread asking for the client is given one built from the configuration as it was or as it has been reset, rather than one built from a configuration that is half of each.
@api public @return [self] @example Reset the configuration
Gems.reset
# File lib/gems.rb, line 94 def self.reset CLIENT_MUTEX.synchronize do @client&.close @client_values = nil super end end