Class: Osm::Member::Contact
- Inherits:
-
Osm::Model
- Object
- Osm::Model
- Osm::Member::Contact
- Defined in:
- lib/osm/member.rb
Direct Known Subclasses
DoctorContact, EmergencyContact, MemberContact, PrimaryContact
Instance Attribute Summary collapse
-
#additional_information ⇒ DirtyHashy
The additional information (key is OSM’s variable name, value is the data).
-
#additional_information_labels ⇒ DirtyHashy
The labels for the additional information (key is OSM’s variable name, value is the label).
-
#address_1 ⇒ String
The 1st line of the address.
-
#address_2 ⇒ String
The 2nd line of the address.
-
#address_3 ⇒ String
The 3rd line of the address.
-
#address_4 ⇒ String
The 4th line of the address.
-
#first_name ⇒ String
The contact’s first name.
-
#last_name ⇒ String
The contact’s last name.
-
#phone_1 ⇒ String
The primary phone number.
-
#phone_2 ⇒ String
The secondary phone number.
-
#postcode ⇒ String
The postcode of the address.
Instance Method Summary collapse
-
#all_phones ⇒ Array<String>
Get an array of all phone numbers for the contact.
-
#initialize ⇒ Object
constructor
Initialize a new Contact.
-
#name(seperator = ' ') ⇒ String
Get the full name.
-
#update(api, member, force = false) ⇒ Boolean
Update the contact in OSM.
Methods inherited from Osm::Model
#<, #<=, #<=>, #>, #>=, #between?, #changed_attributes, configure, #reset_changed_attributes, #to_i
Constructor Details
#initialize ⇒ Object
Initialize a new Contact
|
# File 'lib/osm/member.rb', line 657
|
Instance Attribute Details
#additional_information ⇒ DirtyHashy
Returns the additional information (key is OSM’s variable name, value is the data).
638 |
# File 'lib/osm/member.rb', line 638 attribute :first_name, :type => String |
#additional_information_labels ⇒ DirtyHashy
Returns the labels for the additional information (key is OSM’s variable name, value is the label).
638 |
# File 'lib/osm/member.rb', line 638 attribute :first_name, :type => String |
#address_1 ⇒ String
Returns the 1st line of the address.
638 |
# File 'lib/osm/member.rb', line 638 attribute :first_name, :type => String |
#address_2 ⇒ String
Returns the 2nd line of the address.
638 |
# File 'lib/osm/member.rb', line 638 attribute :first_name, :type => String |
#address_3 ⇒ String
Returns the 3rd line of the address.
638 |
# File 'lib/osm/member.rb', line 638 attribute :first_name, :type => String |
#address_4 ⇒ String
Returns the 4th line of the address.
638 |
# File 'lib/osm/member.rb', line 638 attribute :first_name, :type => String |
#first_name ⇒ String
Returns the contact’s first name.
638 |
# File 'lib/osm/member.rb', line 638 attribute :first_name, :type => String |
#last_name ⇒ String
Returns the contact’s last name.
638 |
# File 'lib/osm/member.rb', line 638 attribute :first_name, :type => String |
#phone_1 ⇒ String
Returns the primary phone number.
638 |
# File 'lib/osm/member.rb', line 638 attribute :first_name, :type => String |
#phone_2 ⇒ String
Returns the secondary phone number.
638 |
# File 'lib/osm/member.rb', line 638 attribute :first_name, :type => String |
#postcode ⇒ String
Returns the postcode of the address.
638 |
# File 'lib/osm/member.rb', line 638 attribute :first_name, :type => String |
Instance Method Details
#all_phones ⇒ Array<String>
Get an array of all phone numbers for the contact
670 671 672 |
# File 'lib/osm/member.rb', line 670 def all_phones [phone_1, phone_2].select{ |n| !n.blank? }.map{ |n| n.gsub(/[^\d\+]/, '') } end |
#name(seperator = ' ') ⇒ String
Get the full name
664 665 666 |
# File 'lib/osm/member.rb', line 664 def name(seperator=' ') return [first_name, last_name].select{ |i| !i.blank? }.join(seperator) end |
#update(api, member, force = false) ⇒ Boolean
Update the contact in OSM
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 |
# File 'lib/osm/member.rb', line 680 def update(api, member, force=false) raise Osm::ObjectIsInvalid, 'member is invalid' unless valid? require_ability_to(api, :write, :member, member.section_id) attribute_map = { 'first_name' => 'data[firstname]', 'last_name' => 'data[lastname]', 'surgery' => 'data[surgery]', 'address_1' => 'data[address1]', 'address_2' => 'data[address2]', 'address_3' => 'data[address3]', 'address_4' => 'data[address4]', 'postcode' => 'data[postcode]', 'phone_1' => 'data[phone1]', 'receive_phone_1' => 'data[phone1_sms]', 'phone_2' => 'data[phone2]', 'receive_phone_2' => 'data[phone2_sms]', 'email_1' => 'data[email1]', 'receive_email_1' => 'data[email1_leaders]', 'email_2' => 'data[email2]', 'receive_email_2' => 'data[email2_leaders]', } # our name => OSM name data = {} attributes.keys.select{ |a| !['additional_information', 'additional_information_labels'].include?(a) }.select{ |a| force || changed_attributes.include?(a) }.each do |attr| value = send(attr) value = 'yes' if value.eql?(true) data[attribute_map[attr]] = value end additional_information.keys.select{ |a| force || additional_information.changes.keys.include?(a) }.each do |attr| data["data[#{attr}]"] = additional_information[attr] end updated = true unless data.empty? result = api.perform_query("ext/customdata/?action=update§ion_id=#{member.section_id}", { 'associated_id' => member.id, 'associated_type' => 'member', 'context' => 'members', 'group_id' => self.class::GROUP_ID, }.merge(data)) updated = result.is_a?(Hash) && result['status'].eql?(true) end # Finish off if updated reset_changed_attributes additional_information.clean_up! end return updated end |