class WeixinAuthorize::JsTicket::Store

Attributes

client[RW]

Public Class Methods

init_with(client) click to toggle source
# 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
new(client) click to toggle source
# File lib/weixin_authorize/js_ticket/store.rb, line 8
def initialize(client)
  @client = client
end

Public Instance Methods

jsticket() click to toggle source
# File lib/weixin_authorize/js_ticket/store.rb, line 28
def jsticket
  refresh_jsticket if jsticket_expired?
end
jsticket_expired?() click to toggle source
# 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() click to toggle source
# File lib/weixin_authorize/js_ticket/store.rb, line 24
def refresh_jsticket
  set_jsticket
end
set_jsticket() click to toggle source
# 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 = WeixinAuthorize.calculate_expire(result["expires_in"])
end