class Gem::Commands::ApiCommand
module Rubygems; end
Constants
- VERSION
Attributes
Public Class Methods
Source
# File lib/rubygems/commands/api_command.rb, line 13 def initialize defaults = { query: nil } super("api", "Send requests to rubygems' API.", defaults) add_option("-j", "--jq QUERY", "Pass results through jq with QUERY.") do |v, o| options[:query] = v end end
Calls superclass method
Public Instance Methods
Source
# File lib/rubygems/commands/api_command.rb, line 31 def description <<~EOF.lines.grep_v(/DELETE|POST|PATCH/).join # TODO: handle more? `gem api` lets you hit rubygems API endpoints on the commandline. It uses the credentials located at ~/.gem/credentials. Here's the current full API: GET /api/v1/activity/latest GET /api/v1/activity/just_updated GET /api/v1/api_key.(json|yaml) GET /api/v1/dependencies?gems=$GEM1,$GEM2,... GET /api/v1/downloads.(json|yaml) GET /api/v1/downloads/$NAME-$VERSION.(json|yaml) POST /api/v1/gems GET /api/v1/gems.(json|yaml) GET /api/v1/gems/$NAME.(json|yaml) GET /api/v1/gems/$NAME/reverse_dependencies.json GET /api/v1/gems/$NAME/owners.(json|yaml) POST /api/v1/gems/$NAME/owners DELETE /api/v1/gems/$NAME/owners PATCH /api/v1/gems/$NAME/owners DELETE /api/v1/gems/yank POST /api/v1/oidc/trusted_publisher/exchange_token GET /api/v1/owners/$username_or_id/gems.(json|yaml) GET /api/v1/profile/me.(json|yaml) GET /api/v1/profiles/$username_or_id.(json|yaml) GET /api/v1/search.(json|yaml)?query=$query[&page=$N] GET /api/v1/timeframe_versions.json GET /api/v1/versions/$NAME.(json|yaml) GET /api/v1/versions/$NAME/latest.json GET /api/v1/web_hooks.(json|yaml) POST /api/v1/web_hooks DELETE /api/v1/web_hooks/remove POST /api/v1/web_hooks/fire GET /api/v2/rubygems/$NAME/versions/$VERSION.(json|yaml) Currently, only the GET endpoints are currently supported, but most of the others are supported through other gem commands (eg `gem owner`). EOF end
Source
# File lib/rubygems/commands/api_command.rb, line 81 def execute url = options[:args].shift base = "https://rubygems.org" # HACK: should look at sources url = base + url prefs = YAML.load File.read File.expand_path "~/.gem/credentials" self.creds = prefs[:rubygems_api_key] body = read_url url query = options[:query] if query then IO.popen ["jq", query].shelljoin, "r+" do |pipe| pipe.puts body pipe.close_write say pipe.read end else say body end end
Source
# File lib/rubygems/commands/api_command.rb, line 75 def read_url url URI.parse(url) .read("User-Agent" => "rubygems-api/#{VERSION}", "Authorization" => creds) end