Class: Mints::Contact
- Inherits:
-
Object
- Object
- Mints::Contact
- Includes:
- ContactConfig, ContactContent, ContactEcommerce, MintsHelper, ThreadsHelper
- Defined in:
- lib/contact.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
-
#change_password(data) ⇒ Object
Change Password.
-
#initialize(host, api_key, session_token = nil, contact_token_id = nil, debug = false, timeouts = {}) ⇒ Contact
constructor
Initialize.
-
#login(email, password) ⇒ Object
Login.
-
#logout ⇒ Object
Logout.
-
#magic_link_login(token) ⇒ Object
Magic Link Login.
-
#me(options = nil) ⇒ Object
Me.
-
#oauth_login(data) ⇒ Object
OAuth Login.
-
#recover_password(data) ⇒ Object
Recover Password.
-
#register(data) ⇒ Object
Register.
-
#reset_password(data) ⇒ Object
Reset Password.
-
#send_magic_link(email_or_phone, template_slug, redirect_url = '', life_time = 1440, max_visits = nil, driver = 'email') ⇒ Object
Send Magic Link.
-
#status ⇒ Object
Status.
-
#update(data) ⇒ Object
Update.
Methods included from ThreadsHelper
Methods included from MintsHelper
#correct_json, #data_transform, #get_query_results
Methods included from ContactVouchers
Methods included from ContactOrders
#add_item_to_shopping_cart, #create_order, #detach_order_item_from_order_item_group, #get_my_shopping_cart, #get_order, #get_orders, #update_order, #update_order_item_from_order_item_group
Methods included from ContactOrderItems
#get_order_item, #get_order_items
Methods included from ContactOrderItemsGroups
#create_order_item_group, #delete_order_item_group, #get_order_item_group, #get_order_item_groups, #update_order_item_group
Methods included from ContactConversations
#create_conversation, #create_message, #get_conversation, #get_conversation_participants, #get_conversations, #get_message, #get_messages, #update_conversation, #update_conversation_status
Methods included from ContactAppointments
#attach_follower, #attach_invitee, #create_appointment, #detach_follower, #detach_invitee, #get_appointment, #get_appointments, #scheduled_appointments, #sync_follower, #sync_invitee, #update_appointment
Constructor Details
#initialize(host, api_key, session_token = nil, contact_token_id = nil, debug = false, timeouts = {}) ⇒ Contact
Initialize.
Class constructor.
Parameters
- host
-
(String) – It’s the visitor IP.
- api_key
-
(String) – Mints instance api key.
- contact_token_id
-
(Integer) – Cookie ‘mints_contact_id’ value (mints_contact_token).
Return
Returns a Contact object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/contact.rb', line 33 def initialize( host, api_key, session_token = nil, contact_token_id = nil, debug = false, timeouts = {} ) @contact_v1_url = '/api/contact/v1' @client = Mints::Client.new( host, api_key, 'contact', session_token, contact_token_id, nil, debug, timeouts ) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
20 21 22 |
# File 'lib/contact.rb', line 20 def client @client end |
Instance Method Details
#change_password(data) ⇒ Object
Change Password.
Change password without email. To change the password a contact must be logged.
Parameters
- data
-
(Hash) – A new password allocated in a data key.
Example
data = { password: 'new_password' }
@data = @mints_contact.change_password(data)
260 261 262 |
# File 'lib/contact.rb', line 260 def change_password(data) @client.raw('post', '/change-password', nil, data_transform(data), @contact_v1_url) end |
#login(email, password) ⇒ Object
Login.
Starts a contact session.
Parameters
-
(String) – The email that will be logged.
- password
-
(String) – The password of the email.
Example
@mints_contact.login('[email protected]', 'password')
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/contact.rb', line 85 def login(email, password) data = { email: email, password: password } response = @client.raw('post', '/contacts/login', nil, data_transform(data)) @client.session_token = response['session_token'] if response.key? 'session_token' response end |
#logout ⇒ Object
Logout.
Ends a contact session previously logged.
Example
@data = @mints_contact.logout
241 242 243 244 245 246 247 248 |
# File 'lib/contact.rb', line 241 def logout if session_token? response = @client.raw('post', '/logout', nil, nil, @contact_v1_url) @client.session_token = nil if response['success'] response end end |
#magic_link_login(token) ⇒ Object
Magic Link Login.
Starts a contact session with a token received in the contact email. The token will be received by send_magic_link method.
Parameters
- token
-
(String) – The email token that will be used to log in.
Example
@mints_contact.magic_link_login(
'd8618c6d-a165-41cb-b3ec-d053cbf30059:zm54HtRdfHED8dpILZpjyqjPIceiaXNLfOklqM92fveBS0nDtyPYBlI4CPlPe3zq'
)
147 148 149 150 151 152 |
# File 'lib/contact.rb', line 147 def magic_link_login(token) response = @client.raw('get', "/contacts/magic-link-login/#{token}", nil, '/api/v1') @client.session_token = response['session_token'] if response.key? 'session_token' response end |
#me(options = nil) ⇒ Object
Me.
Get contact logged info.
Parameters
- # options
-
(Hash) – List of Resource collection Options shown above can be used as parameter.
First Example
@data = @mints_contact.me
Second Example
= {
attributes: true,
taxonomies: true
}
@data = @mints_contact.me()
204 205 206 |
# File 'lib/contact.rb', line 204 def me( = nil) @client.raw('get', '/me', , nil, @contact_v1_url) end |
#oauth_login(data) ⇒ Object
OAuth Login.
Login a contact using oauth.
132 133 134 |
# File 'lib/contact.rb', line 132 def oauth_login(data) @client.raw('post', '/contacts/oauth-login', nil, data) end |
#recover_password(data) ⇒ Object
Recover Password.
Send a email that contains a token to a contact. That token will be used in reset_password to establish a new password.
Parameters
- data
-
(Hash) – It’s a data key where will be hosted the destination email.
Example
data = { email: '[email protected]' }
@mints_contact.recover_password(data)
106 107 108 |
# File 'lib/contact.rb', line 106 def recover_password(data) @client.raw('post', '/contacts/recover-password', nil, data_transform(data)) end |
#register(data) ⇒ Object
Register.
Register a contact.
Parameters
- data
-
(Hash) – It’s the register data.
Example
data = {
email: '[email protected]',
given_name: 'Given Name',
last_name: 'Last Name',
password: 'password'
}
@mints_contact.register(data);
71 72 73 |
# File 'lib/contact.rb', line 71 def register(data) @client.raw('post', '/contacts/register', nil, data_transform(data)) end |
#reset_password(data) ⇒ Object
Reset Password.
Reset password using a token. The token is obtained by recover_password method.
Parameters
- data
-
(Hash) – It’s a set of data which contains all the information to reset a contact password.
Example
data = {
email: '[email protected]',
password: 'password',
password_confirmation: 'password',
token: '644aa3aa0831d782cc42e42b11aedea9a2234389af4f429a8d96651295ecfa09'
}
@mints_contact.reset_password(data)
125 126 127 |
# File 'lib/contact.rb', line 125 def reset_password(data) @client.raw('post', '/contacts/reset-password', nil, data_transform(data)) end |
#send_magic_link(email_or_phone, template_slug, redirect_url = '', life_time = 1440, max_visits = nil, driver = 'email') ⇒ Object
Send Magic Link.
Send magic link to contact by email. That magic link will be used in magic_link_login method.
Parameters
- email_or_phone
-
(String) – Contact’s email.
- template_slug
-
(String) – Email template’s slug to be used in the email.
- redirectUrl
-
(String) – Url to be redirected in the implemented page.
- lifeTime
-
(Integer) – Maximum time of use in minutes.
- maxVisits
-
(Integer) – The maximum number of uses of a token.
First Example
@mints_contact.send_magic_link('[email protected]', 'template_slug')
Second Example
@mints_contact.send_magic_link('+526561234567', 'template_slug', '', 1440, 3, 'whatsapp')
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/contact.rb', line 170 def send_magic_link(email_or_phone, template_slug, redirect_url = '', life_time = 1440, max_visits = nil, driver = 'email') data = { driver: driver, lifeTime: life_time, maxVisits: max_visits, redirectUrl: redirect_url, templateId: template_slug } if %w[sms whatsapp].include? driver data['phone'] = email_or_phone else data['email'] = email_or_phone end @client.raw('post', '/contacts/magic-link', nil, data_transform(data), '/api/v1') end |
#status ⇒ Object
Status.
Get contact logged status.
Example
@data = @mints_contact.status
214 215 216 |
# File 'lib/contact.rb', line 214 def status @client.raw('get', '/status', nil, nil, @contact_v1_url) end |
#update(data) ⇒ Object
Update.
Update logged contact attributes.
Parameters
- data
-
(Hash) – It’s the data to update with a session active.
Example
data = {
given_name: 'Given Name',
last_name: 'Last Name'
}
@data = @mints_contact.update(data)
231 232 233 |
# File 'lib/contact.rb', line 231 def update(data) @client.raw('put', '/update', nil, data_transform(data), @contact_v1_url) end |