Class: GoogleAppsApi::UserProfiles::Api

Inherits:
BaseApi
  • Object
show all
Defined in:
lib/google_apps_api/user_profiles.rb

Instance Attribute Summary collapse

Attributes inherited from BaseApi

#domain

Instance Method Summary collapse

Methods inherited from BaseApi

#entity

Constructor Details

#initialize(*args) ⇒ Api

Returns a new instance of Api.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/google_apps_api/user_profiles.rb', line 19

def initialize(*args)
  action_list = {
    :domain_login => [:post, ':auth:/accounts/ClientLogin' ],
    :retrieve_all => [:get, ':basic_path:/full?v=3.0'],
    :retrieve_user => [:get, ':basic_path:/full/'],
    :set_emails => [:put, ':basic_path:/full/'],
    :next => [:get, '' ]
  }

  options = args.extract_options!
  domain = options[:domain]

  options.merge!(:action_hash => action_list, :auth => "https://www.google.com", :feed => "https://www.google.com", :service => "cp")
  options[:basic_path] = options[:feed] + "/m8/feeds/profiles/domain/#{options[:domain]}"



  super(options)
end

Instance Attribute Details

#tokenObject (readonly)

Returns the value of attribute token.



17
18
19
# File 'lib/google_apps_api/user_profiles.rb', line 17

def token
  @token
end

Instance Method Details

#retrieve_allObject



39
40
41
42
# File 'lib/google_apps_api/user_profiles.rb', line 39

def retrieve_all()
  response = request(:retrieve_all)
  return response.to_s
end

#retrieve_user(user) ⇒ Object



44
45
46
47
# File 'lib/google_apps_api/user_profiles.rb', line 44

def retrieve_user(user)
  response = request(:retrieve_user, :query => user + "?v=3.0")
  return response.to_s        
end

#set_emails(user, *args) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/google_apps_api/user_profiles.rb', line 49

def set_emails(user, *args)
  emails = args.extract_options!
  doc = Document.new(retrieve_user(user).to_s)
  doc.elements.each("entry/gd:email") do |e|

    e.parent.delete(e)
  end


  primary = emails.delete(:primary) || :other

  base = doc.elements["entry"]
  emails.each_pair do |loc, email|
    base.add_element("gd:email", "address" => email, "rel" => "http://schemas.google.com/g/2005##{loc.to_s}", "primary" => loc == primary ? "true" : "false")
  end

  response  = request(:set_emails,:query => user + "?v=3.0", :body => doc.to_s)

end