rubygems-api 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data/History.rdoc +6 -0
- data/Manifest.txt +7 -0
- data/README.rdoc +55 -0
- data/Rakefile +16 -0
- data/lib/rubygems/commands/api_command.rb +104 -0
- data/lib/rubygems_plugin.rb +3 -0
- data/test/rubygems/test_api.rb +63 -0
- data.tar.gz.sig +2 -0
- metadata +132 -0
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 7cac2baf6384455802bac61aa1bcda1ab07d45add8c41d9814dee581011d391f
|
|
4
|
+
data.tar.gz: 0d85eceda3cf70d32c4099f9fef502563157b7056d0bad4d79f0fb1a5e3fcc7c
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 31e5be4a4657773cb62dc2c7083e69c84b30babe9f126c35e04962e86daec4f391121f0130ea4c60c557fb7c773e5fe46a0f7d5fffb5b591be698fe6579b7a3b
|
|
7
|
+
data.tar.gz: 1822844fbb9df2b333a5eb3d309a19a2bd6ae3cfbe015691ec00808cdb1489c54c94654274e17abe468e317cb5b0a57f9214160ca7f17f342a6738a0a94c5621
|
checksums.yaml.gz.sig
ADDED
|
Binary file
|
data/History.rdoc
ADDED
data/Manifest.txt
ADDED
data/README.rdoc
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
= rubygems-api
|
|
2
|
+
|
|
3
|
+
home :: https://github.com/seattlerb/rubygems-api
|
|
4
|
+
rdoc :: https://docs.seattlerb.org/rubygems-api
|
|
5
|
+
|
|
6
|
+
== DESCRIPTION:
|
|
7
|
+
|
|
8
|
+
Send requests to rubygems' API and print the output. You can also
|
|
9
|
+
query the output with jq (assuming json output) for that endpoint.
|
|
10
|
+
|
|
11
|
+
== FEATURES/PROBLEMS:
|
|
12
|
+
|
|
13
|
+
* Prints results from rubygems API.
|
|
14
|
+
* Can use jq queries to filter and format results.
|
|
15
|
+
* Currently only handles GET endpoints. See -h for a full list.
|
|
16
|
+
* Uses ~/.gem/credentials for a higher query rate.
|
|
17
|
+
|
|
18
|
+
== SYNOPSIS:
|
|
19
|
+
|
|
20
|
+
$ gem api "/api/v1/gems.json" -j "sort_by(.name).[].name"
|
|
21
|
+
|
|
22
|
+
== REQUIREMENTS:
|
|
23
|
+
|
|
24
|
+
* ruby
|
|
25
|
+
* rubygems
|
|
26
|
+
* open-uri
|
|
27
|
+
|
|
28
|
+
== INSTALL:
|
|
29
|
+
|
|
30
|
+
* gem install rubygems-api
|
|
31
|
+
|
|
32
|
+
== LICENSE:
|
|
33
|
+
|
|
34
|
+
(The MIT License)
|
|
35
|
+
|
|
36
|
+
Copyright (c) Ryan Davis, seattle.rb
|
|
37
|
+
|
|
38
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
39
|
+
a copy of this software and associated documentation files (the
|
|
40
|
+
'Software'), to deal in the Software without restriction, including
|
|
41
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
42
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
43
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
44
|
+
the following conditions:
|
|
45
|
+
|
|
46
|
+
The above copyright notice and this permission notice shall be
|
|
47
|
+
included in all copies or substantial portions of the Software.
|
|
48
|
+
|
|
49
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
50
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
51
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
52
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
53
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
54
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
55
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# -*- ruby -*-
|
|
2
|
+
|
|
3
|
+
require "hoe"
|
|
4
|
+
|
|
5
|
+
Hoe.plugin :isolate
|
|
6
|
+
Hoe.plugin :seattlerb
|
|
7
|
+
Hoe.plugin :rdoc
|
|
8
|
+
Hoe.plugin :cov
|
|
9
|
+
|
|
10
|
+
Hoe.spec "rubygems-api" do
|
|
11
|
+
developer "Ryan Davis", "ryand-ruby@zenspider.com"
|
|
12
|
+
|
|
13
|
+
license "MIT"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# vim: syntax=ruby
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
require "rubygems/command"
|
|
2
|
+
require "open-uri"
|
|
3
|
+
require "yaml"
|
|
4
|
+
require "shellwords"
|
|
5
|
+
|
|
6
|
+
# module Rubygems; end
|
|
7
|
+
|
|
8
|
+
class Gem::Commands::ApiCommand < Gem::Command
|
|
9
|
+
VERSION = "1.0.0"
|
|
10
|
+
|
|
11
|
+
attr_accessor :creds
|
|
12
|
+
|
|
13
|
+
def initialize
|
|
14
|
+
defaults = { query: nil }
|
|
15
|
+
|
|
16
|
+
super("api", "Send requests to rubygems' API.", defaults)
|
|
17
|
+
|
|
18
|
+
add_option("-j", "--jq QUERY", "Pass results through jq with QUERY.") do |v, o|
|
|
19
|
+
options[:query] = v
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def arguments # :nodoc:
|
|
24
|
+
"URL API endpoint to hit, with params"
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def usage # :nodoc:
|
|
28
|
+
"#{program_name} URL [-j jq-query]"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def description
|
|
32
|
+
<<~EOF.lines.grep_v(/DELETE|POST|PATCH/).join # TODO: handle more?
|
|
33
|
+
|
|
34
|
+
`gem api` lets you hit rubygems API endpoints on the commandline.
|
|
35
|
+
|
|
36
|
+
It uses the credentials located at ~/.gem/credentials.
|
|
37
|
+
|
|
38
|
+
Here's the current full API:
|
|
39
|
+
|
|
40
|
+
GET /api/v1/activity/latest
|
|
41
|
+
GET /api/v1/activity/just_updated
|
|
42
|
+
GET /api/v1/api_key.(json|yaml)
|
|
43
|
+
GET /api/v1/dependencies?gems=$GEM1,$GEM2,...
|
|
44
|
+
GET /api/v1/downloads.(json|yaml)
|
|
45
|
+
GET /api/v1/downloads/$NAME-$VERSION.(json|yaml)
|
|
46
|
+
POST /api/v1/gems
|
|
47
|
+
GET /api/v1/gems.(json|yaml)
|
|
48
|
+
GET /api/v1/gems/$NAME.(json|yaml)
|
|
49
|
+
GET /api/v1/gems/$NAME/reverse_dependencies.json
|
|
50
|
+
GET /api/v1/gems/$NAME/owners.(json|yaml)
|
|
51
|
+
POST /api/v1/gems/$NAME/owners
|
|
52
|
+
DELETE /api/v1/gems/$NAME/owners
|
|
53
|
+
PATCH /api/v1/gems/$NAME/owners
|
|
54
|
+
DELETE /api/v1/gems/yank
|
|
55
|
+
POST /api/v1/oidc/trusted_publisher/exchange_token
|
|
56
|
+
GET /api/v1/owners/$username_or_id/gems.(json|yaml)
|
|
57
|
+
GET /api/v1/profile/me.(json|yaml)
|
|
58
|
+
GET /api/v1/profiles/$username_or_id.(json|yaml)
|
|
59
|
+
GET /api/v1/search.(json|yaml)?query=$query[&page=$N]
|
|
60
|
+
GET /api/v1/timeframe_versions.json
|
|
61
|
+
GET /api/v1/versions/$NAME.(json|yaml)
|
|
62
|
+
GET /api/v1/versions/$NAME/latest.json
|
|
63
|
+
GET /api/v1/web_hooks.(json|yaml)
|
|
64
|
+
POST /api/v1/web_hooks
|
|
65
|
+
DELETE /api/v1/web_hooks/remove
|
|
66
|
+
POST /api/v1/web_hooks/fire
|
|
67
|
+
GET /api/v2/rubygems/$NAME/versions/$VERSION.(json|yaml)
|
|
68
|
+
|
|
69
|
+
Currently, only the GET endpoints are currently supported, but
|
|
70
|
+
most of the others are supported through other gem commands (eg
|
|
71
|
+
`gem owner`).
|
|
72
|
+
EOF
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def read_url url
|
|
76
|
+
URI.parse(url)
|
|
77
|
+
.read("User-Agent" => "rubygems-api/#{VERSION}",
|
|
78
|
+
"Authorization" => creds)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def execute
|
|
82
|
+
url = options[:args].shift
|
|
83
|
+
|
|
84
|
+
base = "https://rubygems.org" # HACK: should look at sources
|
|
85
|
+
|
|
86
|
+
url = base + url
|
|
87
|
+
|
|
88
|
+
prefs = YAML.load File.read File.expand_path "~/.gem/credentials"
|
|
89
|
+
self.creds = prefs[:rubygems_api_key]
|
|
90
|
+
|
|
91
|
+
body = read_url url
|
|
92
|
+
|
|
93
|
+
query = options[:query]
|
|
94
|
+
if query then
|
|
95
|
+
IO.popen ["jq", query].shelljoin, "r+" do |pipe|
|
|
96
|
+
pipe.puts body
|
|
97
|
+
pipe.close_write
|
|
98
|
+
say pipe.read
|
|
99
|
+
end
|
|
100
|
+
else
|
|
101
|
+
say body
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
require "minitest/autorun"
|
|
2
|
+
require "rubygems/commands/api_command"
|
|
3
|
+
require "json"
|
|
4
|
+
|
|
5
|
+
module TestRubygems; end
|
|
6
|
+
|
|
7
|
+
# sabotage open-uri
|
|
8
|
+
class URI::HTTP
|
|
9
|
+
def read(_) = raise "no"
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
class TestRubygems::TestApi < Minitest::Test
|
|
13
|
+
attr_accessor :cmd, :inn, :out, :err
|
|
14
|
+
|
|
15
|
+
def setup
|
|
16
|
+
self.cmd = Gem::Commands::ApiCommand.new
|
|
17
|
+
self.inn = StringIO.new
|
|
18
|
+
self.out = StringIO.new
|
|
19
|
+
self.err = StringIO.new
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_sanity
|
|
23
|
+
def cmd.read_url(_) = "[3,2,1]"
|
|
24
|
+
|
|
25
|
+
out = "[\n 1,\n 2,\n 3\n]\n"
|
|
26
|
+
assert_api out, "", %w[ /api/woot -j sort|. ]
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def test_execute__vanilla
|
|
30
|
+
def cmd.read_url(_) = "[3,2,1]"
|
|
31
|
+
|
|
32
|
+
out = "[3,2,1]\n"
|
|
33
|
+
assert_api out, "", %w[ /api/woot ]
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def test_cmd__help
|
|
37
|
+
assert_gem_output(/gem api URL/, "") do
|
|
38
|
+
cmd.show_help
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def assert_api out, err, *args
|
|
43
|
+
cmd.handle_options args.flatten
|
|
44
|
+
|
|
45
|
+
assert_gem_output out, err do
|
|
46
|
+
cmd.execute
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def assert_gem_output exp_out, exp_err
|
|
51
|
+
ui = Gem::StreamUI.new inn, out, err
|
|
52
|
+
|
|
53
|
+
Gem::DefaultUserInteraction.use_ui ui do
|
|
54
|
+
yield
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
o_type = Regexp === exp_out ? :match : :equal
|
|
58
|
+
e_type = Regexp === exp_err ? :match : :equal
|
|
59
|
+
|
|
60
|
+
send "assert_#{o_type}", exp_out, out.string
|
|
61
|
+
send "assert_#{e_type}", exp_err, err.string
|
|
62
|
+
end
|
|
63
|
+
end
|
data.tar.gz.sig
ADDED
metadata
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: rubygems-api
|
|
3
|
+
version: !ruby/object:Gem::Version
|
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kYQEUL6XWtfK8fAfbuLJzmLcz6f2ZWrtBvPsYvqRuwI1bWUtil
|
|
25
|
+
2ibJEfIuSIHX6BsUTX18+hlaIussf6EWq/YkE7e2BKmgQE42vSOZMce0kCEAPbx0
|
|
26
|
+
rQtqonfWTHQ8UbQ7GqCL3gDQ0QDD2B+HUlb4uaCZ2icxqa/eOtxMvHC2tj+h0xKY
|
|
27
|
+
xL84ipM5kr0bHGf9/MRZJWcw51urueNycBXu1Xh+pEN8qBmYsFRR4SIODLClybAO
|
|
28
|
+
6cbm2PyPQgKNiqE4H+IQrDVHd9bJs1XgLElk3qoaJBWXc/5fy0J1imYb25UqmiHG
|
|
29
|
+
snGe1hrppvBRdcyEzvhfIPjI
|
|
30
|
+
-----END CERTIFICATE-----
|
|
31
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
32
|
+
dependencies:
|
|
33
|
+
- !ruby/object:Gem::Dependency
|
|
34
|
+
name: rdoc
|
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '6.0'
|
|
40
|
+
- - "<"
|
|
41
|
+
- !ruby/object:Gem::Version
|
|
42
|
+
version: '8'
|
|
43
|
+
type: :development
|
|
44
|
+
prerelease: false
|
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
46
|
+
requirements:
|
|
47
|
+
- - ">="
|
|
48
|
+
- !ruby/object:Gem::Version
|
|
49
|
+
version: '6.0'
|
|
50
|
+
- - "<"
|
|
51
|
+
- !ruby/object:Gem::Version
|
|
52
|
+
version: '8'
|
|
53
|
+
- !ruby/object:Gem::Dependency
|
|
54
|
+
name: simplecov
|
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
|
56
|
+
requirements:
|
|
57
|
+
- - "~>"
|
|
58
|
+
- !ruby/object:Gem::Version
|
|
59
|
+
version: '0.21'
|
|
60
|
+
type: :development
|
|
61
|
+
prerelease: false
|
|
62
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
63
|
+
requirements:
|
|
64
|
+
- - "~>"
|
|
65
|
+
- !ruby/object:Gem::Version
|
|
66
|
+
version: '0.21'
|
|
67
|
+
- !ruby/object:Gem::Dependency
|
|
68
|
+
name: hoe
|
|
69
|
+
requirement: !ruby/object:Gem::Requirement
|
|
70
|
+
requirements:
|
|
71
|
+
- - "~>"
|
|
72
|
+
- !ruby/object:Gem::Version
|
|
73
|
+
version: '4.6'
|
|
74
|
+
type: :development
|
|
75
|
+
prerelease: false
|
|
76
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
77
|
+
requirements:
|
|
78
|
+
- - "~>"
|
|
79
|
+
- !ruby/object:Gem::Version
|
|
80
|
+
version: '4.6'
|
|
81
|
+
description: |-
|
|
82
|
+
Send requests to rubygems' API and print the output. You can also
|
|
83
|
+
query the output with jq (assuming json output) for that endpoint.
|
|
84
|
+
|
|
85
|
+
== Features/Problems:
|
|
86
|
+
|
|
87
|
+
* Prints results from rubygems API.
|
|
88
|
+
* Can use jq queries to filter and format results.
|
|
89
|
+
* Currently only handles GET endpoints. See -h for a full list.
|
|
90
|
+
* Uses ~/.gem/credentials for a higher query rate.
|
|
91
|
+
email:
|
|
92
|
+
- ryand-ruby@zenspider.com
|
|
93
|
+
executables: []
|
|
94
|
+
extensions: []
|
|
95
|
+
extra_rdoc_files:
|
|
96
|
+
- History.rdoc
|
|
97
|
+
- Manifest.txt
|
|
98
|
+
- README.rdoc
|
|
99
|
+
files:
|
|
100
|
+
- History.rdoc
|
|
101
|
+
- Manifest.txt
|
|
102
|
+
- README.rdoc
|
|
103
|
+
- Rakefile
|
|
104
|
+
- lib/rubygems/commands/api_command.rb
|
|
105
|
+
- lib/rubygems_plugin.rb
|
|
106
|
+
- test/rubygems/test_api.rb
|
|
107
|
+
homepage: https://github.com/seattlerb/rubygems-api
|
|
108
|
+
licenses:
|
|
109
|
+
- MIT
|
|
110
|
+
metadata:
|
|
111
|
+
homepage_uri: https://github.com/seattlerb/rubygems-api
|
|
112
|
+
documentation_uri: https://docs.seattlerb.org/rubygems-api
|
|
113
|
+
rdoc_options:
|
|
114
|
+
- "--main"
|
|
115
|
+
- README.rdoc
|
|
116
|
+
require_paths:
|
|
117
|
+
- lib
|
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
119
|
+
requirements:
|
|
120
|
+
- - ">="
|
|
121
|
+
- !ruby/object:Gem::Version
|
|
122
|
+
version: '0'
|
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
|
+
requirements:
|
|
125
|
+
- - ">="
|
|
126
|
+
- !ruby/object:Gem::Version
|
|
127
|
+
version: '0'
|
|
128
|
+
requirements: []
|
|
129
|
+
rubygems_version: 3.7.2
|
|
130
|
+
specification_version: 4
|
|
131
|
+
summary: Send requests to rubygems' API and print the output
|
|
132
|
+
test_files: []
|
metadata.gz.sig
ADDED
|
Binary file
|