Devuelve la URL de Telegram en la API
This commit is contained in:
parent
0467384c90
commit
b922a689a4
4 changed files with 16 additions and 3 deletions
|
@ -26,7 +26,7 @@ class PiratasController < ApplicationController
|
|||
#
|
||||
# Obtener el perfil propio
|
||||
#
|
||||
# @return [Hash] { id: @int, nick: @string, email: @string }
|
||||
# @return [Hash] { id: @int, nick: @string, email: @string, telegram_url: @string }
|
||||
def yo
|
||||
@pirata = current_pirata
|
||||
end
|
||||
|
|
|
@ -23,7 +23,14 @@ class Pirata < ApplicationRecord
|
|||
|
||||
before_create :telegram_token!
|
||||
|
||||
# Asigna un token a cada pirata
|
||||
# Devuelve la URL de Telegram
|
||||
# @return [String]
|
||||
def telegram_url
|
||||
'https://t.me/' + Telegram.bots[:default].username + '?start=' + telegram_token
|
||||
end
|
||||
|
||||
# Asigna un token a cada pirata si no lo tiene
|
||||
# @return [TrueClass] Los callbacks tienen que terminar en true
|
||||
def telegram_token!
|
||||
self.telegram_token = SecureRandom.hex unless telegram_token
|
||||
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
json.call(pirata, :id, :nick, :email)
|
||||
json.call(pirata, :id, :nick, :email, :telegram_url)
|
||||
|
|
|
@ -8,4 +8,10 @@ class PirataTest < ActiveSupport::TestCase
|
|||
|
||||
assert_equal true, pirata.valid?
|
||||
end
|
||||
|
||||
test 'tiene un token de telegram' do
|
||||
pirate = create :pirata
|
||||
|
||||
assert pirate.telegram_token
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue