Top Level Namespace

Defined Under Namespace

Modules: PlatformLib

Instance Method Summary collapse

Instance Method Details

#sync_guid_with_id(user, pass) ⇒ 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
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/scripts/sync_guid_with_id.rb', line 18

def sync_guid_with_id(user, pass)

  service = PlatformLib::DataService.new(user, pass)

  params = {
    fields: "id,guid",
    schema: "1.6.0",
    form: "cjson",
    byCustomValue: "{mDialogIngestSuccess}{true}",
    range: "1-100",
    sort: "added|desc",
    account: "Shaw - GlobalTV"
  }

  update_params = {
    schema: "1.2",
    account: "Shaw - GlobalTV"
  }

  items = []

  begin
    service.media_service.get_media_items(params) do |item|
      # these are the old items
      next if item.guid =~ /\A\d+\z/

      if item.guid != item.id.split('/').last
        item.guid = item.id.split('/').last.to_s
        items << item
      end
    end

    # update the items
    items.each { |item| item.guid = item.id.split('/').last }

    if items.empty?
      puts "All items are up to date."
    else
      service.media_service.update_media_items(items, update_params)
      puts "Updated #{items.size} items."
    end
  ensure
    service.sign_out
  end
end