class Youzanyun::Client
Attributes
access_token[RW]
client_id[RW]
client_secret[RW]
expired_at[RW]
grant_id[RW]
redis_key[RW]
token_type[RW]
Public Class Methods
new(client_id, client_secret, grant_id, options={})
click to toggle source
Calls superclass method
# File lib/youzanyun/client.rb, line 17 def initialize(client_id, client_secret, grant_id, options={}) self.client_id = client_id self.client_secret = client_secret self.expired_at = Time.now.to_i self.grant_id = grant_id self.redis_key = security_redis_key(options[:redis_key] || "youzanyun_#{client_id}") super() end
Public Instance Methods
get_access_token()
click to toggle source
# File lib/youzanyun/client.rb, line 26 def get_access_token synchronize { token_store.access_token } end
get_token_type()
click to toggle source
# File lib/youzanyun/client.rb, line 30 def get_token_type synchronize { token_store.token_type } end
http_delete(url, delete_body={}, url_params={}, endpoint="api")
click to toggle source
# File lib/youzanyun/client.rb, line 52 def http_delete(url, delete_body={}, url_params={}, endpoint="api") url_params = access_token_param.merge(url_params) url = "#{url}?access_token=#{get_access_token}" Youzanyun.http_delete_without_token(url, delete_body, url_params, endpoint) end
http_get(url, url_params={}, endpoint="api")
click to toggle source
# File lib/youzanyun/client.rb, line 42 def http_get(url, url_params={}, endpoint="api") url_params = url_params.merge(access_token_param) Youzanyun.http_get_without_token(url, url_params, endpoint) end
http_post(url, post_body={}, url_params={}, endpoint="api")
click to toggle source
# File lib/youzanyun/client.rb, line 47 def http_post(url, post_body={}, url_params={}, endpoint="api") url_params = access_token_param.merge(url_params) Youzanyun.http_post_without_token(url, post_body, url_params, endpoint) end
is_valid?()
click to toggle source
# File lib/youzanyun/client.rb, line 34 def is_valid? token_store.valid? end
token_store()
click to toggle source
# File lib/youzanyun/client.rb, line 38 def token_store Token::Store.init_with(self) end
verify?(event_sign:, body:)
click to toggle source
# File lib/youzanyun/client.rb, line 58 def verify?(event_sign:, body:) str = client_id + body + client_secret Digest::MD5.hexdigest(str) == event_sign end
Private Instance Methods
access_token_param()
click to toggle source
# File lib/youzanyun/client.rb, line 65 def access_token_param { access_token: get_access_token } end
security_redis_key(key)
click to toggle source
# File lib/youzanyun/client.rb, line 69 def security_redis_key(key) Digest::MD5.hexdigest(key.to_s).upcase end