Class: Skore::Kred

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/skore/kred.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_id, app_key) ⇒ Kred

Initialize and load data from kred api

Raises:

  • (ArgumentError)


16
17
18
19
20
21
# 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

Instance Attribute Details

#dataObject

Returns the value of attribute data.



13
14
15
# File 'lib/skore/kred.rb', line 13

def data
  @data
end

Instance Method Details

#score(social_network, username) ⇒ Object

Get score from Kred api



24
25
26
27
28
29
30
31
32
# 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