class Skore::Kred

Attributes

data[RW]

Public Class Methods

new(app_id, app_key) click to toggle source

Initialize and load data from kred api

# File lib/skore/kred.rb, line 16
def initialize(app_id, app_key)
  raise ArgumentError, 'app_id is required' if app_id == nil || app_id.empty?
  raise ArgumentError, 'api_key is required' if app_key == nil || app_key.empty?
  @app_id = app_id
  @app_key = app_key
end

Public Instance Methods

score(social_network, username) click to toggle source

Get score from Kred api

# File lib/skore/kred.rb, line 24
def score(social_network, username)
  begin
    @data = self.class.get("?term=#{username}&source=#{social_network}&app_id=#{@app_id}&app_key=#{@app_key}", verify: false)
    result = @data ? JSON.parse(@data.body) : nil
    result['data'][0]['influence'] if result && result['data']
  rescue Timeout::Error
    nil
  end
end