lib/skore/peerindex.rb in skore-0.0.3 vs lib/skore/peerindex.rb in skore-1.0.0
- old
+ new
@@ -1,38 +1,32 @@
require 'httparty'
-##
# This module analize and extract score from social analizer http://kred.com
module Skore
class PeerIndex
- ##
# Include httparty module from http querys
include HTTParty
- base_uri "https://api.peerindex.com/1/actor/topic"
+ base_uri 'https://api.peerindex.com/1/actor/topic'
default_timeout 1
attr_accessor :data
- ##
# Initialize and load data from kred api
- def initialize(api_key, username)
- begin
- @data = self.class.get("?twitter_screen_name=#{username}&api_key=#{api_key}", :verify => false)
- rescue Timeout::Error
- @data = false
- end
+ def initialize(api_key)
+ raise ArgumentError, 'api_key is required' if api_key == nil || api_key.empty?
+ @api_key = api_key
end
- ##
# Get core from peerindex api
- def score
- if @data
- result = JSON.parse(@data.body)
- result["peerindex"]
- else
- -1
- end
+ 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
end
end
\ No newline at end of file