Class: GProv::Provision::Member

Inherits:
EntryBase show all
Defined in:
lib/gprov/provision/member.rb

Instance Attribute Summary collapse

Attributes inherited from EntryBase

#connection, #status

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from EntryBase

#attributes_from_hash, #initialize, #xml_to_hash

Methods included from EntryBase::ClassMethods

#attribute_names, #attribute_titles, #attributes, #xmlattr

Constructor Details

This class inherits a constructor from GProv::Provision::EntryBase

Instance Attribute Details

#group_idObject

Returns the value of attribute group_id.



12
13
14
# File 'lib/gprov/provision/member.rb', line 12

def group_id
  @group_id
end

Class Method Details

.all(connection, group_id) ⇒ Object



14
15
16
17
18
# File 'lib/gprov/provision/member.rb', line 14

def self.all(connection, group_id)
  feed = GProv::Provision::Feed.new(connection, "/group/2.0/:domain/#{group_id}/member", "/xmlns:feed/xmlns:entry")
  entries = feed.fetch
  entries.map { |xml| new(:status => :clean, :connection => connection, :source => xml) }
end

Instance Method Details

#create!Object



37
38
39
40
# File 'lib/gprov/provision/member.rb', line 37

def create!
  response = connection.post("/group/2.0/:domain/#{@group_id}/member", {:body => to_nokogiri.to_xml})
  status = :clean
end

#delete!Object



42
43
44
45
# File 'lib/gprov/provision/member.rb', line 42

def delete!
  response = connection.delete("/group/2.0/:domain/#{@group_id}/member/#{@member_id}")
  status = :clean
end

#to_nokogiriObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/gprov/provision/member.rb', line 20

def to_nokogiri
  base_document = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
    xml.entry('xmlns:atom' => 'http://www.w3.org/2005/Atom',
              'xmlns:apps' => 'http://schemas.google.com/apps/2006',
              'xmlns:gd'   => "http://schemas.google.com/g/2005" ) {

      # Namespaces cannot be used until they are declared, so we need to
      # retroactively declare the namespace of the parent
      xml.parent.namespace = xml.parent.namespace_definitions.select {|ns| ns.prefix == "atom"}.first

      xml['apps'].property("name" => "memberId", "value" => @member_id)
    }
  end

  base_document
end