Class: Mints::Contact

Inherits:
Object
  • Object
show all
Defined in:
lib/contact.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, api_key, session_token = nil, contact_token_id = nil, debug = false) ⇒ Contact

Initialize.

Class constructor


10
11
12
# File 'lib/contact.rb', line 10

def initialize(host, api_key, session_token = nil, contact_token_id = nil, debug = false)
  @client = Mints::Client.new(host, api_key, "contact", session_token, contact_token_id, debug)
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.


5
6
7
# File 'lib/contact.rb', line 5

def client
  @client
end

Instance Method Details

#change_password(data) ⇒ Object

Change Password.

Change password


72
73
74
# File 'lib/contact.rb', line 72

def change_password(data)
  return @client.raw("post", "/contacts/change-password", nil, data)
end

#login(email, password) ⇒ Object

Login.

Starts a contact session


18
19
20
21
22
23
24
25
26
27
28
# File 'lib/contact.rb', line 18

def (email, password)
  data = {
    email: email,
    password: password
  }
  response = @client.raw("post", "/contacts/login", nil, {data: data})
  if response.key? "session_token"
    @client.session_token = response["session_token"]
  end
  return response
end

#logoutObject

Logout.

Ends a contact session


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

def logout
  response = @client.raw("post", "/contacts/logout") if session_token?
  if response["success"]
    @client.session_token = nil
  end 
  return response
end

Magic Link Login.

Starts a contact session


34
35
36
37
38
39
40
# File 'lib/contact.rb', line 34

def (token)
  response = @client.raw("get", "/contacts/magic-link-login/#{token}", nil, '/api/v1')
  if response.key? "session_token"
    @client.session_token = response["session_token"]
  end
  return response
end

#meObject

Me.

Get contact logged info


104
105
106
# File 'lib/contact.rb', line 104

def me
  return @client.raw("get", "/contacts/me")
end

#oauth_login(data) ⇒ Object

OAuth Login.

Login a contact using oauth


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

def (data)
  return @client.raw("post", "/contacts/oauth-login", nil, data)
end

#recover_password(data) ⇒ Object

Recover Password.

Recover password


80
81
82
# File 'lib/contact.rb', line 80

def recover_password(data)
  return @client.raw("post", "/contacts/recover-password", nil, data)
end

#reset_password(data) ⇒ Object

Reset Password.

Reset password


88
89
90
# File 'lib/contact.rb', line 88

def reset_password(data)
  return @client.raw("post", "/contacts/reset-password", nil, data)
end

Send magic link to contact


44
45
46
47
48
49
50
51
52
53
54
# File 'lib/contact.rb', line 44

def send_magic_link(email, template_slug, redirectUrl = '', lifeTime = 1440, maxVisits = nil)
  data = {
    email: email,
    lifeTime: lifeTime,
    maxVisits: maxVisits,
    redirectUrl: redirectUrl,
    templateId: template_slug
  }
  response = @client.raw("post", "/contacts/magic-link", nil, { data: data }, '/api/v1')
  return response
end

#statusObject

Status.

Get contact logged status


112
113
114
# File 'lib/contact.rb', line 112

def status
  return @client.raw("get", "/contacts/status")
end

#update(data) ⇒ Object

Update.

Update logged contact attributes


120
121
122
# File 'lib/contact.rb', line 120

def update(data)
  return @client.raw("put", "/contacts/update", nil, data)
end