Class: TridentAssistant::CLI::Collection
- Defined in:
- lib/trident_assistant/cli/collection.rb
Overview
CLI tool of collection
Defined Under Namespace
Classes: InvalidError
Constant Summary
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
#api, #bot, #client, #keystore
Instance Method Summary collapse
Methods inherited from Base
Constructor Details
This class inherits a constructor from TridentAssistant::CLI::Base
Instance Method Details
#create ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/trident_assistant/cli/collection.rb', line 24 def create name = [:name] || UI.ask("Please input collection name") raise InvalidError, "Name cannot be blank" if name.blank? description = [:description] || UI.ask("Please input collection description") raise InvalidError, "Description cannot be blank" if description.blank? icon = [:icon] || UI.ask("Please input icon file or icon url") icon_file = File.open(icon) if File.exist? icon external_url = [:url] || UI.ask("Please input collection external url, start with https:// or http://") split = [:split] || UI.ask("Please input collection split", default: "0.0") payload = { name: name, description: description, external_url: external_url, split: split } if icon_file.present? payload[:icon_base64] = Base64.strict_encode64(icon_file.read) else payload[:icon_url] = icon end log api.create_collection(**payload) rescue InvalidError => e log UI.fmt("{{x}} failed: #{e.inspect}") ensure icon_file&.close end |
#index ⇒ Object
13 14 15 |
# File 'lib/trident_assistant/cli/collection.rb', line 13 def index log api.collections end |
#show(id) ⇒ Object
76 77 78 |
# File 'lib/trident_assistant/cli/collection.rb', line 76 def show(id) log api.collection id end |
#update(id) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/trident_assistant/cli/collection.rb', line 61 def update(id) payload = {} payload[:description] = [:description] if [:description].present? payload[:external_url] = [:url] if [:url].present? if [:icon].present? && File.exist?([:icon]) icon = File.open [:icon] payload[:icon_base64] = Base64.strict_encode64(icon.read) end log api.update_collection(id, **payload) ensure icon&.close end |