Method: Ldp::Container#add

Defined in:
lib/ldp/container.rb

#add(*args) ⇒ Object

Add a new resource to the LDP container



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ldp/container.rb', line 30

def add *args
  # slug, graph
  # graph
  # slug

  case
  when (args.length > 2 || args.length == 0)

  when (args.length == 2)
    slug, graph_or_content = args
  when (args.first.is_a? RDF::Enumerable)
    slug = nil
    graph_or_content = args.first
  else
    slug = args.first
    graph_or_content = build_empty_graph
  end

  resp = client.post subject, (graph_or_content.is_a?(RDF::Enumerable) ? graph_or_content.dump(:ttl) : graph_or_content) do |req|
    req.headers['Slug'] = slug
  end

  client.find_or_initialize resp.headers['Location']
end