Class: GProv::Provision::OrgMember

Inherits:
EntryBase
  • Object
show all
Defined in:
lib/gprov/provision/orgmember.rb

Instance Attribute Summary

Attributes inherited from EntryBase

#connection, #status

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from EntryBase

#attributes_from_hash, #xml_to_hash

Methods included from EntryBase::ClassMethods

#attribute_names, #attribute_titles, #attributes, #xmlattr

Constructor Details

#initialize(opts = {}) ⇒ OrgMember

This attribute will only be sent and never received



54
55
56
57
58
# File 'lib/gprov/provision/orgmember.rb', line 54

def initialize(opts={})
  super
  # Generate this variable in the case that the org_unit_path is updated
  @old_org_unit_path = @org_unit_path
end

Class Method Details

.all(connection, options = {:target => :all}) ⇒ Object

Retrieve all organization users in the domain.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/gprov/provision/orgmember.rb', line 27

def self.all(connection, options = {:target => :all})
  id = GProv::Provision::CustomerID.get(connection)

  case options[:target]
  when :orgunit
    # XXX validation
    url = "/orguser/2.0/#{id.customer_id}?get=children&orgUnitPath=#{options[:orgunit]}"
  when :all
    url = "/orguser/2.0/#{id.customer_id}?get=all"
  end

  feed = GProv::Provision::Feed.new(connection, url, "/xmlns:feed/xmlns:entry")
  entries = feed.fetch
  entries.map { |xml| new(:status => :clean, :connection => connection, :source => xml) }
end

.get(connection, email) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/gprov/provision/orgmember.rb', line 43

def self.get(connection, email)
  id = GProv::Provision::CustomerID.get(connection)
  response = connection.get("/orguser/2.0/#{id.customer_id}/#{email}")

  document = Nokogiri::XML(response.body)
  xml = document.root

  new(:status => :clean, :connection => connection, :source => xml)
end

Instance Method Details

#to_nokogiriObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/gprov/provision/orgmember.rb', line 60

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" => "orgUnitPath", "value" => @org_unit_path)
      xml['apps'].property("name" => "oldOrgUnitPath", "value" => @old_org_unit_path)
    }
  end
end

#update!Object



76
77
78
79
80
# File 'lib/gprov/provision/orgmember.rb', line 76

def update!
  id = GProv::Provision::CustomerID.get(connection)
  response = connection.put("/orguser/2.0/#{id.customer_id}/#{@org_user_email}", {:body => to_nokogiri.to_xml})
  status = :clean
end