buzzsprout-cli 0.1.1
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
- data/LICENSE +21 -0
- data/README.md +271 -0
- data/bin/buzzsprout +6 -0
- data/lib/buzzsprout/animation/wordmark.rb +41 -0
- data/lib/buzzsprout/animation.rb +181 -0
- data/lib/buzzsprout/cli.rb +215 -0
- data/lib/buzzsprout/client.rb +306 -0
- data/lib/buzzsprout/color.rb +195 -0
- data/lib/buzzsprout/commands/base.rb +188 -0
- data/lib/buzzsprout/commands/brand_affiliations.rb +98 -0
- data/lib/buzzsprout/commands/chapters.rb +58 -0
- data/lib/buzzsprout/commands/contributors.rb +119 -0
- data/lib/buzzsprout/commands/downloads.rb +139 -0
- data/lib/buzzsprout/commands/episodes.rb +116 -0
- data/lib/buzzsprout/commands/fan_mail.rb +216 -0
- data/lib/buzzsprout/commands/feed_verifications.rb +74 -0
- data/lib/buzzsprout/commands/listings.rb +159 -0
- data/lib/buzzsprout/commands/login.rb +264 -0
- data/lib/buzzsprout/commands/podcasts.rb +85 -0
- data/lib/buzzsprout/commands/podrolls.rb +74 -0
- data/lib/buzzsprout/commands/skills.rb +144 -0
- data/lib/buzzsprout/commands/status.rb +64 -0
- data/lib/buzzsprout/commands/team.rb +75 -0
- data/lib/buzzsprout/commands/transcripts.rb +100 -0
- data/lib/buzzsprout/commands/update.rb +36 -0
- data/lib/buzzsprout/commands/uploads.rb +134 -0
- data/lib/buzzsprout/config.rb +125 -0
- data/lib/buzzsprout/formatter.rb +68 -0
- data/lib/buzzsprout/group_help.rb +74 -0
- data/lib/buzzsprout/oauth.rb +203 -0
- data/lib/buzzsprout/options.rb +155 -0
- data/lib/buzzsprout/podcast_picker.rb +328 -0
- data/lib/buzzsprout/redact.rb +65 -0
- data/lib/buzzsprout/updater.rb +230 -0
- data/lib/buzzsprout/version.rb +5 -0
- data/skills/README.md +62 -0
- data/skills/brand_affiliations/SKILL.md +52 -0
- data/skills/buzzsprout/SKILL.md +111 -0
- data/skills/chapters/SKILL.md +49 -0
- data/skills/contributors/SKILL.md +58 -0
- data/skills/episodes/SKILL.md +61 -0
- data/skills/fan_mail/SKILL.md +53 -0
- data/skills/feed_verifications/SKILL.md +51 -0
- data/skills/insertion_points/SKILL.md +50 -0
- data/skills/listings/SKILL.md +52 -0
- data/skills/podcasts/SKILL.md +57 -0
- data/skills/podrolls/SKILL.md +49 -0
- data/skills/soundbites/SKILL.md +51 -0
- data/skills/stats/SKILL.md +65 -0
- data/skills/team/SKILL.md +10 -0
- data/skills/transcripts/SKILL.md +60 -0
- data/skills/uploads/SKILL.md +68 -0
- metadata +102 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Buzzsprout
|
|
4
|
+
module Commands
|
|
5
|
+
class Team < Base
|
|
6
|
+
USAGE = 'buzzsprout team [command] [flags]'
|
|
7
|
+
HELP_PAGE = {
|
|
8
|
+
summary: 'Manage podcast team members.',
|
|
9
|
+
usage: 'buzzsprout team <command> [id]',
|
|
10
|
+
aliases: %w[team],
|
|
11
|
+
commands: [
|
|
12
|
+
['list', 'List team members (default)'],
|
|
13
|
+
['invite', 'Invite a member (--email, --role)'],
|
|
14
|
+
['update', 'Update a team member'],
|
|
15
|
+
['delete', 'Remove a team member']
|
|
16
|
+
],
|
|
17
|
+
examples: [
|
|
18
|
+
'buzzsprout team',
|
|
19
|
+
'buzzsprout team invite --email editor@example.com --role editor'
|
|
20
|
+
]
|
|
21
|
+
}.freeze
|
|
22
|
+
|
|
23
|
+
def run
|
|
24
|
+
verb = @args.shift || 'list'
|
|
25
|
+
case verb
|
|
26
|
+
when 'list' then list
|
|
27
|
+
when 'invite', 'create' then invite
|
|
28
|
+
when 'update' then update
|
|
29
|
+
when 'delete', 'remove' then delete_member
|
|
30
|
+
else
|
|
31
|
+
group_help
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
private
|
|
36
|
+
|
|
37
|
+
def list
|
|
38
|
+
podcast_id = podcast_id_from_args!
|
|
39
|
+
data = client.get("/#{podcast_id}/team")
|
|
40
|
+
output(data) do
|
|
41
|
+
@formatter.heading("Team for podcast #{podcast_id}")
|
|
42
|
+
Array(data).each { |row| @io.puts "#{row['id']} #{row['name']} #{row['email']} (#{row['role']})" }
|
|
43
|
+
end
|
|
44
|
+
0
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def invite
|
|
48
|
+
podcast_id = podcast_id_from_args!
|
|
49
|
+
body = @options.merge_body
|
|
50
|
+
raise 'email is required' if body['email'].to_s.empty?
|
|
51
|
+
|
|
52
|
+
data = client.post("/#{podcast_id}/team", body: body)
|
|
53
|
+
output(data) { @io.puts "Invited #{data && data['email']} as #{data && data['role']}" }
|
|
54
|
+
0
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def update
|
|
58
|
+
podcast_id = podcast_id_from_args!
|
|
59
|
+
id = shift_id!('team_id')
|
|
60
|
+
body = @options.merge_body
|
|
61
|
+
data = client.patch("/#{podcast_id}/team/#{id}", body: body)
|
|
62
|
+
output(data) { @io.puts "Updated team member #{id}" }
|
|
63
|
+
0
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def delete_member
|
|
67
|
+
podcast_id = podcast_id_from_args!
|
|
68
|
+
id = shift_id!('team_id')
|
|
69
|
+
data = client.delete("/#{podcast_id}/team/#{id}")
|
|
70
|
+
output(data) { @io.puts "Removed team member #{id}" }
|
|
71
|
+
0
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Buzzsprout
|
|
4
|
+
module Commands
|
|
5
|
+
class Transcripts < Base
|
|
6
|
+
USAGE = 'buzzsprout transcripts <command> [flags]'
|
|
7
|
+
HELP_WHEN_BARE = true
|
|
8
|
+
HELP_PAGE = {
|
|
9
|
+
summary: 'Show, upload, or replace episode transcripts.',
|
|
10
|
+
usage: 'buzzsprout transcripts <command> <episode_id>',
|
|
11
|
+
aliases: %w[transcripts],
|
|
12
|
+
commands: [
|
|
13
|
+
['show', 'Show the custom transcript'],
|
|
14
|
+
['upload', 'Upload a custom transcript (--file)'],
|
|
15
|
+
['delete', 'Delete the custom transcript'],
|
|
16
|
+
['high-fidelity', 'Show the high-fidelity transcript'],
|
|
17
|
+
['replace-high-fidelity', 'Replace high-fidelity segments (--body)']
|
|
18
|
+
],
|
|
19
|
+
examples: [
|
|
20
|
+
'buzzsprout transcripts show 788881',
|
|
21
|
+
'buzzsprout transcripts upload 788881 --file ./show.srt'
|
|
22
|
+
]
|
|
23
|
+
}.freeze
|
|
24
|
+
|
|
25
|
+
def run
|
|
26
|
+
verb = @args.shift
|
|
27
|
+
case verb
|
|
28
|
+
when 'show' then show
|
|
29
|
+
when 'upload', 'create' then upload
|
|
30
|
+
when 'delete' then delete
|
|
31
|
+
when 'high-fidelity', 'hf' then high_fidelity
|
|
32
|
+
when 'replace-high-fidelity', 'replace-hf' then replace_high_fidelity
|
|
33
|
+
else
|
|
34
|
+
group_help
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
private
|
|
39
|
+
|
|
40
|
+
def show
|
|
41
|
+
podcast_id = podcast_id_from_args!
|
|
42
|
+
episode_id = shift_id!('episode_id')
|
|
43
|
+
data = client.get("/#{podcast_id}/episodes/#{episode_id}/transcript")
|
|
44
|
+
output(data) { @formatter.show_record("Transcript for episode #{episode_id}", data, %w[id status published download_url]) }
|
|
45
|
+
0
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def upload
|
|
49
|
+
podcast_id = podcast_id_from_args!
|
|
50
|
+
episode_id = shift_id!('episode_id')
|
|
51
|
+
path = @options.file
|
|
52
|
+
raise 'Provide --file PATH' if path.to_s.empty?
|
|
53
|
+
raise "File not found: #{path}" unless File.file?(path)
|
|
54
|
+
|
|
55
|
+
format = @options.fields['transcript_format'] || @options.format || File.extname(path).delete_prefix('.').downcase
|
|
56
|
+
raise 'transcript format must be srt or json' unless %w[srt json].include?(format)
|
|
57
|
+
|
|
58
|
+
data = client.post(
|
|
59
|
+
"/#{podcast_id}/episodes/#{episode_id}/transcript",
|
|
60
|
+
multipart: {
|
|
61
|
+
transcript_file: {
|
|
62
|
+
filename: File.basename(path),
|
|
63
|
+
content_type: format == 'json' ? 'application/json' : 'application/x-subrip',
|
|
64
|
+
data: File.binread(path)
|
|
65
|
+
},
|
|
66
|
+
transcript_format: format
|
|
67
|
+
}
|
|
68
|
+
)
|
|
69
|
+
output(data) { @io.puts "Uploaded custom transcript for episode #{episode_id}" }
|
|
70
|
+
0
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def delete
|
|
74
|
+
podcast_id = podcast_id_from_args!
|
|
75
|
+
episode_id = shift_id!('episode_id')
|
|
76
|
+
data = client.delete("/#{podcast_id}/episodes/#{episode_id}/transcript")
|
|
77
|
+
output(data) { @io.puts "Deleted custom transcript for episode #{episode_id}" }
|
|
78
|
+
0
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def high_fidelity
|
|
82
|
+
podcast_id = podcast_id_from_args!
|
|
83
|
+
episode_id = shift_id!('episode_id')
|
|
84
|
+
data = client.get("/#{podcast_id}/episodes/#{episode_id}/high_fidelity_transcript")
|
|
85
|
+
output(data) { @io.puts "High-fidelity transcript: #{Array(data).size} segments" }
|
|
86
|
+
0
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def replace_high_fidelity
|
|
90
|
+
podcast_id = podcast_id_from_args!
|
|
91
|
+
episode_id = shift_id!('episode_id')
|
|
92
|
+
raise 'Provide --body with a segment array' unless @options.body.is_a?(Array)
|
|
93
|
+
|
|
94
|
+
data = client.put("/#{podcast_id}/episodes/#{episode_id}/high_fidelity_transcript", body: @options.body)
|
|
95
|
+
output(data) { @io.puts "Replaced high-fidelity transcript for episode #{episode_id}" }
|
|
96
|
+
0
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Buzzsprout
|
|
4
|
+
module Commands
|
|
5
|
+
class Update < Base
|
|
6
|
+
HELP_PAGE = {
|
|
7
|
+
summary: 'Update a Git installation and refresh bundled agent skills.',
|
|
8
|
+
usage: 'buzzsprout update [--check] [--json] [--dir PATH]',
|
|
9
|
+
flags: [['--check', 'Check for updates without installing'], ['--json', 'Print machine-readable results'],
|
|
10
|
+
['--dir PATH', 'Skills destination override']],
|
|
11
|
+
examples: ['buzzsprout update', 'buzzsprout update --check --json']
|
|
12
|
+
}.freeze
|
|
13
|
+
|
|
14
|
+
def run
|
|
15
|
+
check_only = @args.delete('--check') || @options.dry_run?
|
|
16
|
+
raise 'Unknown update arguments. Run buzzsprout update --help.' unless @args.empty?
|
|
17
|
+
updater = Updater.new
|
|
18
|
+
result = check_only ? updater.check : updater.update(io: @err, dir: @options.dir)
|
|
19
|
+
output(result) do
|
|
20
|
+
if check_only
|
|
21
|
+
if result[:update_available]
|
|
22
|
+
@io.puts "Update available. Run: #{result[:update_command]}"
|
|
23
|
+
@io.puts 'Then run: buzzsprout skills install' unless result[:distribution].nil? || result[:distribution] == 'git'
|
|
24
|
+
else
|
|
25
|
+
@io.puts 'Buzzsprout CLI is up to date.'
|
|
26
|
+
end
|
|
27
|
+
else
|
|
28
|
+
@io.puts(result[:updated] ? 'Buzzsprout CLI updated.' : 'Buzzsprout CLI is up to date.')
|
|
29
|
+
@io.puts 'Start a new AI session to load refreshed skills.' if result[:skills_refreshed]
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
0
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Buzzsprout
|
|
4
|
+
module Commands
|
|
5
|
+
class Uploads < Base
|
|
6
|
+
USAGE = 'buzzsprout uploads <command> [flags]'
|
|
7
|
+
HELP_WHEN_BARE = true
|
|
8
|
+
HELP_PAGE = {
|
|
9
|
+
summary: 'Upload audio or video for an episode.',
|
|
10
|
+
usage: 'buzzsprout uploads <command> <episode_id> [upload_id]',
|
|
11
|
+
aliases: %w[uploads upload],
|
|
12
|
+
commands: [
|
|
13
|
+
['start', 'Start an upload (--file PATH)'],
|
|
14
|
+
['complete', 'Mark an upload complete'],
|
|
15
|
+
['abort', 'Abort an in-progress upload']
|
|
16
|
+
],
|
|
17
|
+
flags: [
|
|
18
|
+
['--file PATH', 'Local media file (start)']
|
|
19
|
+
],
|
|
20
|
+
examples: [
|
|
21
|
+
'buzzsprout uploads start 788881 --file ./episode.m4a',
|
|
22
|
+
'buzzsprout uploads complete 788881 UPLOAD_ID'
|
|
23
|
+
]
|
|
24
|
+
}.freeze
|
|
25
|
+
|
|
26
|
+
MIME = {
|
|
27
|
+
'mp3' => 'audio/mpeg',
|
|
28
|
+
'm4a' => 'audio/mp4',
|
|
29
|
+
'aac' => 'audio/aac',
|
|
30
|
+
'wav' => 'audio/wav',
|
|
31
|
+
'ogg' => 'audio/ogg',
|
|
32
|
+
'flac' => 'audio/flac',
|
|
33
|
+
'mp4' => 'video/mp4',
|
|
34
|
+
'm4v' => 'video/mp4',
|
|
35
|
+
'mov' => 'video/quicktime',
|
|
36
|
+
'webm' => 'video/webm'
|
|
37
|
+
}.freeze
|
|
38
|
+
|
|
39
|
+
def run
|
|
40
|
+
verb = @args.shift
|
|
41
|
+
case verb
|
|
42
|
+
when 'start', 'upload'
|
|
43
|
+
start
|
|
44
|
+
when 'complete'
|
|
45
|
+
complete
|
|
46
|
+
when 'abort'
|
|
47
|
+
abort_upload
|
|
48
|
+
else
|
|
49
|
+
group_help
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
private
|
|
54
|
+
|
|
55
|
+
def start
|
|
56
|
+
podcast_id = podcast_id_from_args!
|
|
57
|
+
episode_id = shift_id!('episode_id')
|
|
58
|
+
path = @options.file || Options.extract_option!(@args, '--file')
|
|
59
|
+
raise 'Provide --file PATH' if path.to_s.empty?
|
|
60
|
+
raise "File not found: #{path}" unless File.file?(path)
|
|
61
|
+
|
|
62
|
+
size = File.size(path)
|
|
63
|
+
filename = File.basename(path)
|
|
64
|
+
type = @options.fields['type'] || mime_for(filename)
|
|
65
|
+
multipart = @options.fields.key?('multipart') ? @options.fields['multipart'] : (size > 5 * 1024 * 1024 * 1024)
|
|
66
|
+
body = {
|
|
67
|
+
filename: filename,
|
|
68
|
+
type: type,
|
|
69
|
+
byte_size: size
|
|
70
|
+
}
|
|
71
|
+
body[:multipart] = true if multipart
|
|
72
|
+
|
|
73
|
+
started = client.post("/#{podcast_id}/episodes/#{episode_id}/uploads", body: body)
|
|
74
|
+
return 0 if started.nil? && @options.dry_run?
|
|
75
|
+
|
|
76
|
+
upload = started.is_a?(Hash) ? (started['upload'] || started) : started
|
|
77
|
+
output(started) { @io.puts "Started upload #{upload['id']} (#{filename}, #{size} bytes)" }
|
|
78
|
+
|
|
79
|
+
if upload['multipart']
|
|
80
|
+
put_parts(path, upload)
|
|
81
|
+
else
|
|
82
|
+
url = upload['upload_url']
|
|
83
|
+
raise 'No upload_url returned' if url.to_s.empty?
|
|
84
|
+
|
|
85
|
+
bytes = File.binread(path)
|
|
86
|
+
@io.puts "Uploading bytes to storage (no Authorization header)…"
|
|
87
|
+
client.put_bytes(url, bytes)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
upload_id = encode_id(upload['id'])
|
|
91
|
+
completed = client.post("/#{podcast_id}/episodes/#{episode_id}/uploads/#{upload_id}/complete")
|
|
92
|
+
output(completed) { @io.puts Color.green("Upload complete. Encoding will finish asynchronously — poll with: buzzsprout episodes show #{podcast_id} #{episode_id}", io: @io) }
|
|
93
|
+
0
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def complete
|
|
97
|
+
podcast_id = podcast_id_from_args!
|
|
98
|
+
episode_id = shift_id!('episode_id')
|
|
99
|
+
upload_id = encode_id(shift_id!('upload_id'))
|
|
100
|
+
result = client.post("/#{podcast_id}/episodes/#{episode_id}/uploads/#{upload_id}/complete")
|
|
101
|
+
output(result) { @io.puts "Completed upload #{upload_id}" }
|
|
102
|
+
0
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def abort_upload
|
|
106
|
+
podcast_id = podcast_id_from_args!
|
|
107
|
+
episode_id = shift_id!('episode_id')
|
|
108
|
+
upload_id = encode_id(shift_id!('upload_id'))
|
|
109
|
+
result = client.delete("/#{podcast_id}/episodes/#{episode_id}/uploads/#{upload_id}/abort")
|
|
110
|
+
output(result) { @io.puts "Aborted upload #{upload_id}" }
|
|
111
|
+
0
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def put_parts(path, upload)
|
|
115
|
+
part_size = upload['part_size'].to_i
|
|
116
|
+
File.open(path, 'rb') do |file|
|
|
117
|
+
Array(upload['parts']).each do |part|
|
|
118
|
+
length = part.fetch('content_length').to_i
|
|
119
|
+
offset = (part.fetch('part_number').to_i - 1) * part_size
|
|
120
|
+
file.seek(offset)
|
|
121
|
+
bytes = file.read(length)
|
|
122
|
+
@io.puts "Uploading part #{part['part_number']} (#{length} bytes)…"
|
|
123
|
+
client.put_bytes(part.fetch('url'), bytes)
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def mime_for(filename)
|
|
129
|
+
ext = File.extname(filename).delete_prefix('.').downcase
|
|
130
|
+
MIME[ext] || 'application/octet-stream'
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
end
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'json'
|
|
4
|
+
require 'fileutils'
|
|
5
|
+
require 'tempfile'
|
|
6
|
+
|
|
7
|
+
module Buzzsprout
|
|
8
|
+
class Config
|
|
9
|
+
DEFAULT_API_BASE = 'https://www.buzzsprout.com/api'
|
|
10
|
+
DEFAULT_CONFIG_FILE = File.expand_path('~/.buzzsprout.json')
|
|
11
|
+
|
|
12
|
+
class << self
|
|
13
|
+
def config_file
|
|
14
|
+
ENV['BUZZSPROUT_CONFIG'] || DEFAULT_CONFIG_FILE
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def api_base_url
|
|
18
|
+
(ENV['BUZZSPROUT_API_BASE'] || loaded[:api_base] || DEFAULT_API_BASE).to_s.chomp('/')
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def load
|
|
22
|
+
return @config if @config
|
|
23
|
+
|
|
24
|
+
unless File.exist?(config_file)
|
|
25
|
+
@config = {}
|
|
26
|
+
return @config
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
@config = JSON.parse(File.read(config_file), symbolize_names: true)
|
|
30
|
+
rescue JSON::ParserError
|
|
31
|
+
raise "Could not parse #{config_file}. Fix or delete it, then run 'buzzsprout login'."
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def loaded
|
|
35
|
+
load
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def save(config)
|
|
39
|
+
return with_lock { clear_cache; save(config) } unless Thread.current[:buzzsprout_config_locked]
|
|
40
|
+
|
|
41
|
+
merged = loaded.merge(config.transform_keys(&:to_sym))
|
|
42
|
+
merged.delete_if { |_, value| value.nil? || value == '' }
|
|
43
|
+
dir = File.dirname(config_file)
|
|
44
|
+
FileUtils.mkdir_p(dir)
|
|
45
|
+
Tempfile.create(['buzzsprout', '.json'], dir) do |file|
|
|
46
|
+
file.chmod(0o600)
|
|
47
|
+
file.write(JSON.pretty_generate(merged))
|
|
48
|
+
file.flush
|
|
49
|
+
file.fsync
|
|
50
|
+
File.rename(file.path, config_file)
|
|
51
|
+
end
|
|
52
|
+
@token = nil
|
|
53
|
+
@config = merged
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def with_lock
|
|
57
|
+
FileUtils.mkdir_p(File.dirname(config_file))
|
|
58
|
+
File.open("#{config_file}.lock", File::RDWR | File::CREAT, 0o600) do |lock|
|
|
59
|
+
lock.flock(File::LOCK_EX)
|
|
60
|
+
Thread.current[:buzzsprout_config_locked] = true
|
|
61
|
+
yield
|
|
62
|
+
ensure
|
|
63
|
+
Thread.current[:buzzsprout_config_locked] = false
|
|
64
|
+
lock.flock(File::LOCK_UN)
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def oauth?
|
|
69
|
+
ENV['BUZZSPROUT_API_TOKEN'].to_s.empty? && loaded[:auth_method] == 'oauth'
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def configured?
|
|
73
|
+
oauth? ? loaded.dig(:oauth, :api_base) == api_base_url : !token.to_s.empty?
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def token
|
|
77
|
+
return loaded.dig(:oauth, :access_token) if oauth?
|
|
78
|
+
return @token if @token
|
|
79
|
+
|
|
80
|
+
env = ENV['BUZZSPROUT_API_TOKEN']
|
|
81
|
+
return @token = env unless env.to_s.empty?
|
|
82
|
+
|
|
83
|
+
value = loaded[:api_token] || loaded[:token]
|
|
84
|
+
@token = value.to_s.empty? ? nil : value
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def default_podcast_id
|
|
88
|
+
ENV['BUZZSPROUT_PODCAST_ID'] || saved_podcast_id
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# File-backed default only (not BUZZSPROUT_PODCAST_ID, which is per-process).
|
|
92
|
+
def saved_podcast_id
|
|
93
|
+
value = loaded[:default_podcast_id] || loaded[:podcast_id]
|
|
94
|
+
return if value.nil? || value.to_s.empty?
|
|
95
|
+
|
|
96
|
+
value
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def require_token!
|
|
100
|
+
return OAuth.access_token if oauth?
|
|
101
|
+
return token if configured?
|
|
102
|
+
|
|
103
|
+
raise "Not authenticated. Run 'buzzsprout login' first (or set BUZZSPROUT_API_TOKEN)."
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def clear_cache
|
|
107
|
+
@config = nil
|
|
108
|
+
@token = nil
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def delete!
|
|
112
|
+
File.delete(config_file) if File.exist?(config_file)
|
|
113
|
+
clear_cache
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
private
|
|
117
|
+
|
|
118
|
+
def chmod_private!(path)
|
|
119
|
+
File.chmod(0o600, path)
|
|
120
|
+
rescue NotImplementedError, SystemCallError
|
|
121
|
+
nil
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'json'
|
|
4
|
+
require_relative 'redact'
|
|
5
|
+
require_relative 'podcast_picker'
|
|
6
|
+
|
|
7
|
+
module Buzzsprout
|
|
8
|
+
class Formatter
|
|
9
|
+
def initialize(io: $stdout)
|
|
10
|
+
@io = io
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def heading(title)
|
|
14
|
+
@io.puts Color.bold(title, io: @io)
|
|
15
|
+
@io.puts '=' * 60
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def kv(label, value)
|
|
19
|
+
return if value.nil? || value == ''
|
|
20
|
+
|
|
21
|
+
@io.puts "#{label.ljust(16)} #{value}"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def list_podcasts(podcasts)
|
|
25
|
+
heading('Podcasts')
|
|
26
|
+
rows = wrap_list(podcasts)
|
|
27
|
+
if rows.empty?
|
|
28
|
+
@io.puts 'No podcasts found.'
|
|
29
|
+
return
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
rows.each do |podcast|
|
|
33
|
+
@io.puts PodcastPicker.format_label(podcast, io: @io)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def show_record(title, record, keys)
|
|
38
|
+
heading(title)
|
|
39
|
+
keys.each { |key| kv(key, record[key]) }
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def list_records(title, records, columns)
|
|
43
|
+
heading(title)
|
|
44
|
+
if records.nil? || records.empty?
|
|
45
|
+
@io.puts 'None found.'
|
|
46
|
+
return
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
Array(records).each do |record|
|
|
50
|
+
line = columns.map { |key| record[key] }.compact.join(' ')
|
|
51
|
+
@io.puts line
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def json(data)
|
|
56
|
+
payload = JSON.pretty_generate(data.nil? ? { ok: true } : data)
|
|
57
|
+
@io.puts Redact.string(payload)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def wrap_list(data)
|
|
61
|
+
case data
|
|
62
|
+
when Array then data
|
|
63
|
+
when Hash then [data]
|
|
64
|
+
else []
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'color'
|
|
4
|
+
|
|
5
|
+
module Buzzsprout
|
|
6
|
+
# Basecamp-style group help for a parent command (USAGE / COMMANDS / FLAGS / …).
|
|
7
|
+
class GroupHelp
|
|
8
|
+
INHERITED_FLAGS = [
|
|
9
|
+
['--json', 'Print raw JSON'],
|
|
10
|
+
['--body \'{…}\'', 'JSON request body'],
|
|
11
|
+
['--file PATH', 'Upload a local file'],
|
|
12
|
+
['--podcast ID, --in ID', 'Podcast id for this invocation'],
|
|
13
|
+
['--dry-run', 'Print the request without sending it']
|
|
14
|
+
].freeze
|
|
15
|
+
|
|
16
|
+
def initialize(io: $stdout)
|
|
17
|
+
@io = io
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def print(page)
|
|
21
|
+
page = symbolize(page)
|
|
22
|
+
summary = page[:summary].to_s
|
|
23
|
+
@io.puts summary unless summary.empty?
|
|
24
|
+
@io.puts '' unless summary.empty?
|
|
25
|
+
|
|
26
|
+
section('USAGE', Array(page[:usage]))
|
|
27
|
+
aliases = Array(page[:aliases])
|
|
28
|
+
section('ALIASES', [aliases.join(', ')]) unless aliases.empty?
|
|
29
|
+
section('COMMANDS', two_col(page[:commands])) if page[:commands]&.any?
|
|
30
|
+
flags = Array(page[:flags]) + [['-h, --help', "Help for #{command_name(page)}"]]
|
|
31
|
+
section('FLAGS', two_col(flags))
|
|
32
|
+
section('INHERITED FLAGS', two_col(page[:inherited] || INHERITED_FLAGS))
|
|
33
|
+
examples = Array(page[:examples])
|
|
34
|
+
section('EXAMPLES', examples.map { |line| line.start_with?('$') ? line : "$ #{line}" }) unless examples.empty?
|
|
35
|
+
learn = page[:learn] || "buzzsprout #{command_name(page)} --help"
|
|
36
|
+
section('LEARN MORE', Array(learn))
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def self.print(page, io: $stdout)
|
|
40
|
+
new(io: io).print(page)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
private
|
|
44
|
+
|
|
45
|
+
def command_name(page)
|
|
46
|
+
return page[:name] if page[:name]
|
|
47
|
+
|
|
48
|
+
usage = Array(page[:usage]).first.to_s
|
|
49
|
+
usage.split.find { |part| part != 'buzzsprout' } || 'command'
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def section(title, lines)
|
|
53
|
+
return if lines.nil? || lines.empty?
|
|
54
|
+
|
|
55
|
+
@io.puts Color.bold(title, io: @io)
|
|
56
|
+
lines.each { |line| @io.puts(line.match?(/\A\s/) ? line : " #{line}") }
|
|
57
|
+
@io.puts ''
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def two_col(rows)
|
|
61
|
+
rows = Array(rows)
|
|
62
|
+
return [] if rows.empty?
|
|
63
|
+
|
|
64
|
+
width = rows.map { |left, _| left.to_s.length }.max
|
|
65
|
+
rows.map do |left, right|
|
|
66
|
+
" #{left.to_s.ljust(width)} #{right}"
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def symbolize(page)
|
|
71
|
+
page.to_h.transform_keys(&:to_sym)
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|