Class: Furaffinity::Cli

Inherits:
Thor
  • Object
show all
Includes:
CliBase
Defined in:
lib/furaffinity/cli.rb

Constant Summary collapse

EDIT_TEMPLATE =
<<~YAML
  ---
  # Submission info for %<id>s

  # Required field:
  title: %<title>s

  # Required field
  description: |-
  %<description>s

  # Optional field, keywords separated by spaces:
  keywords: %<keywords>s

  # Required field, one of: [#{Furaffinity::Client::RATING_MAP.keys.join(", ")}]
  rating: %<rating>s

  scrap: %<scrap>s
  lock_comments: %<lock_comments>s

  # vim: syntax=yaml
YAML

Instance Method Summary collapse

Methods included from CliBase

included

Instance Method Details

#__print_versionObject



180
# File 'lib/furaffinity/cli.rb', line 180

def __print_version = puts "furaffinity-cli/#{VERSION}"

#auth(a_cookie, b_cookie) ⇒ Object



23
24
25
26
27
28
# File 'lib/furaffinity/cli.rb', line 23

def auth(a_cookie, b_cookie)
  set_log_level(options)
  config = config_for(options)
  config.set!(a: a_cookie, b: b_cookie)
  say "Authentication info stored.", :green
end

#edit_interactive(id) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/furaffinity/cli.rb', line 112

def edit_interactive(id)
  set_log_level(options)
  config = config_for(options)
  client = config.new_client

  submission_info = client.submission_info(id)
  # write template
  file = Tempfile.new("facli_edit_#{id}")
  file.puts format(EDIT_TEMPLATE,
    id:,
    **submission_info.slice(:title, :keywords, :scrap, :lock_comments).transform_values(&:inspect),
    description: submission_info.fetch(:message).gsub(/^/, "  "),
    rating:      submission_info.fetch(:rating),
  )
  file.close
  CliUtils.open_editor file.path, fatal: true
  params = YAML.safe_load_file(file.path, permitted_classes: [Symbol]).transform_keys(&:to_sym)

  url = client.update(id:, **params)
  say "Submission updated!  #{url}", :green
ensure
  file.close
  file.unlink
end

#notificationsObject



31
32
33
34
35
36
37
# File 'lib/furaffinity/cli.rb', line 31

def notifications
  set_log_level(options)
  config = config_for(options)
  client = config.new_client

  puts JSON.pretty_generate client.notifications
end

#upload(file_path) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/furaffinity/cli.rb', line 72

def upload(file_path)
  set_log_level(options)
  config = config_for(options)
  client = config.new_client

  upload_options = options.slice(
    *client
      .method(:upload)
      .parameters
      .select { |(type, name)| %i[keyreq key].include?(type) }
      .map(&:last)
  ).transform_keys(&:to_sym)
  url = client.upload(File.new(file_path), **upload_options)
  say "Submission uploaded!  #{url}", :green
end