diff --git a/lib/ews/types/contact.rb b/lib/ews/types/contact.rb index c68a82f1..f772d782 100644 --- a/lib/ews/types/contact.rb +++ b/lib/ews/types/contact.rb @@ -3,5 +3,84 @@ class Contact include Viewpoint::EWS include Viewpoint::EWS::Types include Viewpoint::EWS::Types::Item + + CONTACT_KEY_PATHS = { + given_name: [:given_name, :text], + surname: [:surname, :text], + yomi_given_name: [:yomi_given_name, :text], + yomi_surname: [:yomi_surname, :text], + display_name: [:display_name, :text], + company_name: [:company_name, :text], + yomi_company_name: [:yomi_company_name, :text], + email_addresses: [:email_addresses, :elems], + physical_addresses: [:physical_addresses, :elems], + phone_numbers: [:phone_numbers, :elems], + department: [:department, :text], + job_title: [:job_title, :text], + office_location: [:office_location, :text], + } + + CONTACT_KEY_TYPES = { + email_addresses: :build_email_addresses, + physical_addresses: :build_physical_addresses, + phone_numbers: :build_phone_numbers + } + + CONTACT_KEY_ALIAS = { + first_name: :given_name, + last_name: :surname, + yomi_first_name: :yomi_given_name, + yomi_last_name: :yomi_surname, + emails: :email_addresses, + addresses: :physical_addresses, + title: :job_title, + company: :company_name, + office: :office_location, + } + + + private + + + def build_phone_number(phone_number) + Types::PhoneNumber.new(ews, phone_number) + end + + def build_phone_numbers(phone_numbers) + return [] if phone_numbers.nil? + phone_numbers.collect { |pn| build_phone_number(pn[:entry]) } + end + + def build_email_address(email) + Types::EmailAddress.new(ews, email) + end + + def build_email_addresses(users) + return [] if users.nil? + users.collect { |u| build_email_address(u[:entry]) } + end + + def build_physical_address(address_ews) + Types::PhysicalAddress.new(ews, address_ews) + end + + def build_physical_addresses(addresses) + return [] if addresses.nil? + addresses.collect { |a| build_physical_address(a[:entry]) } + end + + def key_paths + super.merge(CONTACT_KEY_PATHS) + end + + def key_types + super.merge(CONTACT_KEY_TYPES) + end + + def key_alias + super.merge(CONTACT_KEY_ALIAS) + end + + end end diff --git a/lib/ews/types/email_address.rb b/lib/ews/types/email_address.rb new file mode 100644 index 00000000..ebc6452d --- /dev/null +++ b/lib/ews/types/email_address.rb @@ -0,0 +1,40 @@ +module Viewpoint::EWS::Types + class EmailAddress + include Viewpoint::EWS + include Viewpoint::EWS::Types + + EMAIL_ADDRESS_KEY_PATHS = { + key: [:attribs, :key], + name: [:attribs, :name], + mailbox_type: [:attribs, :mailbox_type], + email_address: [:text] + } + EMAIL_ADDRESS_KEY_TYPES = { } + EMAIL_ADDRESS_KEY_ALIAS = { + email: :email_address + } + + def initialize(ews, email_address) + @ews = ews + @ews_item = email_address + end + + + private + + + def key_paths + @key_paths ||= super.merge(EMAIL_ADDRESS_KEY_PATHS) + end + + def key_types + @key_types ||= super.merge(EMAIL_ADDRESS_KEY_TYPES) + end + + def key_alias + @key_alias ||= super.merge(EMAIL_ADDRESS_KEY_ALIAS) + end + + end # EmailAddress +end # Viewpoint::EWS::Types + diff --git a/lib/ews/types/phone_number.rb b/lib/ews/types/phone_number.rb new file mode 100644 index 00000000..9b7fdd04 --- /dev/null +++ b/lib/ews/types/phone_number.rb @@ -0,0 +1,38 @@ +module Viewpoint::EWS::Types + class PhoneNumber + include Viewpoint::EWS + include Viewpoint::EWS::Types + + PHONE_NUMBER_KEY_PATHS = { + key: [:attribs, :key], + phone_number: [:text] + } + PHONE_NUMBER_KEY_TYPES = { } + PHONE_NUMBER_KEY_ALIAS = { + name: :key + } + + def initialize(ews, phone_number) + @ews = ews + @ews_item = phone_number + end + + + private + + + def key_paths + @key_paths ||= super.merge(PHONE_NUMBER_KEY_PATHS) + end + + def key_types + @key_types ||= super.merge(PHONE_NUMBER_KEY_TYPES) + end + + def key_alias + @key_alias ||= super.merge(PHONE_NUMBER_KEY_ALIAS) + end + + end # PhoneNumber +end # Viewpoint::EWS::Types + diff --git a/lib/ews/types/physical_address.rb b/lib/ews/types/physical_address.rb new file mode 100644 index 00000000..ad95d141 --- /dev/null +++ b/lib/ews/types/physical_address.rb @@ -0,0 +1,54 @@ +module Viewpoint::EWS::Types + class PhysicalAddress + include Viewpoint::EWS + include Viewpoint::EWS::Types + + PHYSICAL_ADDRESS_KEY_PATHS = { + key: [:key], + street: [:street], + city: [:city], + state: [:state], + country_or_region: [:country_or_region], + postal_code: [:postal_code] + } + PHYSICAL_ADDRESS_KEY_TYPES = { } + PHYSICAL_ADDRESS_KEY_ALIAS = { + country: :country_or_region, + region: :country_or_region, + name: :key + } + + def initialize(ews, physical_address) + @ews = ews + @ews_item = physical_address + simplify! + end + + + private + + + def simplify! + return unless @ews_item.has_key?(:elems) + @ews_item[:key] = @ews_item[:attribs][:key] + @ews_item = @ews_item[:elems].inject({}){|m,o| + m[o.keys.first] = o.values.first[:text]; + m + } + end + + def key_paths + @key_paths ||= super.merge(PHYSICAL_ADDRESS_KEY_PATHS) + end + + def key_types + @key_types ||= super.merge(PHYSICAL_ADDRESS_KEY_TYPES) + end + + def key_alias + @key_alias ||= super.merge(PHYSICAL_ADDRESS_KEY_ALIAS) + end + + end # PhysicalAddress +end # Viewpoint::EWS::Types + diff --git a/lib/viewpoint.rb b/lib/viewpoint.rb index dfce8991..b93ea106 100644 --- a/lib/viewpoint.rb +++ b/lib/viewpoint.rb @@ -87,6 +87,9 @@ require 'ews/types/out_of_office' require 'ews/types/export_items_response_message' require 'ews/types/post_item' +require 'ews/types/physical_address' +require 'ews/types/email_address' +require 'ews/types/phone_number' # Events require 'ews/types/event'