Class: ET::Folders

Inherits:
BaseObject show all
Defined in:
lib/exact-target-api/folders.rb

Instance Attribute Summary

Attributes inherited from BaseObject

#client, #endpoint, #lastRequestID, #obj, #props

Instance Method Summary collapse

Methods inherited from BaseObject

#stringify_keys!, #symbolize_keys!

Constructor Details

#initialize(client) ⇒ Folders

Returns a new instance of Folders.



3
4
5
6
7
# File 'lib/exact-target-api/folders.rb', line 3

def initialize(client)
  @client = client


end

Instance Method Details

#create(name, parent_folder_id, description = '', options = {}) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/exact-target-api/folders.rb', line 41

def create(name, parent_folder_id, description = '', options = {})
  stringify_keys!(options)

  folder = ET::Folder.new
  folder.client = @client
  data = {
    "CustomerKey" => name,
    "Name" => name,
    "ContentType"=> "EMAIL",
    "ParentFolder" => {"ID" => parent_folder_id},
    "Description" => description
  }.merge(options)

  res = folder.post(data)
  if res.results[0] && (id = res.results[0][:new_id]).to_i > 0
    id
  end
end

#find(name) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/exact-target-api/folders.rb', line 18

def find(name)
  folder = ET::Folder.new
  folder.client = @client
  props = ["ID"]
  filter = {
    'LeftOperand' => {
      'Property' => 'Name',
      'SimpleOperator' => 'equals',
      'Value' => name
    },
    'LogicalOperator' => 'AND',
    'RightOperand' => {
      'Property' => 'ContentType',
      'SimpleOperator' => 'equals',
      'Value' => 'EMAIL'
    }
  }
  res = folder.get(props, filter)

  res.results[0][:id] if res.results[0]
end

#find_or_create(name, parent_folder_id, description = '', options = {}) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/exact-target-api/folders.rb', line 9

def find_or_create(name, parent_folder_id, description = '', options = {})
  if (folder_id = find(name))
    folder_id
  else
    create(name, parent_folder_id, description, options)
  end
end