Baidupush 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/Baidupush/base.rb +2 -3
- data/lib/Baidupush/{api.rb → push_notice.rb} +32 -7
- data/lib/Baidupush/sa +11 -0
- data/lib/Baidupush/version.rb +1 -1
- data/lib/rails/generators/Baidupush/config/config_generator.rb +1 -1
- data/test/test_base.rb +71 -0
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc1ff5eb3d193b3b3cb91cbbc4c0028ef864f72e
|
4
|
+
data.tar.gz: 8f10829d54e0c16e3109bc929def023e7b66de88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b982f1208fbd593540534c051975f1ac2d6de926c7448e5f74f18403197e8f887a07897663befaa77ea6efd41187b12a19e5fc54e1512f2cfda37e8f2d9f7304
|
7
|
+
data.tar.gz: d94edb06c53ae190d979c58e1d90d2a26afce34d397b7d961064ab694d38c30049391770c97c2fa1f005bed5b1be0e786cd2de2c52ea4363d258e7a789019739
|
data/lib/Baidupush/base.rb
CHANGED
@@ -34,9 +34,9 @@ module Baidupush
|
|
34
34
|
str += "#{key}=#{params[key]}"
|
35
35
|
end
|
36
36
|
str += "#{secertkey}"
|
37
|
-
p "**STR:#{str}"
|
37
|
+
#p "**STR:#{str}"
|
38
38
|
str = CGI::escape(str)
|
39
|
-
p "**Str: #{str}"
|
39
|
+
#p "**Str: #{str}"
|
40
40
|
sign = Digest::MD5.hexdigest(str)
|
41
41
|
sign
|
42
42
|
end
|
@@ -70,7 +70,6 @@ module Baidupush
|
|
70
70
|
def self.http_get(url,args)
|
71
71
|
uri = URI.parse(url)
|
72
72
|
uri.query = URI.encode_www_form(args)
|
73
|
-
p "URL : #{uri}"
|
74
73
|
http = Net::HTTP.new(uri.host, uri.port)
|
75
74
|
request = Net::HTTP::Get.new(uri.request_uri)
|
76
75
|
time_start = Time.now.to_i
|
@@ -4,7 +4,7 @@ require "#{File.dirname(__FILE__)}/base"
|
|
4
4
|
require 'securerandom'
|
5
5
|
|
6
6
|
module Baidupush
|
7
|
-
class
|
7
|
+
class PushNotice
|
8
8
|
# To change this template use File | Settings | File Templates.
|
9
9
|
|
10
10
|
HTTP_METHOD_POST = "POST"
|
@@ -159,10 +159,6 @@ module Baidupush
|
|
159
159
|
push_config
|
160
160
|
end
|
161
161
|
|
162
|
-
def push_msg_ios(options={})
|
163
|
-
|
164
|
-
end
|
165
|
-
|
166
162
|
|
167
163
|
#"title" : "hello" ,
|
168
164
|
# “description: "hello world"
|
@@ -184,9 +180,20 @@ module Baidupush
|
|
184
180
|
params.merge!({key.to_s=>value})
|
185
181
|
end
|
186
182
|
params.merge!("custom_content"=>custom_content)
|
183
|
+
#p "Android_msg: #{params}"
|
187
184
|
params
|
188
185
|
end
|
189
186
|
|
187
|
+
def get_ios_msg(msg,options={})
|
188
|
+
options = _params_default(options,DEFAULT_IOS_FIELD)
|
189
|
+
if msg.class!=Hash
|
190
|
+
raise RuntimeError,"推送苹果的消息应为Hash"
|
191
|
+
end
|
192
|
+
params = {:aps=>options}
|
193
|
+
msg.each do |key,value|
|
194
|
+
params.merge!(key=>value)
|
195
|
+
end
|
196
|
+
end
|
190
197
|
|
191
198
|
#options:
|
192
199
|
#method string 是 方法名,必须存在:push_msg。
|
@@ -223,6 +230,16 @@ module Baidupush
|
|
223
230
|
request_server(options)
|
224
231
|
end
|
225
232
|
|
233
|
+
|
234
|
+
#deploy_status: 1:开发 2:生产
|
235
|
+
def push_msg_ios(send_ios_msg,options={})
|
236
|
+
options = _params_default(options,DEFAULT_REQUREST_BAIDU_METHOD)
|
237
|
+
options = _params_default(options,DEFAULT_PUSH_CONFIG)
|
238
|
+
options[:msg_keys] = Time.now.to_i.to_s + ::SecureRandom.uuid.gsub!("-","")
|
239
|
+
options.merge!(:messages => send_ios_msg)
|
240
|
+
request_server(options)
|
241
|
+
end
|
242
|
+
|
226
243
|
#---------推送相关函数------------END-------------------------------------------
|
227
244
|
|
228
245
|
|
@@ -268,8 +285,8 @@ module Baidupush
|
|
268
285
|
#类初始值
|
269
286
|
DEFAULT_API = {
|
270
287
|
:name => "测试应用",
|
271
|
-
:secret_key => "
|
272
|
-
:api_key => "
|
288
|
+
:secret_key => "7RmGeGbCmzwfWmrtQKtXb3q28p3IlhH3",
|
289
|
+
:api_key => "GVdWkcfOcAYNODhqWPPooQT6",
|
273
290
|
:url => "http://channel.api.duapp.com/rest/2.0/channel/channel",
|
274
291
|
}
|
275
292
|
|
@@ -301,6 +318,14 @@ module Baidupush
|
|
301
318
|
:pkg_version=>"0.1",
|
302
319
|
}
|
303
320
|
|
321
|
+
|
322
|
+
#apple的推送消息初始化设置
|
323
|
+
DEFAULT_IOS_FIELD = {
|
324
|
+
:alert=>"Message From Baidu Push",
|
325
|
+
:Sound=>"",
|
326
|
+
:Badge=>0
|
327
|
+
}
|
328
|
+
|
304
329
|
#推送类型函数的初始化设置
|
305
330
|
DEFAULT_PUSH_CONFIG = {
|
306
331
|
:method => "push_msg",
|
data/lib/Baidupush/sa
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
POSThttp://channel.api.duapp.com/rest/2.0/channel/channelapikey=AIgqItcV8tHLwfnO72QSBn9cchannel_id=11111111111device_type=3message_type=0messages=Hello Channelmethod=push_msgmsg_keys=channel_msg_keypush_type=1timestamp=1381817628user_id=1111111111111kckoI6PGF3FMhdA7mLjpGLi5Ukuedm91
|
2
|
+
POSThttp://channel.api.duapp.com/rest/2.0/channel/channelapikey=AIgqItcV8tHLwfnO72QSBn9cchannel_id=11111111111device_type=3message_type=0messages=Hello Channelmethod=push_msgmsg_keys=channel_msg_keypush_type=1timestamp=1381817628user_id=1111111111111kckoI6PGF3FMhdA7mLjpGLi5Ukuedm91
|
3
|
+
|
4
|
+
|
5
|
+
POSThttp%3A%2F%2Fchannel.api.duapp.com%2Frest%2F2.0%2Fchannel%2Fchannelapikey%3DAIgqItcV8tHLwfnO72QSBn9cchannel_id%3D11111111111device_type%3D3message_type%3D0messages%3DHello+Channelmethod%3Dpush_msgmsg_keys%3Dchannel_msg_keypush_type%3D1timestamp%3D1381817628user_id%3D1111111111111kckoI6PGF3FMhdA7mLjpGLi5Ukuedm91
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
8c7879008203e18e0898af7a7d1e6ad2
|
11
|
+
1e7d1022f004788f8e2e6ea7a39725e1
|
data/lib/Baidupush/version.rb
CHANGED
@@ -6,7 +6,7 @@ module Baidupush
|
|
6
6
|
class ConfigGenerator < Rails::Generators::Base
|
7
7
|
desc "Creates a baidu_cloud_push configuration file at config/baidu_push.yml"
|
8
8
|
|
9
|
-
def create_config_file
|
9
|
+
def self.create_config_file
|
10
10
|
template 'baidu_cloud_push.yml', File.join('config', 'baidu_cloud_push.yml')
|
11
11
|
end
|
12
12
|
|
data/test/test_base.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
#encoding:utf-8
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require "#{File.dirname(__FILE__)}/../lib/Baidupush/base"
|
5
|
+
require "#{File.dirname(__FILE__)}/../lib/Baidupush/push"
|
6
|
+
|
7
|
+
class TestBase < Test::Unit::TestCase
|
8
|
+
# To change this template use File | Settings | File Templates.
|
9
|
+
include Baidupush
|
10
|
+
|
11
|
+
def test_api_query_bindlist
|
12
|
+
assert_block do
|
13
|
+
p "Request query bindlist"
|
14
|
+
api = PushNotice.new
|
15
|
+
ret = api.query_bindlist
|
16
|
+
p ret
|
17
|
+
ret
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_send_msg_andriod
|
22
|
+
assert_block do
|
23
|
+
p "Request Send msg andriod"
|
24
|
+
api = PushNotice.new
|
25
|
+
ret = api.push_msg_andriod(api.get_android_msg("测试","这是个测试",{"c1"=>1,"c2"=>2}))
|
26
|
+
p ret
|
27
|
+
ret
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_send_msg_ios
|
32
|
+
assert_block do
|
33
|
+
p "Request Send msg IOS"
|
34
|
+
api = PushNotice.new
|
35
|
+
ret = api.push_msg_andriod(api.get_ios_msg({"test"=>"这是个测试"},{:deploy_status=>1}))
|
36
|
+
p ret
|
37
|
+
ret
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_set_tag
|
42
|
+
assert_block do
|
43
|
+
p "Requrest Set tag"
|
44
|
+
api = PushNotice.new
|
45
|
+
ret = api.tag_set
|
46
|
+
p ret
|
47
|
+
ret
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_fetch_tag
|
52
|
+
assert_block do
|
53
|
+
p "Request Fetch tag"
|
54
|
+
api = PushNotice.new
|
55
|
+
ret = api.tag_fetch
|
56
|
+
p ret
|
57
|
+
ret
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_delete_tag
|
62
|
+
assert_block do
|
63
|
+
p "Request Delete tag"
|
64
|
+
api = PushNotice.new
|
65
|
+
ret = api.tag_delete
|
66
|
+
p ret
|
67
|
+
ret
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Baidupush
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zql
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -53,12 +53,14 @@ files:
|
|
53
53
|
- README.md
|
54
54
|
- Rakefile
|
55
55
|
- lib/Baidupush.rb
|
56
|
-
- lib/Baidupush/api.rb
|
57
56
|
- lib/Baidupush/base.rb
|
58
57
|
- lib/Baidupush/base_error.rb
|
58
|
+
- lib/Baidupush/push_notice.rb
|
59
|
+
- lib/Baidupush/sa
|
59
60
|
- lib/Baidupush/version.rb
|
60
61
|
- lib/rails/generators/Baidupush/config/config_generator.rb
|
61
62
|
- lib/rails/generators/Baidupush/config/templates/baidu_cloud_push.yml
|
63
|
+
- test/test_base.rb
|
62
64
|
homepage: ''
|
63
65
|
licenses:
|
64
66
|
- MIT
|
@@ -83,4 +85,5 @@ rubygems_version: 2.0.3
|
|
83
85
|
signing_key:
|
84
86
|
specification_version: 4
|
85
87
|
summary: 百度云推送
|
86
|
-
test_files:
|
88
|
+
test_files:
|
89
|
+
- test/test_base.rb
|