class Osm::Member::Contact

Public Instance Methods

all_phones() click to toggle source

Get an array of all phone numbers for the contact @return [Array<String>]

# File lib/osm/member.rb, line 673
def all_phones
  [phone_1, phone_2].select{ |n| !n.blank? }.map{ |n| n.gsub(/[^\d\+]/, '') }
end
name(seperator=' ') click to toggle source

Get the full name @param [String] seperator What to split the contact's first name and last name with @return [String] this scout's full name seperated by the optional seperator

# File lib/osm/member.rb, line 667
def name(seperator=' ')
  return [first_name, last_name].select{ |i| !i.blank? }.join(seperator)
end
update(api, member, force=false) click to toggle source

Update the contact in OSM @param [Osm::Api] api The api to use to make the request @param [Osm::Member] section The member to update the contact for @param [Boolean] force Whether to force updates (ie tell OSM every attribute changed even if we don't think it did) @return [Boolean] whether the member was successfully updated or not @raise [Osm::ObjectIsInvalid] If the Contact is invalid

# File lib/osm/member.rb, line 683
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&section_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