Module: APIHub::Baller

Extended by:
Baller
Includes:
APIHub
Included in:
Baller
Defined in:
lib/apihub/baller.rb,
lib/apihub/baller/version.rb,
lib/apihub/baller/email_providers.rb

Defined Under Namespace

Modules: EmailProviders

Constant Summary collapse

VERSION =
"0.0.4"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#defaultsObject

Returns the value of attribute defaults.



9
10
11
# File 'lib/apihub/baller.rb', line 9

def defaults
  @defaults
end

Instance Method Details

#api_key=(value) ⇒ Object



24
25
26
# File 'lib/apihub/baller.rb', line 24

def api_key=(value)
  APIHub.api_key = value
end

#baller?(email, options = {}) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
32
# File 'lib/apihub/baller.rb', line 28

def baller?(email, options = {})
  threshold = options[:threshold] || 20

  lookup(options).score > threshold
end

#lookup(email) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/apihub/baller.rb', line 34

def lookup(email)
  if email =~ /.+@.+/
    person = Streaming::Person[email: email]
    suffix, domain = email.split('@', 2)

  else
    domain = email
  end

  unless EmailProviders::DOMAINS.include?(domain)
    company = Streaming::Company[domain: domain]
  end

  return unless person || company

  result = Mash.new(person || {})
  result.merge!(company: company)
  result.merge!(score: score(result))
  result
end

#score(result, options = {}) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/apihub/baller.rb', line 55

def score(result, options = {})
  options = defaults.merge(options)

  score = 0.0

  return score unless result

  if result.avatar
    score += 5
  end

  if result.twitter
    score += result.twitter.followers * options.twitter_followers_weight
  end

  if result.angellist
    score += result.angellist.followers * options.angellist_followers_weight
  end

  if result.klout && result.klout.score
    score += result.klout.score * options.klout_score_weight
  end

  if company = result.company
    unless company.personal
      score += options.company_score
    end

    if company.raised
      score += company.raised *
                options.company_raised_weight
    end

    if company.employees
      score += company.employees *
                options.company_employees_weight
    end

    if company.alexa && company.alexa.globalRank
      score += 1 / (company.alexa.globalRank *
                options.company_alexa_rank_weight)
    end

    if company.google && company.google.rank && company.google.rank > 0
      score += 1 / (company.google.rank *
                options.company_google_rank_weight)
    end

    if company.twitter
      score += company.twitter.followers *
                options.company_twitter_followers_weight
    end
  end

  score /= options.total_score

  [score.round(1), 1.0].min
end