umeng_msg 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +25 -0
- data/README.md +9 -3
- data/lib/umeng_msg/params.rb +14 -5
- data/lib/umeng_msg/subject.rb +17 -54
- data/lib/umeng_msg/version.rb +1 -1
- data/lib/umeng_msg.rb +1 -2
- metadata +4 -5
- data/lib/umeng_msg/logger.rb +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 416ff86f4b0879074f320006544565a366888f5f
|
4
|
+
data.tar.gz: 702c92ae3d94f423702c0103444538816a6b7439
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e92008fec996c1dfb3e5fc1f9b2a91dd32c905d7e3cc8f3a81b724ac8e26dec19cf576ba48a333b3db753e6c8b534ec6ad1f3e319198db528e4c34d3491ee468
|
7
|
+
data.tar.gz: 6acd68399a169365f65f82d967ab0980ccc0c564b17f789c6a68ab4e4c03452e52e46b08c640c55313f8ea7c91a9f6ec6da8eb33c12b58710522b94e2198afd7
|
data/LICENSE
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
copyright (c) <year> <copyright holders>
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
The above copyright notice and this permission notice shall be included in
|
15
|
+
all copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
25
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# UmengMsg
|
2
2
|
|
3
|
-
|
3
|
+
此gem是对友盟推送的api封装,支持推送 查询 删除 以及上传文件
|
4
|
+
推送部分功能待实施 再todo中
|
4
5
|
|
5
6
|
TODO: Delete this and the text above, and describe your gem
|
6
7
|
|
@@ -21,8 +22,13 @@ Or install it yourself as:
|
|
21
22
|
$ gem install umeng_msg
|
22
23
|
|
23
24
|
## Usage
|
24
|
-
|
25
|
-
|
25
|
+
1. rails generate umeng_msg:install
|
26
|
+
2. UmengMsg::Subject.new('ios', options).push #or upload check cancel
|
27
|
+
3. options 示例: {'task_id': 'xxxxx'}
|
28
|
+
4. 推送相关options参数请参看官方文档, check 与 cancel 只需要 task_id参数, upload 只需要content 参数
|
29
|
+
5. 返回结果以error_code 为nil 表示发送成功, error_code 为999 时为网络等错误与友盟无关
|
30
|
+
6. 拓展或自定义功能请自行拓展
|
31
|
+
7. 默认请求超时是3秒
|
26
32
|
|
27
33
|
## Development
|
28
34
|
|
data/lib/umeng_msg/params.rb
CHANGED
@@ -3,13 +3,14 @@ module UmengMsg
|
|
3
3
|
module Params
|
4
4
|
extend self
|
5
5
|
|
6
|
-
def push_params(platform,
|
6
|
+
def push_params(platform, options)
|
7
7
|
params = {
|
8
8
|
'appkey' => UmengMsg.appkey(platform),
|
9
9
|
'timestamp' => Time.now.to_i.to_s,
|
10
10
|
'type' => options['type'],
|
11
11
|
'device_tokens' => options['device_tokens'],
|
12
12
|
'alias_type' => options['alias_type'],
|
13
|
+
'alias' => options['alias'],
|
13
14
|
'file_id' => options['file_id'],
|
14
15
|
'policy' => {
|
15
16
|
'start_time' => options['start_time'],
|
@@ -31,6 +32,8 @@ module UmengMsg
|
|
31
32
|
'content-available' => options['content-available'],
|
32
33
|
'category' => options['category']
|
33
34
|
},
|
35
|
+
'title' => options['title'],
|
36
|
+
'extra' => options['extra'] || {}
|
34
37
|
}
|
35
38
|
}
|
36
39
|
android_payload = {
|
@@ -53,8 +56,7 @@ module UmengMsg
|
|
53
56
|
'activity' => options['activity'],
|
54
57
|
'custom' => options['custom']
|
55
58
|
},
|
56
|
-
'extra' => {
|
57
|
-
}
|
59
|
+
'extra' => options['extra'] || {}
|
58
60
|
}
|
59
61
|
|
60
62
|
}
|
@@ -72,7 +74,8 @@ module UmengMsg
|
|
72
74
|
# }.merge(params)
|
73
75
|
# end
|
74
76
|
|
75
|
-
platform.downcase == 'ios' ? params.merge(ios_payload) : params.merge(android_payload)
|
77
|
+
platform.downcase == 'ios' ? params.merge!(ios_payload) : params.merge!(android_payload)
|
78
|
+
params = compact_params(params)
|
76
79
|
end
|
77
80
|
|
78
81
|
def check_params(platform, task_id)
|
@@ -97,6 +100,12 @@ module UmengMsg
|
|
97
100
|
'content' => content
|
98
101
|
}
|
99
102
|
end
|
103
|
+
|
104
|
+
private
|
105
|
+
#取出nil的key 不然友盟解析json出错
|
106
|
+
def compact_params(params)
|
107
|
+
custom_compact = Proc.new { |k, v| v.delete_if(&custom_compact) if v.kind_of?(Hash); v.blank? }
|
108
|
+
params.delete_if &custom_compact
|
109
|
+
end
|
100
110
|
end
|
101
111
|
end
|
102
|
-
|
data/lib/umeng_msg/subject.rb
CHANGED
@@ -10,82 +10,45 @@ module UmengMsg
|
|
10
10
|
CANCEL_URL = 'http://msg.umeng.com/api/cancel'
|
11
11
|
UPLOAD_URL = 'http://msg.umeng.com/upload'
|
12
12
|
|
13
|
-
def initialize(platform,
|
13
|
+
def initialize(platform, options)
|
14
14
|
@platform = platform
|
15
|
-
@
|
16
|
-
@content = options['content']
|
17
|
-
@file_id, @task_id = nil
|
18
|
-
@ret = { push: nil, check: nil, cancel: nil, upload: nil }
|
19
|
-
@error_code = { push: nil, check: nil, cancel: nil, upload: nil }
|
15
|
+
@options = options
|
20
16
|
end
|
21
17
|
|
22
18
|
def push
|
23
|
-
|
24
|
-
begin
|
25
|
-
parse_res RestClient.post("#{PUSH_URL}?sign=#{sign}", @payload.to_json, content_type: :json, accept: :json)
|
26
|
-
rescue => e
|
27
|
-
parse_res e.response
|
28
|
-
end
|
19
|
+
post_youmeng(CANCEL_URL, Params.push_params(@platform, @options))
|
29
20
|
end
|
30
21
|
|
31
22
|
def check
|
32
|
-
|
33
|
-
sign = Sign.generate @platform, CHECK_URL, @check_payload
|
34
|
-
begin
|
35
|
-
parse_res RestClient.post("#{CHECK_URL}?sign=#{sign}", @check_payload.to_json, content_type: :json, accept: :json)
|
36
|
-
rescue => e
|
37
|
-
parse_res e.response
|
38
|
-
end
|
23
|
+
post_youmeng(CANCEL_URL, Params.check_params(@platform, @options['task_id']))
|
39
24
|
end
|
40
25
|
|
41
26
|
def cancel
|
42
|
-
|
43
|
-
sign = Sign.generate @platform, CANCEL_URL, @cancel_payload
|
44
|
-
begin
|
45
|
-
parse_res RestClient.post("#{CANCEL_URL}?sign=#{sign}", @cancel_payload.to_json, content_type: :json, accept: :json)
|
46
|
-
rescue => e
|
47
|
-
parse_res e.response
|
48
|
-
end
|
27
|
+
post_youmeng(CANCEL_URL, Params.cancel_params(@platform, @options['task_id']))
|
49
28
|
end
|
50
29
|
|
51
30
|
def upload
|
52
|
-
|
53
|
-
|
31
|
+
post_youmeng(UPLOAD_URL, Params.upload_params(@platform, @options['content']))
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
def post_youmeng(url, payload)
|
36
|
+
sign = Sign.generate @platform, url, payload
|
54
37
|
begin
|
55
|
-
parse_res RestClient.post("#{
|
38
|
+
parse_res RestClient.post("#{url}?sign=#{sign}", payload.to_json, timeout: 3, open_timeout: 3, content_type: :json, accept: :json)
|
56
39
|
rescue => e
|
57
|
-
|
40
|
+
error_result e.message
|
58
41
|
end
|
59
42
|
end
|
60
43
|
|
61
|
-
private
|
62
|
-
|
63
44
|
def parse_res response
|
64
|
-
|
65
|
-
|
66
|
-
@error_code[:push] = res_hsh['data']['error_code']
|
67
|
-
@task_id = res_hsh['data']['task_id']
|
45
|
+
result = JSON.parse(response)
|
46
|
+
{result: result['ret'], error_code: result['data']['error_code'], data: result['data']}
|
68
47
|
end
|
69
48
|
|
70
|
-
def
|
71
|
-
|
72
|
-
@ret[:check] = res_hsh['ret']
|
73
|
-
@error_code[:check] = res_hsh['data']['error_code']
|
74
|
-
@check_data = res_hsh['data']
|
49
|
+
def error_result(error_message)
|
50
|
+
{result: error_message, error_code: '999', data: {}}
|
75
51
|
end
|
76
52
|
|
77
|
-
def cancel_parse
|
78
|
-
res_hsh = JSON.parse(response)
|
79
|
-
@ret[:cancel] = res_hsh['ret']
|
80
|
-
@error_code[:cancel] = res_hsh['data']['error_code']
|
81
|
-
end
|
82
|
-
|
83
|
-
def upload_parse response
|
84
|
-
res_hsh = JSON.parse(response)
|
85
|
-
@ret[:upload] = res_hsh['ret']
|
86
|
-
@error_code[:upload] = res_hsh['data']['error_code']
|
87
|
-
@file_id = res_hsh['data']['file_id']
|
88
|
-
end
|
89
53
|
end
|
90
54
|
end
|
91
|
-
|
data/lib/umeng_msg/version.rb
CHANGED
data/lib/umeng_msg.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: umeng_msg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hzlu
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -91,6 +91,7 @@ files:
|
|
91
91
|
- ".rspec"
|
92
92
|
- ".travis.yml"
|
93
93
|
- Gemfile
|
94
|
+
- LICENSE
|
94
95
|
- README.md
|
95
96
|
- Rakefile
|
96
97
|
- bin/console
|
@@ -99,7 +100,6 @@ files:
|
|
99
100
|
- lib/generators/umeng_msg/templates/umeng_msg.rb
|
100
101
|
- lib/umeng_msg.rb
|
101
102
|
- lib/umeng_msg/configuration.rb
|
102
|
-
- lib/umeng_msg/logger.rb
|
103
103
|
- lib/umeng_msg/params.rb
|
104
104
|
- lib/umeng_msg/sign.rb
|
105
105
|
- lib/umeng_msg/subject.rb
|
@@ -124,9 +124,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
124
|
version: '0'
|
125
125
|
requirements: []
|
126
126
|
rubyforge_project:
|
127
|
-
rubygems_version: 2.
|
127
|
+
rubygems_version: 2.5.1
|
128
128
|
signing_key:
|
129
129
|
specification_version: 4
|
130
130
|
summary: The encapsulation of umeng message.
|
131
131
|
test_files: []
|
132
|
-
has_rdoc:
|
data/lib/umeng_msg/logger.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
module UmengMsg
|
2
|
-
module Logger
|
3
|
-
def logger_file
|
4
|
-
Rails.root.join("log", "umeng_push.log")
|
5
|
-
end
|
6
|
-
|
7
|
-
def error_file
|
8
|
-
Rails.root.join("log", "error.log")
|
9
|
-
end
|
10
|
-
|
11
|
-
def umeng_logger
|
12
|
-
@logger ||= Yell.new do |l|
|
13
|
-
l.level = 'gte.info'
|
14
|
-
|
15
|
-
l.adapter :datefile, logger_file, level: 'lte.error', keep: 5
|
16
|
-
l.adapter :datefile, error_file, level: 'gte.error', keep:5
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|