Class: EPC::Command::CreateLibrarysetCommand
- Inherits:
-
BaseCommand
- Object
- BaseCommand
- EPC::Command::CreateLibrarysetCommand
- Defined in:
- lib/epc/command/libraryset/create_libraryset_command.rb
Constant Summary
Constants inherited from BaseCommand
BaseCommand::GIVEUP_TICKS, BaseCommand::SLEEP_TIME, BaseCommand::TICKER_TICKS
Instance Attribute Summary
Attributes inherited from BaseCommand
#client, #klass_name, #object_id, #object_type, #options, #target_id, #target_type
Instance Method Summary collapse
Methods inherited from BaseCommand
#check_options, #context_params, #context_params=, #go, include_module, inherited, #initialize, required_options, #say_err
Methods included from PersistentAttributes
#auth_token, #caller_id, #target_url
Constructor Details
This class inherits a constructor from EPC::Command::BaseCommand
Instance Method Details
#execute(params = []) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 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 |
# File 'lib/epc/command/libraryset/create_libraryset_command.rb', line 4 def execute(params = []) set = params[0] language = params[1] raise FatalError, "You need to specify a name for the set" if set.blank? raise FatalError, "You need to specify a language" if language.blank? params = {} params[:name] = set params[:language_id] = retrieve_identifier_for("LibraryLanguage", language) raise InputError, "Request failed: Language [#{language}] not found" if params[:language_id].blank? && @options[:file].blank? status, response, headers = client.post(EPC::Config::LIBRARY_SETS_PATH, params) if status.successful? say("Set [#{set}] created") set_id = response[:id] if @options[:file].present? libraries = EPC::Config.read_content_as_json(@options[:file]) libraries = libraries.map{|h| {:name => h["name"], :library_version => h["library_version"], :group => h["group"]}} lib_ids = retrieve_libraries(libraries) failures = [] lib_ids.each do |lib_id| status, response, headers = client.post(EPC::Config::LIBRARY_SETS_PATH + "/#{set_id}/attach_library", :library_id => lib_id) if status.successful? say("Library [#{lib_id}] added to set") failures << false else say_err("Failed to add [#{lib_id}]: [#{response[:message]}]") failures << true end end return failures.all? ? 1 : 0 end else say_err("Request failed: [#{response[:message]}]") end return status end |