class GoodData::LCM2::SynchronizeNewSegments

Constants

DESCRIPTION
PARAMS

Public Class Methods

call(params) click to toggle source
# File lib/gooddata/lcm/actions/synchronize_new_segments.rb, line 35
def call(params)
  client = params.gdc_gd_client

  domain_name = params.organization || params.domain
  fail "Either organisation or domain has to be specified in params" unless domain_name
  domain = client.domain(domain_name) || fail("Invalid domain name specified - #{domain_name}")
  data_product = params.data_product
  domain_segments = domain.segments(:all, data_product)

  params.segments.pmap 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