Class: Wechat::Api::JsTicket

Inherits:
Object
  • Object
show all
Defined in:
lib/wechat/api/js_ticket.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ JsTicket

Returns a new instance of JsTicket.



6
7
8
# File 'lib/wechat/api/js_ticket.rb', line 6

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



5
6
7
# File 'lib/wechat/api/js_ticket.rb', line 5

def client
  @client
end

#expires_atObject (readonly)

Returns the value of attribute expires_at.



5
6
7
# File 'lib/wechat/api/js_ticket.rb', line 5

def expires_at
  @expires_at
end

#ticketObject (readonly)

Returns the value of attribute ticket.



5
6
7
# File 'lib/wechat/api/js_ticket.rb', line 5

def ticket
  @ticket
end

Instance Method Details

#expired?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/wechat/api/js_ticket.rb', line 17

def expired?
  expires_at.nil? || DateTime.now > expires_at
end

#refreshObject



10
11
12
13
14
15
# File 'lib/wechat/api/js_ticket.rb', line 10

def refresh
  js = client.js_ticket
  @ticket = js['ticket']
  @expires_at = DateTime.now + Rational(js['expires_in'].to_i, 3600 * 24)
  self
end