Class: WeixinAuthorize::JsTicket::Store
- Inherits:
-
Object
- Object
- WeixinAuthorize::JsTicket::Store
- Defined in:
- lib/weixin_authorize/js_ticket/store.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(client) ⇒ Store
constructor
A new instance of Store.
- #jsticket ⇒ Object
- #jsticket_expired? ⇒ Boolean
- #refresh_jsticket ⇒ Object
- #set_jsticket ⇒ Object
Constructor Details
#initialize(client) ⇒ Store
Returns a new instance of Store.
8 9 10 |
# File 'lib/weixin_authorize/js_ticket/store.rb', line 8 def initialize(client) @client = client end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
6 7 8 |
# File 'lib/weixin_authorize/js_ticket/store.rb', line 6 def client @client end |
Class Method Details
.init_with(client) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/weixin_authorize/js_ticket/store.rb', line 12 def self.init_with(client) if WeixinAuthorize.weixin_redis.nil? ObjectStore.new(client) else RedisStore.new(client) end end |
Instance Method Details
#jsticket ⇒ Object
28 29 30 |
# File 'lib/weixin_authorize/js_ticket/store.rb', line 28 def jsticket refresh_jsticket if jsticket_expired? end |
#jsticket_expired? ⇒ Boolean
20 21 22 |
# File 'lib/weixin_authorize/js_ticket/store.rb', line 20 def jsticket_expired? raise NotImplementedError, "Subclasses must implement a jsticket_expired? method" end |
#refresh_jsticket ⇒ Object
24 25 26 |
# File 'lib/weixin_authorize/js_ticket/store.rb', line 24 def refresh_jsticket set_jsticket end |
#set_jsticket ⇒ Object
32 33 34 35 36 |
# File 'lib/weixin_authorize/js_ticket/store.rb', line 32 def set_jsticket result = client.http_get("/ticket/getticket", {type: 1}).result client.jsticket = result["ticket"] client.jsticket_expired_at = result["expires_in"] + Time.now.to_i end |