Class: Skore::PeerIndex

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key) ⇒ PeerIndex

Initialize and load data from kred api

Raises:

  • (ArgumentError)


15
16
17
18
# File 'lib/skore/peerindex.rb', line 15

def initialize(api_key)
    raise ArgumentError, 'api_key is required' if api_key == nil || api_key.empty?
    @api_key = api_key
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



12
13
14
# File 'lib/skore/peerindex.rb', line 12

def data
  @data
end

Instance Method Details

#score(username) ⇒ Object

Get core from peerindex api



21
22
23
24
25
26
27
28
29
# File 'lib/skore/peerindex.rb', line 21

def score(username)
    begin
      @data = self.class.get("?twitter_screen_name=#{username}&api_key=#{@api_key}", verify: false)
      result = @data ? JSON.parse(@data.body) : nil
      result['peerindex'] if result
    rescue Timeout::Error
      nil
    end
end