Class: Birdwatcher::KloutClient
- Inherits:
-
HttpClient
- Object
- HttpClient
- Birdwatcher::KloutClient
- Defined in:
- lib/birdwatcher/klout_client.rb
Constant Summary
Constants inherited from HttpClient
HttpClient::DEFAULT_RETRIES, HttpClient::DEFAULT_TIMEOUT, HttpClient::RETRIABLE_EXCEPTIONS, HttpClient::USER_AGENTS
Instance Method Summary collapse
-
#get_id(screen_name) ⇒ String
Get Klout ID of a Twitter user.
-
#get_influence(klout_id) ⇒ Hash
Get Klout influence graph of a user.
-
#get_score(klout_id) ⇒ Numeric
Get Klout score of a user.
-
#get_topics(klout_id) ⇒ Array
Get Klout topics of a user.
-
#initialize(api_key, options = {}) ⇒ KloutClient
constructor
Class initializer.
Methods inherited from HttpClient
#do_delete, #do_get, #do_head, #do_post, #do_put
Constructor Details
#initialize(api_key, options = {}) ⇒ KloutClient
Class initializer
10 11 12 13 14 15 16 17 18 |
# File 'lib/birdwatcher/klout_client.rb', line 10 def initialize(api_key, = {}) @api_key = api_key = { :headers => { "User-Agent" => "Birdwatcher v#{Birdwatcher::VERSION}", "Accept" => "application/json" } }.merge() end |
Instance Method Details
#get_id(screen_name) ⇒ String
Get Klout ID of a Twitter user
25 26 27 28 29 30 |
# File 'lib/birdwatcher/klout_client.rb', line 25 def get_id(screen_name) response = do_get("/identity.json/twitter?screenName=#{url_encode(screen_name)}&key=#{url_encode(@api_key)}") if response.status == 200 JSON.parse(response.body)["id"] end end |
#get_influence(klout_id) ⇒ Hash
Get Klout influence graph of a user
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/birdwatcher/klout_client.rb', line 61 def get_influence(klout_id) response = do_get("/user.json/#{klout_id}/influence?key=#{url_encode(@api_key)}") if response.status == 200 body = JSON.parse(response.body) { :influencers => body["myInfluencers"].map { |i| i["entity"]["payload"]["nick"] }, :influencees => body["myInfluencees"].map { |i| i["entity"]["payload"]["nick"] } } end end |
#get_score(klout_id) ⇒ Numeric
Get Klout score of a user
37 38 39 40 41 42 |
# File 'lib/birdwatcher/klout_client.rb', line 37 def get_score(klout_id) response = do_get("/user.json/#{klout_id}/score?key=#{url_encode(@api_key)}") if response.status == 200 JSON.parse(response.body)["score"] end end |
#get_topics(klout_id) ⇒ Array
Get Klout topics of a user
49 50 51 52 53 54 |
# File 'lib/birdwatcher/klout_client.rb', line 49 def get_topics(klout_id) response = do_get("/user.json/#{klout_id}/topics?key=#{url_encode(@api_key)}") if response.status == 200 JSON.parse(response.body).map { |t| t["displayName"] } end end |