module Youzanyun

encoding: utf-8

encoding: utf-8

Constants

CUSTOM_ENDPOINT
VERSION

Attributes

config[RW]

Public Class Methods

api_endpoint() click to toggle source
# File lib/youzanyun.rb, line 56
def api_endpoint
  "https://open.youzanyun.com/api"
end
calculate_expire(expires_in) click to toggle source
# File lib/youzanyun.rb, line 60
def calculate_expire(expires_in)
  expires_in.to_i / 1000 - key_expired.to_i
end
configure() { |config ||= config| ... } click to toggle source
# File lib/youzanyun/config.rb, line 6
def configure
  yield self.config ||= Config.new
end
endpoint_url(endpoint, url) click to toggle source
# File lib/youzanyun.rb, line 51
def endpoint_url(endpoint, url)
  return url if endpoint == CUSTOM_ENDPOINT
  send("#{endpoint}_endpoint") + url
end
http_delete_without_token(url, delete_body = {}, url_params = {}, endpoint="api") click to toggle source
# File lib/youzanyun.rb, line 37
def http_delete_without_token(url, delete_body = {}, url_params = {}, endpoint="api")
  delete_api_url = endpoint_url(endpoint, url)
  load_json(resource(delete_api_url).delete(params: url_params, raw_response: true))
end
http_get_without_token(url, url_params={}, endpoint="api") click to toggle source
# File lib/youzanyun.rb, line 27
def http_get_without_token(url, url_params={}, endpoint="api")
  get_api_url = endpoint_url(endpoint, url)
  load_json(resource(get_api_url).get(params: url_params))
end
http_post_without_token(url, post_body = {}, url_params = {}, endpoint="api") click to toggle source
# File lib/youzanyun.rb, line 32
def http_post_without_token(url, post_body = {}, url_params = {}, endpoint="api")
  post_api_url = endpoint_url(endpoint, url)
  load_json(resource(post_api_url).post(JSON.generate(post_body), params: url_params))
end
key_expired() click to toggle source
# File lib/youzanyun/config.rb, line 15
def key_expired
  config.key_expired rescue 100
end
load_json(string) click to toggle source
# File lib/youzanyun.rb, line 46
def load_json(string)
  result_hash = JSON.parse(string.force_encoding("UTF-8").gsub(/[\u0011-\u001F]/, ""))
  ResultHandler.new(result_hash["code"], result_hash["message"], result_hash["success"], result_hash)
end
resource(url) click to toggle source
# File lib/youzanyun.rb, line 42
def resource(url)
  RestClient::Resource.new(url, rest_client_options)
end
rest_client_options() click to toggle source
# File lib/youzanyun/config.rb, line 19
def rest_client_options
  return { timeout: 5, open_timeout: 5, verify_ssl: true } if config.nil?
  config.rest_client_options
end
youzanyun_redis() click to toggle source
# File lib/youzanyun/config.rb, line 10
def youzanyun_redis
  return nil if config.nil?
  @redis ||= config.redis
end