Class: Telegram::Auth::Fields
- Inherits:
-
Object
- Object
- Telegram::Auth::Fields
- Defined in:
- lib/telegram/auth/fields.rb
Instance Method Summary collapse
- #expired?(time = Time.now.to_i) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(hash) ⇒ Fields
constructor
A new instance of Fields.
- #to_s ⇒ Object
Constructor Details
#initialize(hash) ⇒ Fields
Returns a new instance of Fields.
3 4 5 |
# File 'lib/telegram/auth/fields.rb', line 3 def initialize(hash) @hash = hash end |
Instance Method Details
#expired?(time = Time.now.to_i) ⇒ Boolean
7 8 9 10 |
# File 'lib/telegram/auth/fields.rb', line 7 def expired?(time = Time.now.to_i) return false unless Configuration.instance.auth_expires_in.present? time > @hash[:auth_date] + Configuration.instance.auth_expires_in end |
#hash ⇒ Object
12 13 14 15 |
# File 'lib/telegram/auth/fields.rb', line 12 def hash token_sha = OpenSSL::Digest::SHA256.new.digest(Configuration.instance.token) OpenSSL::HMAC.hexdigest(OpenSSL::Digest::SHA256.new, token_sha, to_s) end |
#to_s ⇒ Object
17 18 19 20 |
# File 'lib/telegram/auth/fields.rb', line 17 def to_s permitted_hash = @hash.slice(:auth_date, :id, :username, :first_name, :last_name, :photo_url) permitted_hash.map { |k,v| "#{k}=#{v}" }.sort.join("\n") end |