Class: Gems::Client
- Inherits:
-
Object
- Object
- Gems::Client
- Extended by:
- Forwardable
- Includes:
- API, ClientCredentials
- Defined in:
- lib/gems/client.rb
Overview
A client for the RubyGems API
Instance Attribute Summary collapse
-
#host ⇒ String
The host for API requests.
Attributes included from ClientCredentials
#id_token, #key, #otp, #password, #username
Class Method Summary collapse
-
.new(**options) {|client| ... } ⇒ Client, Object
Build a client, and close it once a block is done with it.
Instance Method Summary collapse
-
#close ⇒ Client
Close the connections the client keeps open for the next request.
-
#delete(path, params = {}, headers: {}, host: nil) ⇒ String
Perform a DELETE request to the RubyGems API.
-
#get(path, params = {}, headers: {}, host: nil) ⇒ String
Perform a GET request to the RubyGems API.
-
#initialize(host: Gems.host, key: UNSET, username: Gems.username, password: Gems.password, otp: Gems.otp, id_token: Gems.id_token, user_agent: Gems.user_agent, open_timeout: Gems.open_timeout, read_timeout: Gems.read_timeout, write_timeout: Gems.write_timeout, debug_output: Gems.debug_output, proxy_url: Gems.proxy_url, keep_alive_timeout: Gems.keep_alive_timeout, max_redirects: Gems.max_redirects, max_retries: Gems.max_retries, max_retry_delay: Gems.max_retry_delay, ca_file: Gems.ca_file, ca_path: Gems.ca_path, cert_store: Gems.cert_store, client_cert: Gems.client_cert, client_key: Gems.client_key) ⇒ Client
constructor
Initialize a new RubyGems API client.
-
#inspect ⇒ String
Summarize the client for the console.
-
#patch(path, body = {}, content_type: nil, headers: {}, host: nil) ⇒ String
Perform a PATCH request to the RubyGems API.
-
#post(path, body = {}, content_type: nil, headers: {}, host: nil) ⇒ String
Perform a POST request to the RubyGems API.
-
#put(path, body = {}, content_type: nil, headers: {}, host: nil) ⇒ String
Perform a PUT request to the RubyGems API.
Methods included from API::WebHookEndpoints
#add_web_hook, #fire_web_hook, #remove_web_hook, #web_hooks
Methods included from API::VersionEndpoints
#attestations, #contents, #latest_version, #timeframe_versions, #timeframe_versions_each, #version, #versions
Methods included from API::TrustedPublisherEndpoints
#add_trusted_publisher, #remove_trusted_publisher, #trusted_publisher, #trusted_publishers
Methods included from API::ProfileEndpoints
#me, #profile, #webauthn_verification, #webauthn_verification_status
Methods included from API::OwnerEndpoints
#add_owner, #owners, #remove_owner, #update_owner
Methods included from API::GemEndpoints
#autocomplete, #owned_gems, #push, #reverse_dependencies, #reverse_dependency_versions, #rubygem, #search, #search_each, #yank
Methods included from API::DownloadEndpoints
#downloads, #most_downloaded, #total_downloads
Methods included from API::APIKeyEndpoints
#api_key_role, #api_key_roles, #assume_api_key_role, #create_api_key, #exchange_trusted_publisher_token, #oidc_id_token, #oidc_id_tokens, #oidc_provider, #oidc_providers, #update_api_key
Methods included from API::ActivityEndpoints
Constructor Details
#initialize(host: Gems.host, key: UNSET, username: Gems.username, password: Gems.password, otp: Gems.otp, id_token: Gems.id_token, user_agent: Gems.user_agent, open_timeout: Gems.open_timeout, read_timeout: Gems.read_timeout, write_timeout: Gems.write_timeout, debug_output: Gems.debug_output, proxy_url: Gems.proxy_url, keep_alive_timeout: Gems.keep_alive_timeout, max_redirects: Gems.max_redirects, max_retries: Gems.max_retries, max_retry_delay: Gems.max_retry_delay, ca_file: Gems.ca_file, ca_path: Gems.ca_path, cert_store: Gems.cert_store, client_cert: Gems.client_cert, client_key: Gems.client_key) ⇒ Client
Initialize a new RubyGems API client
Every option defaults to the global configuration (see Gems.configure).
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/gems/client.rb', line 115 def initialize(host: Gems.host, key: UNSET, username: Gems.username, password: Gems.password, otp: Gems.otp, id_token: Gems.id_token, user_agent: Gems.user_agent, open_timeout: Gems.open_timeout, read_timeout: Gems.read_timeout, write_timeout: Gems.write_timeout, debug_output: Gems.debug_output, proxy_url: Gems.proxy_url, keep_alive_timeout: Gems.keep_alive_timeout, max_redirects: Gems.max_redirects, max_retries: Gems.max_retries, max_retry_delay: Gems.max_retry_delay, ca_file: Gems.ca_file, ca_path: Gems.ca_path, cert_store: Gems.cert_store, client_cert: Gems.client_cert, client_key: Gems.client_key) @host = validate_host(host) @connection = Connection.new(open_timeout:, read_timeout:, write_timeout:, debug_output:, proxy_url:, keep_alive_timeout:, ca_file:, ca_path:, cert_store:, client_cert:, client_key:) @request_builder = RequestBuilder.new(user_agent:) @redirect_handler = RedirectHandler.new(connection: @connection, request_builder: @request_builder, max_redirects:) @retry_handler = RetryHandler.new(max_retries:, max_retry_delay:) initialize_credentials(key:, username:, password:, otp:, id_token:) initialize_authenticator @response_parser = ResponseParser.new end |
Instance Attribute Details
#host ⇒ String
The host for API requests
32 33 34 |
# File 'lib/gems/client.rb', line 32 def host @host end |
Class Method Details
.new(**options) {|client| ... } ⇒ Client, Object
Build a client, and close it once a block is done with it
Without a block the client is returned, as it is from any other constructor. With one, the client is given to
the block and its connections are closed once the block returns or raises, as Net::HTTP.start closes the
connection it opened, and what the block returns is returned. The client can still be used afterwards, since
a closed client opens its connections again as it needs them.
The options are handed to #initialize, which is what declares them, so they are collected here and named there.
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/gems/client.rb', line 65 def self.new(**) # steep:ignore DifferentMethodParameterKind client = super return client unless block_given? begin yield client ensure client.close end end |
Instance Method Details
#close ⇒ Client
Close the connections the client keeps open for the next request
The connections are opened again as they are needed, so requests can still be made afterwards.
177 178 179 180 |
# File 'lib/gems/client.rb', line 177 def close @connection.close self end |
#delete(path, params = {}, headers: {}, host: nil) ⇒ String
Perform a DELETE request to the RubyGems API
214 215 216 |
# File 'lib/gems/client.rb', line 214 def delete(path, params = {}, headers: {}, host: nil) execute_request(:delete, path, params:, headers:, host:) end |
#get(path, params = {}, headers: {}, host: nil) ⇒ String
Perform a GET request to the RubyGems API
197 198 199 |
# File 'lib/gems/client.rb', line 197 def get(path, params = {}, headers: {}, host: nil) execute_request(:get, path, params:, headers:, host:) end |
#inspect ⇒ String
Summarize the client for the console
165 166 167 |
# File 'lib/gems/client.rb', line 165 def inspect "#<#{self.class} host=#{host.inspect} authenticator=#{authenticator.inspect}>" end |
#patch(path, body = {}, content_type: nil, headers: {}, host: nil) ⇒ String
Perform a PATCH request to the RubyGems API
268 269 270 |
# File 'lib/gems/client.rb', line 268 def patch(path, body = {}, content_type: nil, headers: {}, host: nil) execute_request(:patch, path, body:, content_type:, headers:, host:) end |
#post(path, body = {}, content_type: nil, headers: {}, host: nil) ⇒ String
Perform a POST request to the RubyGems API
232 233 234 |
# File 'lib/gems/client.rb', line 232 def post(path, body = {}, content_type: nil, headers: {}, host: nil) execute_request(:post, path, body:, content_type:, headers:, host:) end |
#put(path, body = {}, content_type: nil, headers: {}, host: nil) ⇒ String
Perform a PUT request to the RubyGems API
250 251 252 |
# File 'lib/gems/client.rb', line 250 def put(path, body = {}, content_type: nil, headers: {}, host: nil) execute_request(:put, path, body:, content_type:, headers:, host:) end |