Class: Infopark::Crm::Contact

Inherits:
Infopark::Crm::Core::Resource show all
Defined in:
lib/crm_connector/contact.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.authenticate(login, password) ⇒ Infopark::Crm::Contact

Looks for the user with the given login and check whether the password is correct.

Parameters:

  • login (String)
  • password (String)

Returns:

Raises:

WebCRM Rest Url:

  • POST /api/contacts/authenticate



60
61
62
63
64
65
66
67
68
# File 'lib/crm_connector/contact.rb', line 60

def self.authenticate(, password)
  begin
    response = post(:authenticate, {}, format.encode({:login => , :password => password}))
    result = format.decode(response.body)
    find(result)
  rescue ActiveResource::ResourceInvalid
    raise Errors::AuthenticationFailed
  end
end

.password_set(password, token) ⇒ String

Sets a new password for the contact, which is associated with the given token.

Parameters:

  • password (String)

    The new password.

  • token (String)

    The token provided by password_request which is associated with a contact.

Returns:

  • (String)

    The result message from the server.

WebCRM Rest Url:

  • POST /api/contacts/password_set



76
77
78
79
# File 'lib/crm_connector/contact.rb', line 76

def self.password_set(password, token)
  response = post(:password_set, {}, format.encode({:password => password, :token => token}))
  format.decode(response.body)
end

.search(input) ⇒ Array<Infopark::Crm::Contact>

Searches for contacts

Examples:

results = Infopark::Crm::Contact.search(:params => {:login => 'the_login'})
results = Infopark::Crm::Contact.search(:params => {:email => '[email protected]'})
results = Infopark::Crm::Contact.search(:params => {:q => 'full-text search'})

Parameters:

  • input (Hash)

    A hash containing a params key. The value of this key is a hash containing the actual search query.

Returns:

WebCRM Rest Url:

  • GET /api/contacts/search



14
# File 'lib/crm_connector/contact.rb', line 14

has_search

Instance Method Details

#accountInfopark::Crm::Account

Queries the WebCRM for the Account with the id account_id.

Returns:

WebCRM Rest Url:

  • GET /api/accounts/account_id



49
50
51
# File 'lib/crm_connector/contact.rb', line 49

def 
  Infopark::Crm::Account.find() if 
end

#live_server_groupsArray<String>

Returns the live_server_groups of this contact as defined by Configuration.live_server_groups_callback

Returns:

  • (Array<String>)

    The calculated roles of this contact.



103
104
105
106
107
108
109
110
# File 'lib/crm_connector/contact.rb', line 103

def live_server_groups
  return @live_server_groups if defined?(@live_server_groups)
  callback = Configuration.live_server_groups_callback
  @live_server_groups = callback.call(self) if callback.respond_to?(:call)
  raise "live_server_groups_callback: not defined or unexpected result!" unless @live_server_groups

  @live_server_groups
end

#live_server_groups=(value)

This method returns an undefined value.

Overwrites live_server_groups, so live_server_groups_callback is not called for this object.



115
116
117
# File 'lib/crm_connector/contact.rb', line 115

def live_server_groups=(value)
  @live_server_groups = value
end

#password_request(options = {}) ⇒ Object

Instructs the WebCRM to send the user an e-mail to let them set a new password.

Parameters:

  • options (Hash) (defaults to: {})

WebCRM Rest Url:

  • GET /api/contacts/id/password_request



95
96
97
98
99
# File 'lib/crm_connector/contact.rb', line 95

def password_request(options = {})
  params = options[:params] || {}
  response = post(:password_request, {}, self.class.format.encode(params))
  self.class.format.decode(response.body)
end

#password_set(password)

This method returns an undefined value.

Sets the password of this contact to password.

Parameters:

  • password (String)

    the new password



85
86
87
88
# File 'lib/crm_connector/contact.rb', line 85

def password_set(password)
  token = password_request(:params => {:only_get_token => true})
  self.class.password_set(password, token)
end