Create or update a contact record based on if it has a contact_id or contact_number.
770470
def save_contact(contact)
      request_xml = contact.to_xml

      response_xml = nil
      create_or_save = nil
      if contact.contact_id.nil? && contact.contact_number.nil?
        # Create new contact record.
        response_xml = http_put(@client, "#{@xero_url}/Contacts", request_xml, {})
        create_or_save = :create
      else
        # Update existing contact record.
        response_xml = http_post(@client, "#{@xero_url}/Contacts", request_xml, {})
        create_or_save = :save
      end

      response = parse_response(response_xml, {:request_xml => request_xml}, {:request_signature => "#{create_or_save == :create ? 'PUT' : 'POST'}/contact"})
      contact.contact_id = response.contact.contact_id if response.contact && response.contact.contact_id
      response
    end
969469
def _create_record(self, rtype, name, content):
        """"""
        found = self._list_records(rtype=rtype, name=name, content=content)
        if found:
            return True

        record = self._create_request_record(None, rtype, name, content,
                                             self._get_lexicon_option('ttl'),
                                             self._get_lexicon_option('priority'))

        self._request_add_dns_record(record)
        return True
1269484
def update_or_create(self, attributes, values=None, joining=None, touch=True):
        
        if values is None:
            values = {}

        instance = self._query.where(attributes).first()

        if instance is None:
            return self.create(values, joining, touch)

        instance.fill(**values)

        instance.save({"touch": False})

        return instance
995679
def lookup_hlr_create(self, phonenumber, params=None):
        """"""
        if params is None: params = {}
        return HLR().load(self.request('lookup/' + str(phonenumber) + '/hlr', 'POST', params))
614015
def editContactItem(self, contact, label, number):
        
        contact.label = label
        contact.number = number
405856
def _apply_Create(self, change):
        '''
        '''
        ar = _AzureRecord(self._resource_group, change.new)
        create = self._dns_client.record_sets.create_or_update

        create(resource_group_name=ar.resource_group,
               zone_name=ar.zone_name,
               relative_record_set_name=ar.relative_record_set_name,
               record_type=ar.record_type,
               parameters=ar.params)

        self.log.debug('*  Success Create/Update: {}'.format(ar))
207644
def update_contact(self, um_from_user, um_to_user, message):
        
        contact, created = self.get_or_create(um_from_user,
                                              um_to_user,
                                              message)

        # If the contact already existed, update the message
        if not created:
            contact.latest_message = message
            contact.save()
        return contact
925362
def _init_records(self, record_types):
        """"""
        for record_type in record_types:
            # This conditional was inserted on 7/11/14. It may prove problematic:
            if str(record_type) not in self._my_map['recordTypeIds']:
                record_initialized = self._init_record(str(record_type))
                if record_initialized:
                    self._my_map['recordTypeIds'].append(str(record_type))
214432
def get_or_create(self, um_from_user, um_to_user, message):
        
        created = False
        try:
            contact = self.get(Q(um_from_user=um_from_user, um_to_user=um_to_user) |
                               Q(um_from_user=um_to_user, um_to_user=um_from_user))

        except self.model.DoesNotExist:
            created = True
            contact = self.create(um_from_user=um_from_user,
                                  um_to_user=um_to_user,
                                  latest_message=message)

        return (contact, created)
1201252
function update($id, $save_cols)
    {
        $updated   = false;
        $write_sql = array();
        $record    = $this->get_record($id, true);
        $save_cols = $this->convert_save_data($save_cols, $record);

        foreach ($save_cols as $col => $value) {
            $write_sql[] = sprintf("%s=%s", $this->db->quote_identifier($col), $this->db->quote($value));
        }

        if (!empty($write_sql)) {
            $this->db->query(
                "UPDATE " . $this->db->table_name($this->db_name, true).
                " SET `changed` = ".$this->db->now().", ".join(', ', $write_sql).
                " WHERE `contact_id` = ?".
                    " AND `user_id` = ?".
                    " AND `del` <> 1",
                $id,
                $this->user_id
            );

            $updated = $this->db->affected_rows();
            $this->result = null;  // clear current result (from get_record())
        }

        return !empty($updated);
    }
974947
public function setContactId($v)
    {
        if ($v !== null) {
            $v = (int) $v;
        }

        if ($this->contact_id !== $v) {
            $this->contact_id = $v;
            $this->modifiedColumns[DealerContactInfoVersionTableMap::CONTACT_ID] = true;
        }


        return $this;
    }
1288121
def _create_record(self, rtype, name, content):
        """"""
        if not self._list_records(rtype, name, content):
            self._update_records([{}], {
                'type': rtype,
                'hostname': self._relative_name(name),
                'destination': content,
                'priority': self._get_lexicon_option('priority'),
            })
        LOGGER.debug('create_record: %s', True)
        return True
492669
def update_record(cls, fqdn, name, type, value, ttl, content):
        """"""
        data = {
            "rrset_name": name,
            "rrset_type": type,
            "rrset_values": value,
        }
        if ttl:
            data['rrset_ttl'] = int(ttl)
        meta = cls.get_fqdn_info(fqdn)
        if content:
            url = meta['domain_records_href']
            kwargs = {'headers': {'Content-Type': 'text/plain'},
                      'data': content}
            return cls.json_put(url, **kwargs)

        url = '%s/domains/%s/records/%s/%s' % (cls.api_url, fqdn, name, type)
        return cls.json_put(url, data=json.dumps(data))
611280
def update(self,record,**kw):
        """"""
        vals = self._make_sql_params(kw)
        sql = "UPDATE %s SET %s WHERE rowid=?" %(self.name,
            ",".join(vals))
        self.cursor.execute(sql,kw.values()+[record['__id__']])
802935
def update_or_create(self, *args, **kwargs):
        
        obj, created = super().update_or_create(*args, **kwargs)

        if not created:
            return self.with_signal(result=(obj, created))

        return obj, created
1045552
def update(cls):
        
        ifaddrs = getifaddrs()
        # Create new interfaces
        for ifname in ifaddrs.keys():
            if filter(ifname.startswith, cls.NAME_FILTER):
                cls.objects.get_or_create(name=ifname)

        # Delete no longer existing ones
        cls.objects.exclude(name__in=ifaddrs.keys()).delete()
549544
def create_or_update(cls, object_version, key, value):
        """"""
        assert len(key) < 256
        assert len(value) < 256
        obj = cls.get(object_version, key)
        if obj:
            obj.value = value
            db.session.merge(obj)
        else:
            obj = cls.create(object_version, key, value)
        return obj