Class: Ape::Collection

Inherits:
Object
  • Object
show all
Defined in:
lib/ape/collection.rb

Instance Method Summary collapse

Constructor Details

#initialize(uri, authent = nil) ⇒ Collection

The argument has to be an absolute URI



13
14
15
16
# File 'lib/ape/collection.rb', line 13

def initialize(uri, authent = nil)
  @uri = uri      
  @authent = authent
end

Instance Method Details

#crumbsObject



40
41
42
# File 'lib/ape/collection.rb', line 40

def crumbs
  return @invoker.crumbs
end

#post(opts = {}) ⇒ Object

Post a new element to this collection; return either an Ape::Entry or

an error-message

Options

* :data - element to post as a string
* :type - content type. By default 'application/atom+xml;type=entry'
* :slug - slug header


26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ape/collection.rb', line 26

def post(opts = {})
  return ':data argument not provided' unless opts[:data]
  
  type = opts[:type] || Names::AtomEntryMediaType
  @invoker = Poster.new(@uri, @authent)
  @invoker['Slug'] = opts[:slug] if opts[:slug]
  
  if @invoker.post(type, opts[:data]) 
    @invoker.entry 
  else
    @invoker.last_error    
  end
end