Class: TokenStrans

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

Instance Method Summary collapse

Constructor Details

#initialize(key, fields = {}) ⇒ TokenStrans

Returns a new instance of TokenStrans.



5
6
7
8
9
10
# File 'lib/token.rb', line 5

def initialize (key, fields={})
    @key = key
    @create_at = Time.now
    @minute_validate = fields[:minutes]
    @token = fields['token']
end

Instance Method Details

#date_in_formatObject



12
13
14
15
# File 'lib/token.rb', line 12

def date_in_format()
  today = Time.now
  today.strftime("%a, %d %b %Y %H:%M:%S GMT")
end

#headerObject



17
18
19
20
21
22
23
24
25
# File 'lib/token.rb', line 17

def header
  head ={}
  head['Accept-Language'] = "en"
  head['Content-Type'] = "application/json"
  head['X-Auth-Token'] = @token if @token
  head['X-Api-Key'] = @key
  head['Date'] = date_in_format()
  head
end

#to_jsonObject



31
32
33
34
35
36
37
# File 'lib/token.rb', line 31

def to_json
  {
    'key' => @key,
    'token' => @token,
    'minute_validate' => @minute_validate
  }.to_json
end

#valid?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/token.rb', line 27

def valid?
  !@token.nil? && (Time.now - 10 * 60) <= @create_at
end