mobpush 1.0.1
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.
- checksums.yaml +7 -0
- data/lib/mobpush.rb +5 -0
- data/lib/mobpush/client/push/push_v3_client.rb +75 -0
- data/lib/mobpush/client/push/push_work_builder.rb +48 -0
- data/lib/mobpush/client/stat/stats_v3_client.rb +54 -0
- data/lib/mobpush/config/mobpush_config.rb +9 -0
- data/lib/mobpush/http/mob_http.rb +48 -0
- data/lib/mobpush/http/result.rb +18 -0
- data/lib/mobpush/model/push_label.rb +7 -0
- data/lib/mobpush/model/push_target.rb +12 -0
- data/lib/mobpush/utils/common_helper.rb +45 -0
- metadata +51 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9f679e4532f0123955d248a9333731bc47df5a459a24cb5cd9432af753c4fa06
|
4
|
+
data.tar.gz: 7a7dc462d3a630a9cb104b0a63bab29c3c8b47008dfa0d1b785cf9f0a85f5b0f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ad741170847eb814c89a143fe079ddfe649e67981090fb269b517f63d340952c65f4a5993f6f08cc29d40de890e0072dd7de79733cbd96da8a4f15e0196cbe90
|
7
|
+
data.tar.gz: 8e6a3f7d622abd8365e2d0b1c2ab2738dff3419ff3ca8d52ea9fb58d0b262a33891a6398c151b2ea72d13a0e9ecc66f9ced8484c9cd292201284ed9408504f88
|
data/lib/mobpush.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require "mobpush/config/mobpush_config"
|
4
|
+
require "mobpush/http/mob_http"
|
5
|
+
require_relative 'push_work_builder'
|
6
|
+
|
7
|
+
class PushV3Client
|
8
|
+
@PUSH_URI = "/v3/push/createPush"
|
9
|
+
@GET_BY_WORKID_URI = "/v3/push/getByWorkId"
|
10
|
+
@GET_BY_WORKNO_URI = "/v3/push/getByWorkno"
|
11
|
+
@CANCEL_TASK_URI = "/push/drop"
|
12
|
+
@REPLACE_TASK_URI = "/push/replace"
|
13
|
+
@RECALL_TASK_URI = "/push/recall"
|
14
|
+
|
15
|
+
class << self
|
16
|
+
attr_accessor :PUSH_URI, :GET_BY_WORKID_URI, :GET_BY_WORKNO_URI, :CANCEL_TASK_URI, :REPLACE_TASK_URI, :RECALL_TASK_URI
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
include CommonHelper
|
21
|
+
|
22
|
+
def pushTaskV3(push)
|
23
|
+
url = MobPushConfig.baseUrl + PushV3Client.PUSH_URI
|
24
|
+
MobHTTP.post(url, nil, os2hash(push))
|
25
|
+
end
|
26
|
+
|
27
|
+
def pushTaskV3ByBuilder(builder)
|
28
|
+
pushTaskV3(builder.build())
|
29
|
+
end
|
30
|
+
|
31
|
+
def pushAll(workNo, title, content)
|
32
|
+
pushTaskV3ByBuilder(PushWorkBuilder.new(workNo, title, content).targetAll())
|
33
|
+
end
|
34
|
+
|
35
|
+
def pushByAlias(workNo, title, content, *alia)
|
36
|
+
pushTaskV3ByBuilder(PushWorkBuilder.new(workNo, title, content).targetAlias(alia))
|
37
|
+
end
|
38
|
+
|
39
|
+
def pushByTags(workNo, title, content, *tags)
|
40
|
+
pushTaskV3ByBuilder(PushWorkBuilder.new(workNo, title, content).targetTags(tags))
|
41
|
+
end
|
42
|
+
|
43
|
+
def pushByRids(workNo, title, content, *rids)
|
44
|
+
pushTaskV3ByBuilder(PushWorkBuilder.new(workNo, title, content).targetRids(rids))
|
45
|
+
end
|
46
|
+
|
47
|
+
def pushByAreas(workNo, title, content, pushAreas)
|
48
|
+
pushTaskV3ByBuilder(PushWorkBuilder.new(workNo, title, content).targetAreas(pushAreas))
|
49
|
+
end
|
50
|
+
|
51
|
+
def cancelPushTask(workId)
|
52
|
+
params = {:batchId => workId}
|
53
|
+
MobHTTP.post(MobPushConfig.baseUrl + PushV3Client.CANCEL_TASK_URI, nil, params)
|
54
|
+
end
|
55
|
+
|
56
|
+
def replacePushTask(workId, content)
|
57
|
+
params = {:batchId => workId, :content => content}
|
58
|
+
MobHTTP.post(MobPushConfig.baseUrl + PushV3Client.REPLACE_TASK_URI, nil, params)
|
59
|
+
end
|
60
|
+
|
61
|
+
def recallPushTask(workId)
|
62
|
+
params = {:batchId => workId}
|
63
|
+
MobHTTP.post(MobPushConfig.baseUrl + PushV3Client.RECALL_TASK_URI, nil, params)
|
64
|
+
end
|
65
|
+
|
66
|
+
def getPushByBatchId(batchId)
|
67
|
+
params = {:workId => batchId}
|
68
|
+
MobHTTP.post(MobPushConfig.baseUrl + PushV3Client.GET_BY_WORKID_URI, nil, params)
|
69
|
+
end
|
70
|
+
|
71
|
+
def getPushByWorkno(workno)
|
72
|
+
params = {:workno => workno}
|
73
|
+
MobHTTP.post(MobPushConfig.baseUrl + PushV3Client.GET_BY_WORKNO_URI, nil, params)
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'ostruct'
|
4
|
+
require 'mobpush/model/push_target'
|
5
|
+
|
6
|
+
class PushWorkBuilder
|
7
|
+
def initialize(workno, title, content)
|
8
|
+
@push = OpenStruct.new(workno: workno, source: 'webapi')
|
9
|
+
@push.pushTarget = OpenStruct.new(tagsType: 1)
|
10
|
+
@push.pushNotify = OpenStruct.new(title: title, content: content, taskCron: 0,
|
11
|
+
plats: [1, 2], iosProduction: 1, offlineSeconds: 3600, type: 1)
|
12
|
+
@push.pushOperator = OpenStruct.new()
|
13
|
+
end
|
14
|
+
|
15
|
+
def targetAll()
|
16
|
+
@push.pushTarget.target = PushTarget::TARGET_ALL
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
def targetAlias(*alia)
|
21
|
+
@push.pushTarget.target = PushTarget::TARGET_ALIAS
|
22
|
+
@push.pushTarget.alias = alia.uniq
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
def targetTags(*tags)
|
27
|
+
@push.pushTarget.target = PushTarget::TARGET_TAGS
|
28
|
+
@push.pushTarget.tags = tags.uniq
|
29
|
+
self
|
30
|
+
end
|
31
|
+
|
32
|
+
def targetRids(*rids)
|
33
|
+
@push.pushTarget.target = PushTarget::TARGET_RIDS
|
34
|
+
@push.pushTarget.rids = rids.uniq
|
35
|
+
self
|
36
|
+
end
|
37
|
+
|
38
|
+
def targetAreas(pushAreas)
|
39
|
+
@push.pushTarget.target = PushTarget::TARGET_AREAS
|
40
|
+
@push.pushTarget.pushAreas = pushAreas
|
41
|
+
self
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
def build()
|
46
|
+
@push
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require "mobpush/config/mobpush_config"
|
4
|
+
require "mobpush/http/mob_http"
|
5
|
+
|
6
|
+
class StatsV3Client
|
7
|
+
@GET_BY_WORKID_URI = "/v3/stats/getByWorkId"
|
8
|
+
@GET_BY_WORKIDS_URI = "/v3/stats/getByWorkIds"
|
9
|
+
@GET_BY_WORKNO_URI = "/v3/stats/getByWorkno"
|
10
|
+
@GET_BY_HOUR_URI = "/v3/stats/getByHour"
|
11
|
+
@GET_BY_DAY_URI = "/v3/stats/getByDay"
|
12
|
+
@GET_BY_DEVICE_URI = "/v3/stats/getByDevice"
|
13
|
+
|
14
|
+
|
15
|
+
class << self
|
16
|
+
attr_accessor :GET_BY_WORKID_URI, :GET_BY_WORKIDS_URI, :GET_BY_WORKNO_URI, :GET_BY_HOUR_URI, :GET_BY_DAY_URI, :GET_BY_DEVICE_URI
|
17
|
+
end
|
18
|
+
|
19
|
+
def getStatsByWorkId(workId)
|
20
|
+
params = {:workId => workId}
|
21
|
+
url = MobPushConfig.baseUrl + StatsV3Client.GET_BY_WORKID_URI
|
22
|
+
MobHTTP.post(url, nil, params)
|
23
|
+
end
|
24
|
+
|
25
|
+
def getStatsByWorkIds(workIds)
|
26
|
+
params = {:workIds => workIds}
|
27
|
+
url = MobPushConfig.baseUrl + StatsV3Client.GET_BY_WORKIDS_URI
|
28
|
+
MobHTTP.post(url, nil, params)
|
29
|
+
end
|
30
|
+
|
31
|
+
def getStatsByWorkno(workno)
|
32
|
+
params = {:workno => workno}
|
33
|
+
url = MobPushConfig.baseUrl + StatsV3Client.GET_BY_WORKNO_URI
|
34
|
+
MobHTTP.post(url, nil, params)
|
35
|
+
end
|
36
|
+
|
37
|
+
def getStatsByHour(hour)
|
38
|
+
params = {:hour => hour}
|
39
|
+
url = MobPushConfig.baseUrl + StatsV3Client.GET_BY_HOUR_URI
|
40
|
+
MobHTTP.post(url, nil, params)
|
41
|
+
end
|
42
|
+
|
43
|
+
def getStatsByDay(day)
|
44
|
+
params = {:day => day}
|
45
|
+
url = MobPushConfig.baseUrl + StatsV3Client.GET_BY_DAY_URI
|
46
|
+
MobHTTP.post(url, nil, params)
|
47
|
+
end
|
48
|
+
|
49
|
+
def getStatsByDevice(workId, pageIndex, pageSize)
|
50
|
+
params = {:workId => workId, :pageIndex => pageIndex, :pageSize => pageSize}
|
51
|
+
url = MobPushConfig.baseUrl + StatsV3Client.GET_BY_DEVICE_URI
|
52
|
+
MobHTTP.post(url, nil, params)
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'mobpush/config/mobpush_config'
|
4
|
+
require 'mobpush/utils/common_helper'
|
5
|
+
require_relative 'result'
|
6
|
+
|
7
|
+
module MobHTTP
|
8
|
+
extend self
|
9
|
+
|
10
|
+
require 'digest'
|
11
|
+
require 'ostruct'
|
12
|
+
require 'net/http'
|
13
|
+
require 'json'
|
14
|
+
|
15
|
+
extend CommonHelper
|
16
|
+
|
17
|
+
def post(url, headers = nil, data)
|
18
|
+
uri = URI(url)
|
19
|
+
|
20
|
+
data["appkey"] = MobPushConfig.appkey
|
21
|
+
|
22
|
+
headers = headers.nil? ? {} : headers
|
23
|
+
headers["sign"] = serverSign(data.to_json, MobPushConfig.appSecret)
|
24
|
+
headers["key"] = MobPushConfig.appkey
|
25
|
+
headers['Content-Type'] = 'application/json'
|
26
|
+
|
27
|
+
req = Net::HTTP::Post.new(uri, headers)
|
28
|
+
req.body = data.to_json
|
29
|
+
resp = Net::HTTP.start(uri.hostname, uri.port, :read_timeout => 10, :open_timeout => 10, :write_timeout => 10) do |http|
|
30
|
+
http.request(req)
|
31
|
+
end
|
32
|
+
|
33
|
+
result = MobHttp::Result.new()
|
34
|
+
result.responseCode = resp.code.to_i
|
35
|
+
if resp.code.to_i == MobHttp::Result::SUCCESS
|
36
|
+
result.status = MobHttp::Result::SUCCESS
|
37
|
+
result.res = hash2os(JSON.parse(resp.body)['res'])
|
38
|
+
else
|
39
|
+
result.status = MobHttp::Result::ERROR
|
40
|
+
result.error = JSON.parse(resp.body)['error']
|
41
|
+
end
|
42
|
+
result
|
43
|
+
end
|
44
|
+
|
45
|
+
def serverSign(data, secret)
|
46
|
+
Digest::MD5.hexdigest(data + secret)
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'ostruct'
|
4
|
+
|
5
|
+
module CommonHelper
|
6
|
+
def sanitze_hash(h)
|
7
|
+
h.delete_if do |k, v|
|
8
|
+
v.nil? || (v.respond_to?('empty?') ? v.empty? : false)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def os2hash(os)
|
13
|
+
h = {}
|
14
|
+
os.each_pair do |k, v|
|
15
|
+
if v.is_a?(OpenStruct)
|
16
|
+
h[k] = os2hash(v)
|
17
|
+
else
|
18
|
+
h[k] = v
|
19
|
+
end
|
20
|
+
end
|
21
|
+
h
|
22
|
+
end
|
23
|
+
|
24
|
+
def hash2os(h)
|
25
|
+
if h.is_a?(Hash)
|
26
|
+
os = OpenStruct.new()
|
27
|
+
h.each do |k, v|
|
28
|
+
if v.is_a?(Hash)
|
29
|
+
os.send("#{k}=", hash2os(v))
|
30
|
+
elsif v.is_a?(Array)
|
31
|
+
os.send("#{k}=", v.map{ |e| hash2os(e)})
|
32
|
+
else
|
33
|
+
os.send("#{k}=", v)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
os
|
37
|
+
elsif h.is_a?(Array)
|
38
|
+
h.map do |e|
|
39
|
+
hash2os(e)
|
40
|
+
end
|
41
|
+
else
|
42
|
+
h
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
metadata
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mobpush
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- mobtech
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-07-29 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/mobpush.rb
|
20
|
+
- lib/mobpush/client/push/push_v3_client.rb
|
21
|
+
- lib/mobpush/client/push/push_work_builder.rb
|
22
|
+
- lib/mobpush/client/stat/stats_v3_client.rb
|
23
|
+
- lib/mobpush/config/mobpush_config.rb
|
24
|
+
- lib/mobpush/http/mob_http.rb
|
25
|
+
- lib/mobpush/http/result.rb
|
26
|
+
- lib/mobpush/model/push_label.rb
|
27
|
+
- lib/mobpush/model/push_target.rb
|
28
|
+
- lib/mobpush/utils/common_helper.rb
|
29
|
+
homepage:
|
30
|
+
licenses: []
|
31
|
+
metadata: {}
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.2'
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
requirements: []
|
47
|
+
rubygems_version: 3.0.8
|
48
|
+
signing_key:
|
49
|
+
specification_version: 4
|
50
|
+
summary: mobpush for ruby
|
51
|
+
test_files: []
|