-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpeople_browsr.rb
More file actions
115 lines (92 loc) · 2.31 KB
/
people_browsr.rb
File metadata and controls
115 lines (92 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
require 'net/http'
require 'json'
=begin
Usage:
api = PeopleBrowsr::PeopleBrowsrAPI.new(id, key)
json_obj = api.at_name_cloud(
last: 'yesterday',
count: 30,
source: 'twitter',
term: 'zombies',
limit: 300,
)
puts json_obj['data']
=end
module PeopleBrowsr
class PeopleBrowsrAPI
def initialize(id, key)
@id, @key, @base_url = id, key, 'http://api.peoplebrowsr.com'
end
def at_name_cloud(params={})
fetch "atnamecloud", params
end
def mentions(params={})
fetch "mentions", params
end
def density(params={})
fetch "density", params
end
def word_cloud(params={})
fetch "wordcloud", params
end
def hashtag_cloud(params={})
fetch "hashtagcloud", params
end
def mentions_retweets(params={})
fetch "mentions-retweets", params
end
def friends_and_followers(params={})
fetch "friendsandfollowers", params
end
def top_followers(params={})
fetch "top-followers", params
end
def positive_top_followers(params={})
fetch "Top-Positive-Followers", params
end
def negative_top_followers(params={})
fetch "wordcloud", params
end
def popularity(params={})
fetch "popularity", params
end
def sentiment(params={})
fetch "sentiment", params
end
def top_us_state(params={})
fetch "top-usarea", params
end
def top_countries(params={})
fetch "topcountries", params
end
def top_urls(params={})
fetch "topurls", params
end
def top_pictures(params={})
fetch "toppictures", params
end
def top_videos(params={})
fetch "topvideos", params
end
def kred_outreach(params={})
fetch "kredoutreach", params
end
def kred_influence(params={})
fetch "kredinfluence", params
end
private
def fetch(page, params={})
uri = URI("#@base_url/#{page}?app_id=#@id&app_key=#@key&#{URI.encode_www_form params}")
json = nil
begin
sleep 0.5 unless json.nil?
json = JSON.parse(''.tap do |j|
Net::HTTP.start(uri.host, uri.port) do |http|
http.get(uri.request_uri) { |response| j << response }
end
end)
end until json['status'] == 'complete'
json
end
end
end