Module: Liker

Defined in:
lib/liker.rb,
lib/liker/version.rb

Constant Summary collapse

VERSION =
"0.0.1"

Class Method Summary collapse

Class Method Details

.likes_count(*options) ⇒ Object

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/liker.rb', line 6

def self.likes_count(*options)
  url = options[0]
  raise ArgumentError, "Specify the url as the first argument" unless url
  source = options[1][:source] rescue nil
  if source
    Liker.send("#{source}_likes_count", url)
  else
    result = {
      :facebook => self.facebook_likes_count(url),
      :vk => self.vk_likes_count(url),
      :twitter => self.twitter_likes_count(url)
    }
    result[:total] = result.values.inject{|sum,value| sum + value}
    result
  end
end