From 74e0532c719c82eb3ae9f5f441db87bbef194185 Mon Sep 17 00:00:00 2001 From: brianarpie Date: Fri, 17 Mar 2017 14:29:46 -0400 Subject: [PATCH 1/2] support contact type --- lib/ews/types/contact.rb | 69 +++++++++++++++++++++++++++++++ lib/ews/types/email_address.rb | 40 ++++++++++++++++++ lib/ews/types/physical_address.rb | 54 ++++++++++++++++++++++++ lib/viewpoint.rb | 2 + 4 files changed, 165 insertions(+) create mode 100644 lib/ews/types/email_address.rb create mode 100644 lib/ews/types/physical_address.rb diff --git a/lib/ews/types/contact.rb b/lib/ews/types/contact.rb index c68a82f1..419758de 100644 --- a/lib/ews/types/contact.rb +++ b/lib/ews/types/contact.rb @@ -3,5 +3,74 @@ 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 + } + + 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, + job: :job_title, + company: :company_name, + office: :office_location, + } + + + private + + + 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/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..ae5cbbd4 100644 --- a/lib/viewpoint.rb +++ b/lib/viewpoint.rb @@ -87,6 +87,8 @@ 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' # Events require 'ews/types/event' From bdfd2c184edeabe5b30887cf505abce87b844a72 Mon Sep 17 00:00:00 2001 From: brianarpie Date: Mon, 20 Mar 2017 14:14:16 -0400 Subject: [PATCH 2/2] add phone_number type --- lib/ews/types/contact.rb | 14 +++++++++++-- lib/ews/types/phone_number.rb | 38 +++++++++++++++++++++++++++++++++++ lib/viewpoint.rb | 1 + 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 lib/ews/types/phone_number.rb diff --git a/lib/ews/types/contact.rb b/lib/ews/types/contact.rb index 419758de..f772d782 100644 --- a/lib/ews/types/contact.rb +++ b/lib/ews/types/contact.rb @@ -22,7 +22,8 @@ class Contact CONTACT_KEY_TYPES = { email_addresses: :build_email_addresses, - physical_addresses: :build_physical_addresses + physical_addresses: :build_physical_addresses, + phone_numbers: :build_phone_numbers } CONTACT_KEY_ALIAS = { @@ -32,7 +33,7 @@ class Contact yomi_last_name: :yomi_surname, emails: :email_addresses, addresses: :physical_addresses, - job: :job_title, + title: :job_title, company: :company_name, office: :office_location, } @@ -41,6 +42,15 @@ class Contact 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 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/viewpoint.rb b/lib/viewpoint.rb index ae5cbbd4..b93ea106 100644 --- a/lib/viewpoint.rb +++ b/lib/viewpoint.rb @@ -89,6 +89,7 @@ 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'