class Ribose::CLI::Commands::Conversation

Public Instance Methods

add() click to toggle source
# File lib/ribose/cli/commands/conversation.rb, line 33
def add
  conversation = create_conversation(options)
  say("New Conversation created! Id: " + conversation.id)
end
list() click to toggle source
# File lib/ribose/cli/commands/conversation.rb, line 9
def list
  say(build_output(list_conversations, options))
end
remove() click to toggle source
# File lib/ribose/cli/commands/conversation.rb, line 60
def remove
  remove_conversation(options)
  say("The Conversation has been removed!")
rescue
  say("Please provide a valid Conversation UUID")
end
show() click to toggle source
# File lib/ribose/cli/commands/conversation.rb, line 24
def show
  say(build_resource_output(conversation(options), options))
end
update() click to toggle source
# File lib/ribose/cli/commands/conversation.rb, line 49
def update
  update_conversation(symbolize_keys(options))
  say("Your conversation has been updated!")
rescue Ribose::UnprocessableEntity
  say("Something went wrong!, please check required attributes")
end

Private Instance Methods

conversation(attributes) click to toggle source
# File lib/ribose/cli/commands/conversation.rb, line 69
def conversation(attributes)
  @conversation ||= Ribose::Conversation.fetch(
    attributes[:space_id], attributes[:conversation_id]
  )
end
create_conversation(options) click to toggle source
# File lib/ribose/cli/commands/conversation.rb, line 79
def create_conversation(options)
  Ribose::Conversation.create(
    options[:space_id], name: options[:title], tag_list: options[:tags]
  )
end
list_conversations() click to toggle source
# File lib/ribose/cli/commands/conversation.rb, line 75
def list_conversations
  @conversations ||= Ribose::Conversation.all(options[:space_id])
end
remove_conversation(options) click to toggle source
# File lib/ribose/cli/commands/conversation.rb, line 93
def remove_conversation(options)
  Ribose::Conversation.destroy(
    space_id: options[:space_id],
    conversation_id: options[:conversation_id],
  )
end
table_field_names() click to toggle source
# File lib/ribose/cli/commands/conversation.rb, line 104
def table_field_names
  %w(id space_id name number_of_messages allow_comment)
end
table_headers() click to toggle source
# File lib/ribose/cli/commands/conversation.rb, line 100
def table_headers
  ["ID", "Title"]
end
table_rows(conversations) click to toggle source
# File lib/ribose/cli/commands/conversation.rb, line 108
def table_rows(conversations)
  conversations.map { |conv| [conv.id, conv.name] }
end
update_conversation(attributes) click to toggle source
# File lib/ribose/cli/commands/conversation.rb, line 85
def update_conversation(attributes)
  Ribose::Conversation.update(
    attributes.delete(:space_id),
    attributes.delete(:conversation_id),
    attributes,
  )
end