Class: WeixinAuthorize::JsTicket::Store

Inherits:
Object
  • Object
show all
Defined in:
lib/weixin_authorize/js_ticket/store.rb

Direct Known Subclasses

ObjectStore, RedisStore

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#clientObject

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

#jsticketObject



28
29
30
# File 'lib/weixin_authorize/js_ticket/store.rb', line 28

def jsticket
  refresh_jsticket if jsticket_expired?
end

#jsticket_expired?Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


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_jsticketObject



24
25
26
# File 'lib/weixin_authorize/js_ticket/store.rb', line 24

def refresh_jsticket
  set_jsticket
end

#set_jsticketObject



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 = WeixinAuthorize.calculate_expire(result["expires_in"])
end