lib/skore/kred.rb in skore-0.0.3 vs lib/skore/kred.rb in skore-1.0.0

- old
+ new

@@ -1,38 +1,35 @@ require 'httparty' -## # This module analize and extract score from social analizer http://kred.com module Skore - class Kred + class Kred - ## - # Include httparty module from http querys - include HTTParty - base_uri "http://api.kred.com/kredscore" - default_timeout 1 + # Include httparty module from http querys + include HTTParty - attr_accessor :data + base_uri 'http://api.kred.com/kredscore' + default_timeout 1 - ## - # Initialize and load data from kred api - def initialize(app_id, app_key, username) - begin - @data = self.class.get("?term=#{username}&source=twitter&app_id=#{app_id}&app_key=#{app_key}", :verify => false) - rescue Timeout::Error - @data = false - end - end + attr_accessor :data - ## - # Get score from Kred api - def score - if @data - result = JSON.parse(@data.body) - result["data"][0]["influence"] - else - -1 - end - end + # Initialize and load data from kred api + 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 - end + # Get score from Kred api + 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 + + end end \ No newline at end of file