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
Instance Method Summary collapse
Methods inherited from BaseCommand
#go, inherited, #initialize, #method_missing, required_arguments_count, required_options, #respond_to?
Methods included from PersistentAttributes
#auth_token, #caller_id, #target_url
Constructor Details
This class inherits a constructor from EPC::Command::BaseCommand
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class 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 49 50 51 52 |
# File 'lib/epc/command/libraryset/create_libraryset_command.rb', line 4 def execute(*params) set = params[1] language = params[2] 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 if numeric?(language) language_id = language.to_i else language_id = get_resource_id(EPC::Config::LIBRARY_LANGUAGES_PATH, :name, language, :case_sensitivity => false) end params[:language_id] = language_id 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("Failed to add [#{lib_id}]: [#{response[:message]}]") failures << true end end return failures.all? ? 1 : 0 end else say("Request failed: [#{response[:message]}]") end return status end |