Module: ChartMogul::Concerns::ExternalIdOperations::ClassMethods

Defined in:
lib/chartmogul/concerns/external_id_operations.rb

Instance Method Summary collapse

Instance Method Details

#destroy_by_external_id!(data_source_uuid:, external_id:, handle_as_user_edit: nil) ⇒ Object

Delete a resource by data_source_uuid and external_id

Parameters:

  • handle_as_user_edit (Boolean) (defaults to: nil)

    If true, the change is treated as a user edit



41
42
43
44
45
46
47
48
49
50
# File 'lib/chartmogul/concerns/external_id_operations.rb', line 41

def destroy_by_external_id!(data_source_uuid:, external_id:, handle_as_user_edit: nil)
  path = build_query_path(
    resource_path.path,
    data_source_uuid: data_source_uuid,
    external_id: external_id,
    handle_as_user_edit: handle_as_user_edit
  )
  handling_errors { connection.delete(path) }
  true
end

#retrieve_by_external_id(data_source_uuid:, external_id:) ⇒ Object

Retrieve a resource by data_source_uuid and external_id



14
15
16
17
18
19
20
21
22
23
# File 'lib/chartmogul/concerns/external_id_operations.rb', line 14

def retrieve_by_external_id(data_source_uuid:, external_id:)
  path = build_query_path(
    resource_path.path,
    data_source_uuid: data_source_uuid,
    external_id: external_id
  )
  resp = handling_errors { connection.get(path) }
  json = ChartMogul::Utils::JSONParser.parse(resp.body, immutable_keys: immutable_keys)
  new_from_json(json)
end

#toggle_disabled_by_external_id!(data_source_uuid:, external_id:, disabled:, handle_as_user_edit: nil) ⇒ Object

Toggle disabled state of a resource by data_source_uuid and external_id

Parameters:

  • handle_as_user_edit (Boolean) (defaults to: nil)

    If true, the change is treated as a user edit



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/chartmogul/concerns/external_id_operations.rb', line 54

def toggle_disabled_by_external_id!(data_source_uuid:, external_id:, disabled:, handle_as_user_edit: nil)
  path = build_query_path(
    "#{resource_path.path}/disabled_state",
    data_source_uuid: data_source_uuid,
    external_id: external_id,
    handle_as_user_edit: handle_as_user_edit
  )
  resp = handling_errors { json_patch(path, { disabled: disabled }) }
  json = ChartMogul::Utils::JSONParser.parse(resp.body, immutable_keys: immutable_keys)
  new_from_json(json)
end

#update_by_external_id!(data_source_uuid:, external_id:, handle_as_user_edit: nil, **attributes) ⇒ Object

Update a resource by data_source_uuid and external_id

Parameters:

  • handle_as_user_edit (Boolean) (defaults to: nil)

    If true, the change is treated as a user edit



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/chartmogul/concerns/external_id_operations.rb', line 27

def update_by_external_id!(data_source_uuid:, external_id:, handle_as_user_edit: nil, **attributes)
  path = build_query_path(
    resource_path.path,
    data_source_uuid: data_source_uuid,
    external_id: external_id,
    handle_as_user_edit: handle_as_user_edit
  )
  resp = handling_errors { json_patch(path, attributes) }
  json = ChartMogul::Utils::JSONParser.parse(resp.body, immutable_keys: immutable_keys)
  new_from_json(json)
end