Module: Zuck::FbObject::Write::ClassMethods

Defined in:
lib/zuck/fb_object/write.rb

Instance Method Summary collapse

Instance Method Details

#create(graph, data, parent = nil, path = nil) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/zuck/fb_object/write.rb', line 45

def create(graph, data, parent=nil, path=nil)
  raise_if_read_only
  p = path || parent.path

  # We want facebook to return the data of the created object
  data["redownload"] = 1

  # Create
  result = create_connection(graph, p, list_path, data)["data"]

  # The data is nested by name and id, e.g.
  #
  #     "campaigns" => { "12345" => "data" }
  #
  # Since we only put one at a time, we'll fetch this like that.
  data = result.values.first.values.first

  # Return a new instance
  new(graph, data, parent)
end

#destroy(graph, id) ⇒ Object



66
67
68
69
# File 'lib/zuck/fb_object/write.rb', line 66

def destroy(graph, id)
  raise_if_read_only
  delete(graph, id)
end

#raise_if_read_onlyObject



40
41
42
43
# File 'lib/zuck/fb_object/write.rb', line 40

def raise_if_read_only
  return unless read_only?
  raise Zuck::Error::ReadOnly.new("#{self} is read_only")
end