Class: Ixintui::Service
- Inherits:
-
Object
show all
- Defined in:
- lib/ixintui/service.rb
Class Method Summary
collapse
Class Method Details
.app_key ⇒ Object
6
7
|
# File 'lib/ixintui/service.rb', line 6
def self.app_key
end
|
.app_secret_key ⇒ Object
9
10
|
# File 'lib/ixintui/service.rb', line 9
def self.app_secret_key
end
|
.base_data ⇒ Object
12
13
14
15
16
17
|
# File 'lib/ixintui/service.rb', line 12
def self.base_data
{
appkey: app_key,
is_notif: 1
}
end
|
.push(options = {}) ⇒ Object
39
40
41
42
43
44
45
46
|
# File 'lib/ixintui/service.rb', line 39
def self.push(options = {})
params = base_data.merge(options)
params = validates(params)
params[:sign] = sign(params)
res = RestClient.post(server, JSON.dump(params), content_type: :json)
JSON.parse(res.body)
end
|
.server ⇒ Object
3
4
|
# File 'lib/ixintui/service.rb', line 3
def self.server
end
|
.sign(params) ⇒ Object
19
20
21
22
23
24
|
# File 'lib/ixintui/service.rb', line 19
def self.sign(params)
data = Hash[params.sort]
string = JSON.dump(data)
string += app_secret_key
Digest::MD5.hexdigest(string)
end
|
.validates(params) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/ixintui/service.rb', line 26
def self.validates(params)
case params[:click_action]
when 'open_app', 'open_url', 'intent'
raise ArgumentError, "设置了 click_action 参数为 '#{params[:click_action]}' 但是没有设置 #{params[:click_action]} 参数" if params[params[:click_action].to_sym].blank?
else
params[:click_action] = 'open_app'
params[:open_app] = true
end
raise ArgumentError, "app_key 未设置" if params[:appkey].blank?
return params
end
|