Sha256: dde1c73057602ca0ef9dfaa0e815f5e7fd49c2b1d6f09ff4eb7f8a9871b8efb9

Contents?: true

Size: 1.04 KB

Versions: 2

Compression:

Stored size: 1.04 KB

Contents

require "active_support"

module ShareChecker
  autoload :Provider, 'share_checker/provider'
  autoload :Config, 'share_checker/config'
  
  module Providers
    autoload :Facebook, 'share_checker/providers/facebook'
    autoload :Twitter, 'share_checker/providers/twitter'
    autoload :Vkontakte, 'share_checker/providers/vkontakte'
    autoload :Odnoklassniki, 'share_checker/providers/odnoklassniki'
    autoload :Tweetracker, 'share_checker/providers/tweetracker'
    
    def self.get(provider)
      "ShareChecker::Providers::#{provider.to_s.classify}".constantize
    end
    
    def self.avariable
      constants.select {|c| Class === const_get(c)}.sort.map(&:downcase).map(&:to_sym)
    end
  end
  
  mattr_accessor :config
  @@config = Config.new
  
  # Class methods
  
  def self.setup(&block)
    yield config
  end
  
  def self.check(*args)
    provider(*args).check
  end
  
  def self.provider(provider, url, options = {})
    options = (config.send(provider) || {}).merge(options)
    Providers.get(provider).new(url, provider, options)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
share_checker-0.1.1 lib/share_checker.rb
share_checker-0.1.0 lib/share_checker.rb