Class: Viewpoint::EWS::MailboxUser

Inherits:
Object
  • Object
show all
Includes:
Model
Defined in:
lib/model/mailbox_user.rb

Overview

TODO:

Design a Class method that resolves to an Array of MailboxUsers

This represents a Mailbox object in the Exchange data store

See Also:

Direct Known Subclasses

Attendee

Instance Attribute Summary

Attributes included from Model

#ews_methods, #ews_methods_undef

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mbox_user) ⇒ MailboxUser

Returns a new instance of MailboxUser.



48
49
50
51
52
# File 'lib/model/mailbox_user.rb', line 48

def initialize(mbox_user)
  super() # Calls initialize in Model (creates @ews_methods Array)
  @ews_item = mbox_user
  define_str_var :name, :email_address, :routing_type, :mailbox_type, :item_id
end

Class Method Details

.find_user(resolve) ⇒ MailboxUser, Array

Resolve a user in the Exchange Data Store

Parameters:

  • A (String)

    user to resolve to.

Returns:

  • (MailboxUser, Array)

    If it resolves to one user then it returns a MailboxUser. If it resolves to more than one user an Array of MailboxUsers are returned. If an error ocurrs an exception is raised.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/model/mailbox_user.rb', line 33

def self.find_user(resolve)
  resp = (Viewpoint::EWS::EWS.instance).ews.resolve_names(resolve)
  if(resp.status == 'Success')
    return self.new(resp.items.first[:mailbox])
  elsif(resp.code == 'ErrorNameResolutionMultipleResults')
    users = []
    resp.items.each do |u|
      users << self.new(u[:mailbox])
    end
    return users
  else
    raise EwsError, "Find User produced an error: #{resp.code}: #{resp.message}"
  end
end

Instance Method Details

#add_delegate!(delegate_email, permissions) ⇒ true

Adds one or more delegates to a principal’s mailbox and sets specific access permissions

Parameters:

  • delegate_email (String, MailboxUser)

    The user you would like to give delegate access to. This can either be a simple String e-mail address or you can pass in a MailboxUser object.

  • permissions (Hash)

    A hash of folder type keys and permission type values. An example would be => ‘Editor’. Possible keys are: :calendar_folder_permission_level, :tasks_folder_permission_level, :inbox_folder_permission_level :contacts_folder_permission_level, :notes_folder_permission_level, :journal_folder_permission_level and possible values are: None/Editor/Reviewer/Author/Custom

Returns:

  • (true)

    This method either returns true or raises an error with the message as to why this operation did not succeed.

See Also:



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/model/mailbox_user.rb', line 79

def add_delegate!(delegate_email, permissions)
  # Use a new hash so the passed hash is not modified in case we are in a loop.
  # Thanks to Markus Roberts for pointing this out.
  formatted_perms = {}
  # Modify permissions so we can pass it to the builders
  permissions.each_pair do |k,v|
    formatted_perms[k] = {:text => v}
  end

  resp = (Viewpoint::EWS::EWS.instance).ews.add_delegate(self.email_address, delegate_email, formatted_perms)
  if(resp.status == 'Success')
    return true
  else
    raise EwsError, "Could not add delegate access for user #{delegate_email}: #{resp.code}, #{resp.message}"
  end
end

#get_delegate_infoObject



111
112
113
114
115
116
117
118
# File 'lib/model/mailbox_user.rb', line 111

def get_delegate_info()
  resp = (Viewpoint::EWS::EWS.instance).ews.get_delegate(self.email_address)
 # if(resp.status == 'Success')
 #   return true
 # else
 #   raise EwsError, "Could not update delegate access for user #{delegate_email}: #{resp.code}, #{resp.message}"
 # end
end

#get_oofObject



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/model/mailbox_user.rb', line 54

def get_oof
  mailbox = {:mailbox => {:address => {:text => email_address}}}
  resp = (Viewpoint::EWS::EWS.instance).ews.get_user_oof_settings(mailbox)
  s = resp[:oof_settings]
  @oof_state = s[:oof_state][:text]
  @oof_ext_audience = s[:external_audience][:text]
  @oof_start = DateTime.parse(s[:duration][:start_time][:text])
  @oof_end = DateTime.parse(s[:duration][:end_time][:text])
  @oof_internal_reply = s[:internal_reply][:message][:text]
  @oof_external_reply = s[:internal_reply][:message][:text]
  true
end

#update_delegate!(delegate_email, permissions) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/model/mailbox_user.rb', line 96

def update_delegate!(delegate_email, permissions)
  # Modify permissions so we can pass it to the builders
  formatted_perms = {}
  permissions.each_pair do |k,v|
    formatted_perms[k] = {:text => v}
  end

  resp = (Viewpoint::EWS::EWS.instance).ews.update_delegate(self.email_address, delegate_email, formatted_perms)
  if(resp.status == 'Success')
    return true
  else
    raise EwsError, "Could not update delegate access for user #{delegate_email}: #{resp.code}, #{resp.message}"
  end
end