Class: Wechat::Api::JsTicket
- Inherits:
-
Object
- Object
- Wechat::Api::JsTicket
- Defined in:
- lib/wechat/api/js_ticket.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#expires_at ⇒ Object
readonly
Returns the value of attribute expires_at.
-
#ticket ⇒ Object
readonly
Returns the value of attribute ticket.
Instance Method Summary collapse
- #expired? ⇒ Boolean
-
#initialize(client) ⇒ JsTicket
constructor
A new instance of JsTicket.
- #refresh ⇒ Object
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
#client ⇒ Object (readonly)
Returns the value of attribute client.
5 6 7 |
# File 'lib/wechat/api/js_ticket.rb', line 5 def client @client end |
#expires_at ⇒ Object (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 |
#ticket ⇒ Object (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
17 18 19 |
# File 'lib/wechat/api/js_ticket.rb', line 17 def expired? expires_at.nil? || DateTime.now > expires_at end |
#refresh ⇒ Object
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 |