umeng 0.1.3 → 0.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7205bc19e1e3ae9022ebfe36f203d6c5d309caa4
4
- data.tar.gz: 15cde5cb45348ac742c1e7f90ed92052441cf907
3
+ metadata.gz: b5adfb51aa1f4972ff06e38a2cbbdb38d41c97ad
4
+ data.tar.gz: 547566d862759c92fddb98b7eade3fd64eb5fdc1
5
5
  SHA512:
6
- metadata.gz: 9c30236f863baff4e11a31be6768815c98c0164ad5c39f81a383cc73c94f6099248c7b120b6cdd12d977bf14e5b7352a48a93af7c544bc5d1cd10ba56e97b4f6
7
- data.tar.gz: 690e0bb15024cc3e075e7a06d59ff4d40864d3eda001fa987bdd1a21dfac45805dfd5ead0709237968c856d2aee841d76d485538c231c4ab7164196f4195d642
6
+ metadata.gz: 5771efadc6ce8085fb2d90338e61f1973d0f6109f141078aa5aff011cd3cbebd0ef8db4b1ab351ded7c0296e487d0c8f4b360f3265cafb720faa4b192df051dd
7
+ data.tar.gz: f98e6125a63f7c85ca20d6faf80c82dad1c929c9f6af990d34706aff0f0bf27260520334b076569a8e74ab6feb53d34dd8f9bc972d57e816ec4998b6ef9b0774
data/README.md CHANGED
@@ -22,9 +22,17 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
  ```
25
- ument = Umeng::Client.new(appkey, app_master_secret)
26
- umeng.push(params)
25
+ umeng = Umeng::Client.new(appkey, app_master_secret, plantform)
26
+
27
+ 广播
28
+ umeng.push_broadcast(content, opt={})
29
+ 单播
30
+ umeng.push_unicast(device_tokens, content, opt={})
31
+ 列播
32
+ umeng.push_listcast(device_tokens, content, opt={})
33
+
27
34
  umeng.status(task_id)
35
+
28
36
  umeng.cancel(task_id)
29
37
  ```
30
38
 
@@ -11,4 +11,4 @@ require "umeng"
11
11
  # Pry.start
12
12
 
13
13
  require "irb"
14
- IRB.start
14
+ IRB.start
@@ -1,21 +1,20 @@
1
1
  require 'json'
2
2
  require 'faraday'
3
3
  require 'digest'
4
- require 'umeng/services'
4
+ require 'umeng/send_message'
5
5
 
6
6
  module Umeng
7
7
  UMENG_HOST = 'http://msg.umeng.com'
8
8
 
9
9
  class Client
10
- include Umeng::Services
10
+ include Umeng::SendMessage
11
11
 
12
- attr_accessor :appkey, :app_master_secret
12
+ attr_accessor :appkey, :app_master_secretm, :plantform
13
13
 
14
- def initialize(appkey, app_master_secret)
14
+ def initialize(appkey, app_master_secret, plantform)
15
+ @plantform = plantform
15
16
  @appkey = appkey
16
17
  @app_master_secret = app_master_secret
17
18
  end
18
19
  end
19
- end
20
-
21
-
20
+ end
@@ -0,0 +1,25 @@
1
+ module Umeng
2
+ module JsonBody
3
+ def android_params(content, opt={})
4
+ display_type = opt[:display_type] || "message"
5
+ {
6
+ 'payload': {
7
+ 'display_type': display_type,
8
+ 'body': {
9
+ 'custom': content
10
+ }
11
+ }
12
+ }
13
+ end
14
+
15
+ def ios_params(content, opt={})
16
+ {
17
+ 'payload': {
18
+ 'aps': {
19
+ 'alert': content
20
+ }
21
+ }.merge(opt[:kv])
22
+ }
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,63 @@
1
+ require 'umeng/services'
2
+ require 'umeng/json_body'
3
+
4
+ module Umeng
5
+ module SendMessage
6
+ include Umeng::Services
7
+ include Umeng::JsonBody
8
+
9
+ # 广播
10
+ def push_broadcast(content, opt={})
11
+ params = {
12
+ type: 'broadcast',
13
+ description: opt['description'] || '广播',
14
+ production_mode: opt['production_mode'] || 'true'
15
+ }
16
+ case @plantform
17
+ when 'android'
18
+ params.merge! android_params(content, opt)
19
+ push(params)
20
+ when 'ios'
21
+ params.merge! ios_params(content, opt)
22
+ push(params)
23
+ end
24
+ end
25
+
26
+ # 单播
27
+ def push_unicast(device_tokens, content, opt={})
28
+ params = {
29
+ device_tokens: device_tokens,
30
+ type: 'unicast',
31
+ description: opt['description'] || '单播',
32
+ production_mode: opt['production_mode'] || 'false',
33
+ }
34
+ case @plantform
35
+ when 'android'
36
+ params.merge! android_params(content, opt)
37
+ push(params)
38
+ when 'ios'
39
+ params.merge! ios_params(content, opt)
40
+ push(params)
41
+ end
42
+ end
43
+
44
+ # 列播
45
+ def push_listcast(device_tokens, content, opt={})
46
+ params = {
47
+ device_tokens: device_tokens,
48
+ type: 'listcast',
49
+ description: opt['description'] || '列播',
50
+ production_mode: opt['production_mode'] || 'false',
51
+ }
52
+ case @plantform
53
+ when 'android'
54
+ params.merge! android_params(content, opt)
55
+ push(params)
56
+ when 'ios'
57
+ params.merge! ios_params(content, opt)
58
+ push(params)
59
+ end
60
+ end
61
+
62
+ end
63
+ end
@@ -3,7 +3,7 @@ require 'umeng/util'
3
3
  module Umeng
4
4
  module Services
5
5
  include Umeng::Util
6
-
6
+
7
7
  # 消息发送
8
8
  # POST http://msg.umeng.com/api/send?sign=mysign
9
9
  def push(params={})
@@ -7,7 +7,7 @@ module Umeng
7
7
  Digest::MD5.hexdigest([method, url, post_body, @app_master_secret].join)
8
8
  end
9
9
 
10
- {"status"=>6, "total_count"=>0, "accept_count"=>0, "sent_count"=>0, "open_count"=>0, "dismiss_count"=>0}
10
+ # {"status"=>6, "total_count"=>0, "accept_count"=>0, "sent_count"=>0, "open_count"=>0, "dismiss_count"=>0}
11
11
  def result(body, type)
12
12
  result = JSON.load(body)
13
13
 
@@ -1,3 +1,3 @@
1
1
  module Umeng
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: umeng
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - menghuanwd
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-08-18 00:00:00.000000000 Z
11
+ date: 2015-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -70,6 +70,8 @@ files:
70
70
  - bin/setup
71
71
  - lib/umeng.rb
72
72
  - lib/umeng/client.rb
73
+ - lib/umeng/json_body.rb
74
+ - lib/umeng/send_message.rb
73
75
  - lib/umeng/services.rb
74
76
  - lib/umeng/util.rb
75
77
  - lib/umeng/version.rb