Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EWS Types Contact, EmailAddress, PhysicalAddress & PhoneNumber #259

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions lib/ews/types/contact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
40 changes: 40 additions & 0 deletions lib/ews/types/email_address.rb
Original file line number Diff line number Diff line change
@@ -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

38 changes: 38 additions & 0 deletions lib/ews/types/phone_number.rb
Original file line number Diff line number Diff line change
@@ -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

54 changes: 54 additions & 0 deletions lib/ews/types/physical_address.rb
Original file line number Diff line number Diff line change
@@ -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

3 changes: 3 additions & 0 deletions lib/viewpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down