postrank-api 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +10 -1
- data/VERSION +1 -1
- data/lib/postrank-api/api.rb +54 -1
- data/postrank-api.gemspec +2 -2
- data/spec/api_spec.rb +60 -2
- metadata +3 -3
data/README.md
CHANGED
@@ -26,4 +26,13 @@ For complete documentation on all endpoints please see [PostRank API Docs](http:
|
|
26
26
|
eng = api.engagement(igvita['id'], :start => 'yesterday')
|
27
27
|
|
28
28
|
# lookup social metrics for a url
|
29
|
-
metrics = api.metrics('http://www.igvita.com/')
|
29
|
+
metrics = api.metrics('http://www.igvita.com/')
|
30
|
+
|
31
|
+
# get recommended feeds
|
32
|
+
recommendations = api.recommendations(igvita['id'])
|
33
|
+
|
34
|
+
#lookup relative postranks for given posts
|
35
|
+
postrank = api.postrank(top['items'].collect!{|info| info['original_link']})
|
36
|
+
|
37
|
+
#lookup metrics history for a given post hash
|
38
|
+
history = api.postrank(top['items'].first['id'], :start => '1 month ago')
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/lib/postrank-api/api.rb
CHANGED
@@ -7,6 +7,7 @@ require 'yajl'
|
|
7
7
|
|
8
8
|
module PostRank
|
9
9
|
class API
|
10
|
+
V1_API_BASE = 'http://api.postrank.com/v1'
|
10
11
|
V2_API_BASE = 'http://api.postrank.com/v2'
|
11
12
|
|
12
13
|
def initialize(appkey)
|
@@ -44,6 +45,50 @@ module PostRank
|
|
44
45
|
parse(http.response)
|
45
46
|
end
|
46
47
|
|
48
|
+
def recommendations(feeds, opts = {})
|
49
|
+
req = {
|
50
|
+
:query => {
|
51
|
+
:appkey => @appkey,
|
52
|
+
:num => opts[:num] || 10
|
53
|
+
},
|
54
|
+
:body => build_body(feeds, 'feed')
|
55
|
+
}
|
56
|
+
|
57
|
+
http = post("#{V2_API_BASE}/recommend", req)
|
58
|
+
parse(http.response)
|
59
|
+
end
|
60
|
+
|
61
|
+
def metrics_versioned(posts, opts = {})
|
62
|
+
|
63
|
+
start_time = opts[:start] || 'yesterday'
|
64
|
+
end_time = opts[:end] || 'today'
|
65
|
+
|
66
|
+
req = {
|
67
|
+
:query => {
|
68
|
+
:appkey => @appkey,
|
69
|
+
:min_time => Chronic.parse(start_time).to_i,
|
70
|
+
:max_time => Chronic.parse(end_time).to_i
|
71
|
+
},
|
72
|
+
:body => build_body( posts, 'post_hash')
|
73
|
+
}
|
74
|
+
|
75
|
+
http = post("#{V2_API_BASE}/entry/metrics/historic", req)
|
76
|
+
parse(http.response)
|
77
|
+
end
|
78
|
+
|
79
|
+
def postrank(urls, feeds = [], opts = {})
|
80
|
+
req = {
|
81
|
+
:query => {
|
82
|
+
:appkey => @appkey,
|
83
|
+
:format => 'json',
|
84
|
+
},
|
85
|
+
:body => (build_body(urls, 'url'))+"&"+(build_body(feeds, 'feed_hash'))
|
86
|
+
}
|
87
|
+
http = post("#{V1_API_BASE}/postrank", req)
|
88
|
+
parse(http.response)
|
89
|
+
end
|
90
|
+
|
91
|
+
|
47
92
|
def top_posts(feed, opts = {})
|
48
93
|
req = {
|
49
94
|
:query => {
|
@@ -142,6 +187,14 @@ module PostRank
|
|
142
187
|
dispatch(:get, url, req)
|
143
188
|
end
|
144
189
|
|
190
|
+
def build_body(urls, key)
|
191
|
+
[urls].flatten.map { |e| "#{key}[]=#{e}" }.join("&")
|
192
|
+
end
|
193
|
+
|
194
|
+
def post(url, req)
|
195
|
+
dispatch(:post, url, req)
|
196
|
+
end
|
197
|
+
|
145
198
|
def dispatch(method, url, req)
|
146
199
|
if EM.reactor_running?
|
147
200
|
http = EM::HttpRequest.new(url).send(method, req)
|
@@ -153,5 +206,5 @@ module PostRank
|
|
153
206
|
end
|
154
207
|
http
|
155
208
|
end
|
156
|
-
end
|
157
209
|
end
|
210
|
+
end
|
data/postrank-api.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{postrank-api}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ilya Grigorik"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-07-28}
|
13
13
|
s.description = %q{PostRank API Wrapper}
|
14
14
|
s.email = %q{ilya@igvita.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/spec/api_spec.rb
CHANGED
@@ -5,7 +5,6 @@ require 'pp'
|
|
5
5
|
describe PostRank::API do
|
6
6
|
IGVITA = '421df2d86ab95100de7dcc2e247a08ab'
|
7
7
|
EVERBURNING = 'cb3e81ac96fb0ada1212dfce4f329474'
|
8
|
-
|
9
8
|
let(:api) { PostRank::API.new('test') }
|
10
9
|
|
11
10
|
it "should initialize with appkey" do
|
@@ -71,6 +70,28 @@ describe PostRank::API do
|
|
71
70
|
end
|
72
71
|
end
|
73
72
|
|
73
|
+
describe "Recommendations API" do
|
74
|
+
|
75
|
+
it "should fetch recommendations for a single feed" do
|
76
|
+
EM.synchrony do
|
77
|
+
resp = api.recommendations(IGVITA)
|
78
|
+
resp.class.should == Array
|
79
|
+
EM.stop
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should fetch recommendation for a set of feeds" do
|
84
|
+
EM.synchrony do
|
85
|
+
resp = api.recommendations([IGVITA, EVERBURNING], :num => 1)
|
86
|
+
|
87
|
+
resp.class.should == Array
|
88
|
+
resp.size.should == 1
|
89
|
+
|
90
|
+
EM.stop
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
74
95
|
describe "Top Posts API" do
|
75
96
|
it "should fetch top posts for a feed" do
|
76
97
|
EM.synchrony do
|
@@ -85,6 +106,44 @@ describe PostRank::API do
|
|
85
106
|
end
|
86
107
|
end
|
87
108
|
|
109
|
+
describe "Metrics Versioned API" do
|
110
|
+
it "should fetch metrics for a single post" do
|
111
|
+
EM.synchrony do
|
112
|
+
met = api.metrics_versioned('b0432f947bc0d44766d046bfc3c15043', {:start => '5 years ago', :end => 'today'})
|
113
|
+
met.class.should == Hash
|
114
|
+
met.keys.size.should == 1
|
115
|
+
EM.stop
|
116
|
+
end
|
117
|
+
end
|
118
|
+
it "should fetch metrics for multiple posts" do
|
119
|
+
EM.synchrony do
|
120
|
+
met = api.metrics_versioned(['b0432f947bc0d44766d046bfc3c15043', 'a020c1c3a5b2aef1ab4a7307cf3d2cb6'], {:start => '5 years ago', :end => 'today'})
|
121
|
+
met.class.should == Hash
|
122
|
+
met.keys.size.should == 2
|
123
|
+
EM.stop
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
describe "Postrank API" do
|
129
|
+
it "should fetch postrank with respect to provided urls" do
|
130
|
+
EM.synchrony do
|
131
|
+
pr = api.postrank(['http://www.igvita.com/2008/06/19/splunk-your-distributed-logs-in-ec2/', 'http://www.igvita.com/2008/02/11/nginx-and-memcached-a-400-boost/'])
|
132
|
+
pr.class.should == Hash
|
133
|
+
pr.keys.size.should == 2
|
134
|
+
EM.stop
|
135
|
+
end
|
136
|
+
end
|
137
|
+
it "should fetch postrank with respect specific feeds" do
|
138
|
+
EM.synchrony do
|
139
|
+
pr = api.postrank(['http://www.igvita.com/2008/06/19/splunk-your-distributed-logs-in-ec2/', 'http://www.igvita.com/2008/02/11/nginx-and-memcached-a-400-boost/'], ['421df2d86ab95100de7dcc2e247a08ab'])
|
140
|
+
pr.class.should == Hash
|
141
|
+
pr.keys.size.should == 2
|
142
|
+
EM.stop
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
88
147
|
describe "Feed Engagement API" do
|
89
148
|
it "should fetch engagement for a feed" do
|
90
149
|
EM.synchrony do
|
@@ -169,7 +228,6 @@ describe PostRank::API do
|
|
169
228
|
|
170
229
|
it "should invoke and kill EM reactor transparently" do
|
171
230
|
metrics = api.metrics('1c1a5357e8bd00128db845b2595d5ebe')
|
172
|
-
|
173
231
|
metrics.keys.size.should == 1
|
174
232
|
metrics['1c1a5357e8bd00128db845b2595d5ebe'].class.should == Hash
|
175
233
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 3
|
9
|
+
version: 0.1.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Ilya Grigorik
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-07-28 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|