Class: Viewpoint::EWS::Contact
Overview
Represents a Contact Item in the Exchange datastore.
Constant Summary
Constants included from ItemFieldUriMap
Instance Attribute Summary
Attributes inherited from Item
#change_key, #item_id, #parent_folder_id
Attributes included from Model
#ews_methods, #ews_methods_undef
Class Method Summary collapse
-
.add_contact ⇒ Object
Create a Contact in the Exchange Data Store.
-
.create_item_from_hash(item, folder_id = :contacts) ⇒ Object
This is a class method that creates a new Contact in the Exchange Data Store.
Instance Method Summary collapse
-
#initialize(ews_item, opts = {}) ⇒ Contact
constructor
Initialize an Exchange Web Services item of type Contact.
-
#set_address(address_type, address) ⇒ Object
Set an address for this contact.
- #set_email_addresses(email1, email2 = nil, email3 = nil) ⇒ Object
-
#set_phone_number(phone_type, phone_number) ⇒ Object
Set the phone number.
Methods inherited from Item
add_attachments, #attachments, #clear_updates!, #copy, #deepen!, #delete!, get_item, #mark_read!, #mark_unread!, #move!, #parent_folder, #recycle!, #save!, #text_only=, #text_only?, #update!, #update_attribs, #update_attribs!
Constructor Details
#initialize(ews_item, opts = {}) ⇒ Contact
Initialize an Exchange Web Services item of type Contact
76 77 78 |
# File 'lib/model/contact.rb', line 76 def initialize(ews_item, opts={}) super(ews_item, opts) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Viewpoint::EWS::Item
Class Method Details
.add_contact ⇒ Object
Create a Contact in the Exchange Data Store
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/model/contact.rb', line 61 def self.add_contact() item = {} conn = Viewpoint::EWS::EWS.instance resp = conn.ews.create_contact_item() if(resp.status == 'Success') resp = resp.items.shift self.new(resp[resp.keys.first]) else raise EwsError, "Could not add contact. #{resp.code}: #{resp.}" end end |
.create_item_from_hash(item, folder_id = :contacts) ⇒ Object
This is a class method that creates a new Contact in the Exchange Data Store.
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/model/contact.rb', line 49 def self.create_item_from_hash(item, folder_id = :contacts) conn = Viewpoint::EWS::EWS.instance resp = conn.ews.create_contact_item(folder_id, item) if(resp.status == 'Success') resp = resp.items.shift self.new(resp[resp.keys.first]) else raise EwsError, "Could not create Contact. #{resp.code}: #{resp.}" end end |
Instance Method Details
#set_address(address_type, address) ⇒ Object
Set an address for this contact
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/model/contact.rb', line 123 def set_address(address_type, address) valid_types = [:business, :home, :other] raise EwsError, "Invalid address type (#{address_type}) passed to Contact#set_address." unless valid_types.index address_type valid_field_types = [:street, :city, :state, :country_or_region, :postal_code] type = self.class.name.split(/::/).last.ruby_case.to_sym v = address_type.to_s.camel_case changes = [] field = 'PhysicalAddresses' address.keys.each do |addr_item| raise EwsError, "Invalid address element (#{addr_item}) passed to Contact#set_address." unless valid_field_types.index addr_item index_field = "contacts:PhysicalAddress:#{addr_item.to_s.camel_case}" changes << {:set_item_field => [{:indexed_field_uRI => { :field_uRI => index_field, :field_index => v}}, {type => {field => {:entry => {:key => v, addr_item =>{ :text => address[addr_item]}}}}} ]} end @updates.merge!({:preformatted => changes}) {|k,v1,v2| v1 + v2} end |
#set_email_addresses(email1, email2 = nil, email3 = nil) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/model/contact.rb', line 80 def set_email_addresses(email1, email2=nil, email3=nil) changes = [] type = self.class.name.split(/::/).last.ruby_case.to_sym k = :email_addresses v = 'EmailAddress1' changes << {:set_item_field => [{:indexed_field_uRI => {:field_uRI => FIELD_URIS[k][:text], :field_index => v}}, {type=>{k => {:entry => {:key => v, :text => email1}}}}]} unless email1.nil? v = 'EmailAddress2' changes << {:set_item_field => [{:indexed_field_uRI => {:field_uRI => FIELD_URIS[k][:text], :field_index => v}}, {type=>{k => {:entry => {:key => v, :text => email2}}}}]} unless email2.nil? v = 'EmailAddress3' changes << {:set_item_field => [{:indexed_field_uRI => {:field_uRI => FIELD_URIS[k][:text], :field_index => v}}, {type=>{k => {:entry => {:key => v, :text => email3}}}}]} unless email3.nil? @updates.merge!({:preformatted => changes}) {|k,v1,v2| v1 + v2} end |
#set_phone_number(phone_type, phone_number) ⇒ Object
Set the phone number. You must give a type based on the available Exchange phone number types
102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/model/contact.rb', line 102 def set_phone_number(phone_type, phone_number) valid_types = [:assistant_phone, :business_fax, :business_phone, :business_phone2, :callback, :car_phone, :company_main_phone, :home_fax, :home_phone, :home_phone2, :isdn, :mobile_phone, :other_fax, :other_telephone, :pager, :primary_phone, :radio_phone, :telex, :tty_tdd_phone] raise EwsError, "Invalid phone type (#{phone_type}) passed to Contact#set_phone_number." unless valid_types.index phone_type type = self.class.name.split(/::/).last.ruby_case.to_sym changes = [] k = :phone_numbers v = phone_type.to_s.camel_case changes << {:set_item_field => [{:indexed_field_uRI => {:field_uRI => FIELD_URIS[k][:text], :field_index => v}}, {type=>{k => {:entry => {:key => v, :text => phone_number}}}}]} @updates.merge!({:preformatted => changes}) {|k,v1,v2| v1 + v2} end |