Class: GoodData::LCM2::SynchronizeNewSegments

Inherits:
BaseAction show all
Defined in:
lib/gooddata/lcm/actions/synchronize_new_segments.rb

Constant Summary collapse

DESCRIPTION =
'Synchronize New Segments'
PARAMS =
define_params(self) do
end

Constants included from Dsl::Dsl

Dsl::Dsl::DEFAULT_OPTS, Dsl::Dsl::TYPES

Class Method Summary collapse

Methods inherited from BaseAction

check_params

Methods included from Dsl::Dsl

#define_params, #define_type, #process

Class Method Details

.call(params) ⇒ Object



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
# File 'lib/gooddata/lcm/actions/synchronize_new_segments.rb', line 18

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

  params.segments.map do |segment_in|
    segment_id = segment_in.segment_id

    segment = domain_segments.find do |ds|
      ds.segment_id == segment_id
    end

    if segment_in.is_new
      segment.synchronize_clients

      {
        segment: segment_id,
        new: true,
        synchronized: true
      }
    else
      {
        segment: segment_id,
        new: false,
        synchronized: false
      }
    end
  end
end