// CreateContact creates a new contact.
//
// See https://developer.dnsimple.com/v2/contacts/#create
510170
func (s *ContactsService) CreateContact(accountID string, contactAttributes Contact) (*contactResponse, error) {
	path := versioned(contactPath(accountID, 0))
	contactResponse := &contactResponse{}

	resp, err := s.client.post(path, contactAttributes, contactResponse)
	if err != nil {
		return nil, err
	}

	contactResponse.HttpResponse = resp
	return contactResponse, nil
}
252404
func ListContacts(c *messagebird.Client, groupID string, options *ListOptions) (*contact.ContactList, error) {
	query, err := listQuery(options)
	if err != nil {
		return nil, err
	}

	formattedPath := fmt.Sprintf("%s/%s/%s?%s", path, groupID, contactPath, query)

	contacts := &contact.ContactList{}
	if err = c.Request(contacts, http.MethodGet, formattedPath, nil); err != nil {
		return nil, err
	}

	return contacts, nil
}
26022
func (s *VPNService) CreateVpnConnection(p *CreateVpnConnectionParams) (*CreateVpnConnectionResponse, error) {
	resp, err := s.cs.newRequest("createVpnConnection", p.toURLValues())
	if err != nil {
		return nil, err
	}

	var r CreateVpnConnectionResponse
	if err := json.Unmarshal(resp, &r); err != nil {
		return nil, err
	}

	// If we have a async client, we need to wait for the async result
	if s.cs.async {
		b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
		if err != nil {
			if err == AsyncTimeoutErr {
				return &r, err
			}
			return nil, err
		}

		b, err = getRawValue(b)
		if err != nil {
			return nil, err
		}

		if err := json.Unmarshal(b, &r); err != nil {
			return nil, err
		}
	}

	return &r, nil
}
536220
func (s *PutInvitationConfigurationInput) SetContactEmail(v string) *PutInvitationConfigurationInput {
	s.ContactEmail = &v
	return s
}
441236
func (user *User) ContactInfo() *ContactInfo {
	// Errors should never occurs, since values are stored in db after have been controlled
	yahoo, _ := mail.ParseAddress(user.Profile.Yahoo)
	website, _ := url.Parse(user.Profile.Website)
	github, _ := url.Parse(user.Profile.Github)
	facebook, _ := url.Parse(user.Profile.Facebook)
	twitter, _ := url.Parse(user.Profile.Twitter)

	// Set Address.Name field
	emailName := user.Name + " " + user.Surname
	// yahoo address can be nil
	if yahoo != nil {
		yahoo.Name = emailName
	}

	return &ContactInfo{
		Website:  website,
		GitHub:   github,
		Skype:    user.Profile.Skype,
		Jabber:   user.Profile.Jabber,
		Yahoo:    yahoo,
		Facebook: facebook,
		Twitter:  twitter,
		Steam:    user.Profile.Steam}
}
1162118
func NewContract(caller ContractRef, object ContractRef, value *big.Int, gas uint64) *Contract {
	c := &Contract{CallerAddress: caller.Address(), caller: caller, self: object}

	if parent, ok := caller.(*Contract); ok {
		// Reuse JUMPDEST analysis from parent context if available.
		c.jumpdests = parent.jumpdests
	} else {
		c.jumpdests = make(map[common.Hash]bitvec)
	}

	// Gas should be a pointer so it can safely be reduced through the run
	// This pointer will be off the state transition
	c.Gas = gas
	// ensures a value is set
	c.value = value

	return c
}
970288
func (ac *addrConn) createTransport(addr resolver.Address, copts transport.ConnectOptions, connectDeadline time.Time) (transport.ClientTransport, *grpcsync.Event, error) {
	prefaceReceived := make(chan struct{})
	onCloseCalled := make(chan struct{})
	reconnect := grpcsync.NewEvent()

	target := transport.TargetInfo{
		Addr:      addr.Addr,
		Metadata:  addr.Metadata,
		Authority: ac.cc.authority,
	}

	onGoAway := func(r transport.GoAwayReason) {
		ac.mu.Lock()
		ac.adjustParams(r)
		ac.mu.Unlock()
		reconnect.Fire()
	}

	onClose := func() {
		close(onCloseCalled)
		reconnect.Fire()
	}

	onPrefaceReceipt := func() {
		close(prefaceReceived)
	}

	connectCtx, cancel := context.WithDeadline(ac.ctx, connectDeadline)
	defer cancel()
	if channelz.IsOn() {
		copts.ChannelzParentID = ac.channelzID
	}

	newTr, err := transport.NewClientTransport(connectCtx, ac.cc.ctx, target, copts, onPrefaceReceipt, onGoAway, onClose)
	if err != nil {
		// newTr is either nil, or closed.
		grpclog.Warningf("grpc: addrConn.createTransport failed to connect to %v. Err :%v. Reconnecting...", addr, err)
		return nil, nil, err
	}

	if ac.dopts.reqHandshake == envconfig.RequireHandshakeOn {
		select {
		case <-time.After(connectDeadline.Sub(time.Now())):
			// We didn't get the preface in time.
			newTr.Close()
			grpclog.Warningf("grpc: addrConn.createTransport failed to connect to %v: didn't receive server preface in time. Reconnecting...", addr)
			return nil, nil, errors.New("timed out waiting for server handshake")
		case <-prefaceReceived:
			// We got the preface - huzzah! things are good.
		case <-onCloseCalled:
			// The transport has already closed - noop.
			return nil, nil, errors.New("connection closed")
			// TODO(deklerk) this should bail on ac.ctx.Done(). Add a test and fix.
		}
	}
	return newTr, reconnect, nil
}
1086836
func (s *GetInvitationConfigurationOutput) SetContactEmail(v string) *GetInvitationConfigurationOutput {
	s.ContactEmail = &v
	return s
}
1145288
func (api *Client) CreatePhoneNumber(data *CreatePhoneNumberData) (string, error) {
	_, headers, err := api.makeRequest(http.MethodPost, api.concatUserPath(phoneNumbersPath), nil, data)
	if err != nil {
		return "", err
	}
	return getIDFromLocationHeader(headers), nil
}
1228198
func (s *ContactsService) DeleteContact(accountID string, contactID int64) (*contactResponse, error) {
	path := versioned(contactPath(accountID, contactID))
	contactResponse := &contactResponse{}

	resp, err := s.client.delete(path, nil, nil)
	if err != nil {
		return nil, err
	}

	contactResponse.HttpResponse = resp
	return contactResponse, nil
}
489741
func (mr *MockNetworkAPIClientMockRecorder) NetworkConnect(ctx, networkID, container, config interface{}) *gomock.Call {
	return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NetworkConnect", reflect.TypeOf((*MockNetworkAPIClient)(nil).NetworkConnect), ctx, networkID, container, config)
}
673311
func sendContactUpdate() error {
	log.Debugf("Sending contact SyncMessage")

	lc, err := GetRegisteredContacts()
	if err != nil {
		return fmt.Errorf("could not get local contacts: %s", err)
	}

	var buf bytes.Buffer

	for _, c := range lc {
		cd := &textsecure.ContactDetails{
			Number: &c.Tel,
			Name:   &c.Name,
			// TODO: handle avatars
		}

		b, err := proto.Marshal(cd)
		if err != nil {
			log.Errorf("Failed to marshal contact details")
			continue
		}

		buf.Write(varint32(len(b)))
		buf.Write(b)
	}

	a, err := uploadAttachment(&buf, "application/octet-stream")
	if err != nil {
		return err
	}

	sm := &textsecure.SyncMessage{
		Contacts: &textsecure.SyncMessage_Contacts{
			Blob: &textsecure.AttachmentPointer{
				Id:          &a.id,
				ContentType: &a.ct,
				Key:         a.keys,
			},
		},
	}

	_, err = sendSyncMessage(sm)
	return err
}
48938
func (mr *MockOpenIDConnectRequestStorageMockRecorder) CreateOpenIDConnectSession(arg0, arg1, arg2 interface{}) *gomock.Call {
	return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateOpenIDConnectSession", reflect.TypeOf((*MockOpenIDConnectRequestStorage)(nil).CreateOpenIDConnectSession), arg0, arg1, arg2)
}
556003
func AddContacts(c *messagebird.Client, groupID string, contactIDs []string) error {
	if err := validateAddContacts(contactIDs); err != nil {
		return err
	}

	data := addContactsData(contactIDs)

	return c.Request(nil, http.MethodPut, path+"/"+groupID+"/"+contactPath, data)
}
1328730
func (s *ContactsService) ListContacts(accountID string, options *ListOptions) (*contactsResponse, error) {
	path := versioned(contactPath(accountID, 0))
	contactsResponse := &contactsResponse{}

	path, err := addURLQueryOptions(path, options)
	if err != nil {
		return nil, err
	}

	resp, err := s.client.get(path, contactsResponse)
	if err != nil {
		return contactsResponse, err
	}

	contactsResponse.HttpResponse = resp
	return contactsResponse, nil
}
360950
func (cs *UserService) DeleteContact(userID int, contactID int) (*PingdomResponse, error) {
	req, err := cs.client.NewRequest("DELETE", "/users/"+strconv.Itoa(userID)+"/"+strconv.Itoa(contactID), nil)
	if err != nil {
		return nil, err
	}

	m := &PingdomResponse{}
	_, err = cs.client.Do(req, m)
	if err != nil {
		return nil, err
	}
	return m, err
}
675804
func (c *Contact) ValidContact() error {
	if c.Email == "" && c.Number == "" {
		return fmt.Errorf("you must provide either an Email or a Phone Number to create a contact target")
	}

	if c.Number != "" && c.CountryCode == "" {
		return fmt.Errorf("you must provide a Country Code if providing a phone number")
	}

	if c.Provider != "" && (c.Number == "" || c.CountryCode == "") {
		return fmt.Errorf("you must provide CountryCode and Number if Provider is provided")
	}

	return nil
}