Devuelve la URL de Telegram en la API

This commit is contained in:
fauno 2020-06-20 21:43:01 -03:00
parent 0467384c90
commit b922a689a4
4 changed files with 16 additions and 3 deletions

View file

@ -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

View file

@ -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

View file

@ -1,3 +1,3 @@
# frozen_string_literal: true
json.call(pirata, :id, :nick, :email)
json.call(pirata, :id, :nick, :email, :telegram_url)

View file

@ -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