module AdmqrKnife

Constants

VERSION

Attributes

knife_base_uri[RW]
knife_client_key[RW]
logger[RW]

Public Class Methods

client_key() click to toggle source
# File lib/admqr_knife.rb, line 20
def client_key
  @knife_client_key
end
init(client_key = nil, options = {}) click to toggle source
# File lib/admqr_knife.rb, line 14
def init(client_key = nil, options = {})
  @knife_client_key = client_key || ENV['ADMQR_KNIFE_CLIENT_KEY'] 
  @knife_base_uri = ENV['KNIFE_BASE_URI'] || 'https://www.admqr.com/apic/v1/'
  @logger = options[:logger] || select_logger
end
visit(unique_code:, **options) click to toggle source
# File lib/admqr_knife.rb, line 24
def visit(unique_code:, **options)
  raise 'unique_code 不能为空' if unique_code.to_s == ''

  ua = options[:ua] || options[:client_ua]
  referer = options[:referer]
  tag = options[:tag]
  new_to_visit = options[:new_to_visit]
  remote_ip = options[:remote_ip]
  extra = options[:extra] 
  CubeService.post('/api/knifes/statis',
                   { unique_code: unique_code,
                     client_ua: ua,
                     referer: referer,
                     tag: tag,
                     extra: extra,
                     new_to_visit: new_to_visit,
                     remote_ip: remote_ip }.reject { |_k, v| v.nil? })
rescue StandardError => e
  logger.error "AdmqrKnife Gem Error: #{e.message}"
end

Private Class Methods

select_logger() click to toggle source
# File lib/admqr_knife.rb, line 47
def select_logger
  return Rails.logger if defined? Rails

  Logger.new(STDOUT)
end