renren-api 0.3.4 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/renren-api.rb +1 -1
- data/lib/renren-api/http_adapter.rb +12 -0
- data/spec/http_adapter_spec.rb +47 -0
- metadata +2 -2
data/lib/renren-api.rb
CHANGED
@@ -33,6 +33,18 @@ module RenrenAPI
|
|
33
33
|
}
|
34
34
|
request(params)
|
35
35
|
end
|
36
|
+
def send_notification(receiver_ids, notification)
|
37
|
+
request(
|
38
|
+
:api_key => @api_key,
|
39
|
+
:method => "notifications.send",
|
40
|
+
:call_id => current_time_in_millisecond,
|
41
|
+
:v => "1.0",
|
42
|
+
:session_key => @session_key,
|
43
|
+
:format => "JSON",
|
44
|
+
:to_ids => receiver_ids * ",",
|
45
|
+
:notification => notification
|
46
|
+
)
|
47
|
+
end
|
36
48
|
private
|
37
49
|
def current_time_in_millisecond
|
38
50
|
"%.3f" % Time.now.to_f
|
data/spec/http_adapter_spec.rb
CHANGED
@@ -96,3 +96,50 @@ describe RenrenAPI::HTTPAdapter, "#get_info" do
|
|
96
96
|
end
|
97
97
|
it { should == result }
|
98
98
|
end
|
99
|
+
|
100
|
+
describe RenrenAPI::HTTPAdapter, "#send_notification" do
|
101
|
+
subject { described_class.new(http, api_key, secret_key, session_key).send_notification(receiver_ids, notification) }
|
102
|
+
let(:http) { Net::HTTP.new("api.renren.com") }
|
103
|
+
let(:api_key) { "8802f8e9b2cf4eb993e8c8adb1e02b06" }
|
104
|
+
let(:secret_key) { "34d3d1e26cd44c05a0c450c0a0f8147b" }
|
105
|
+
let(:session_key) { "session_key" }
|
106
|
+
let(:result) do
|
107
|
+
{"result" => 1}
|
108
|
+
end
|
109
|
+
let!(:now) do
|
110
|
+
Time.now
|
111
|
+
end
|
112
|
+
let(:receiver_ids) do
|
113
|
+
[12345, 12346]
|
114
|
+
end
|
115
|
+
let(:params) do
|
116
|
+
{
|
117
|
+
:api_key => api_key,
|
118
|
+
:method => "notifications.send",
|
119
|
+
:call_id => "%.3f" % now.to_f,
|
120
|
+
:v => "1.0",
|
121
|
+
:session_key => session_key,
|
122
|
+
:format => "JSON",
|
123
|
+
:to_ids => receiver_ids * ",",
|
124
|
+
:notification => notification
|
125
|
+
}
|
126
|
+
end
|
127
|
+
let(:notification) do
|
128
|
+
"test"
|
129
|
+
end
|
130
|
+
let(:form_params) do
|
131
|
+
signature_calculator = RenrenAPI::SignatureCalculator.new(secret_key)
|
132
|
+
signature = signature_calculator.calculate(params)
|
133
|
+
URI.encode_www_form(params.merge(:sig => signature))
|
134
|
+
end
|
135
|
+
before :each do
|
136
|
+
Time.stub(:now).and_return(now)
|
137
|
+
response = mock(Net::HTTPResponse)
|
138
|
+
gzip_writer = Zlib::GzipWriter.new(StringIO.new(buffer = ""))
|
139
|
+
gzip_writer << JSON.generate(result)
|
140
|
+
gzip_writer.close
|
141
|
+
response.stub(:code => '200', :message => "OK", :content_type => "application/json", :body => buffer)
|
142
|
+
http.should_receive(:post).with("/restserver.do", form_params, {"Accept-Encoding" => "gzip"}).once.and_return(response)
|
143
|
+
end
|
144
|
+
it { should == result }
|
145
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: renren-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: "0.4"
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Lei, Zhi-Qiang
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-05-
|
13
|
+
date: 2011-05-09 00:00:00 +08:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|