Class: Viewpoint::EWS::MailboxUser
- Inherits:
-
Object
- Object
- Viewpoint::EWS::MailboxUser
- Includes:
- Model
- Defined in:
- lib/model/mailbox_user.rb
Overview
Design a Class method that resolves to an Array of MailboxUsers
This represents a Mailbox object in the Exchange data store
Direct Known Subclasses
Instance Attribute Summary
Attributes included from Model
#ews_methods, #ews_methods_undef
Class Method Summary collapse
-
.find_user(resolve) ⇒ MailboxUser, Array
Resolve a user in the Exchange Data Store.
-
.get_user_availability(email_address, start_time, end_time) ⇒ Object
Get information about when the user with the given email address is available.
Instance Method Summary collapse
-
#add_delegate!(delegate_email, permissions) ⇒ true
Adds one or more delegates to a principal’s mailbox and sets specific access permissions.
- #get_delegate_info ⇒ Object
- #get_oof ⇒ Object
-
#get_user_availability(start_time, end_time) ⇒ Object
Get information about when this user is available.
-
#initialize(mbox_user) ⇒ MailboxUser
constructor
A new instance of MailboxUser.
- #update_delegate!(delegate_email, permissions) ⇒ Object
Constructor Details
#initialize(mbox_user) ⇒ MailboxUser
Returns a new instance of MailboxUser.
64 65 66 67 68 |
# File 'lib/model/mailbox_user.rb', line 64 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
-
rename “resolve” to something more descriptive
-
standardize on a common return type???
Resolve a user in the Exchange Data Store
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/model/mailbox_user.rb', line 35 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.}" end end |
.get_user_availability(email_address, start_time, end_time) ⇒ Object
Get information about when the user with the given email address is available.
55 56 57 58 59 60 61 62 |
# File 'lib/model/mailbox_user.rb', line 55 def self.get_user_availability(email_address, start_time, end_time) resp = (Viewpoint::EWS::EWS.instance).ews.get_user_availability(email_address, start_time, end_time) if(resp.status == 'Success') return resp.items else raise EwsError, "GetUserAvailability produced an error: #{resp.code}: #{resp.}" 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
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/model/mailbox_user.rb', line 103 def add_delegate!(delegate_email, ) # 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 .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.}" end end |
#get_delegate_info ⇒ Object
135 136 137 138 139 140 141 142 |
# File 'lib/model/mailbox_user.rb', line 135 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_oof ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/model/mailbox_user.rb', line 70 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 |
#get_user_availability(start_time, end_time) ⇒ Object
Get information about when this user is available.
87 88 89 |
# File 'lib/model/mailbox_user.rb', line 87 def get_user_availability(start_time, end_time) return MailboxUser.get_user_availability(self.email_address, start_time, end_time) end |
#update_delegate!(delegate_email, permissions) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/model/mailbox_user.rb', line 120 def update_delegate!(delegate_email, ) # Modify permissions so we can pass it to the builders formatted_perms = {} .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.}" end end |