Class: GoodData::LCM2::CollectSegments
- Inherits:
-
BaseAction
- Object
- BaseAction
- GoodData::LCM2::CollectSegments
- Defined in:
- lib/gooddata/lcm/actions/collect_segments.rb
Constant Summary collapse
- DESCRIPTION =
'Collect Segments from API'- PARAMS =
define_params(self) do description 'Client Used for Connecting to GD' param :gdc_gd_client, instance_of(Type::GdClientType), required: true description 'Organization Name' param :organization, instance_of(Type::StringType), required: true end
Constants included from Dsl::Dsl
Dsl::Dsl::DEFAULT_OPTS, Dsl::Dsl::TYPES
Class Method Summary collapse
Methods inherited from BaseAction
Methods included from Dsl::Dsl
#define_params, #define_type, #process
Class Method Details
.call(params) ⇒ Object
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/gooddata/lcm/actions/collect_segments.rb', line 23 def call(params) # Check if all required parameters were passed BaseAction.check_params(PARAMS, params) client = params.gdc_gd_client domain_name = params.organization || params.domain domain = client.domain(domain_name) || fail("Invalid domain name specified - #{domain_name}") domain_segments = domain.segments if params.segments_filter domain_segments.select! do |segment| params.segments_filter.include?(segment.segment_id) end end segments = domain_segments.map do |segment| project = nil begin project = segment.master_project rescue RestClient::BadRequest => e params.gdc_logger.error "Failed to retrieve master project for segment #{segment.id}. Error: #{e}" raise end raise "Master project for segment #{segment.id} doesn't exist." unless project { segment_id: segment.segment_id, development_pid: project.pid, driver: project.driver.downcase, master_name: project.title } end segments.compact! # Return results { results: segments, params: { segments: segments } } end |