Class: UmengPush::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/umeng_push/client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(platform, appkey, app_master_secret, production_mode = false) ⇒ Client

Returns a new instance of Client.



8
9
10
11
12
13
# File 'lib/umeng_push/client.rb', line 8

def initialize(platform, appkey, app_master_secret, production_mode=false)
  @platform = platform
  @appkey = appkey
  @app_master_secret = app_master_secret
  @production_mode = production_mode
end

Instance Attribute Details

#app_master_secretObject

Returns the value of attribute app_master_secret.



7
8
9
# File 'lib/umeng_push/client.rb', line 7

def app_master_secret
  @app_master_secret
end

#appkeyObject

Returns the value of attribute appkey.



7
8
9
# File 'lib/umeng_push/client.rb', line 7

def appkey
  @appkey
end

#platformObject

Returns the value of attribute platform.



7
8
9
# File 'lib/umeng_push/client.rb', line 7

def platform
  @platform
end

#production_modeObject

Returns the value of attribute production_mode.



7
8
9
# File 'lib/umeng_push/client.rb', line 7

def production_mode
  @production_mode
end

Class Method Details

.androidObject



24
25
26
27
28
29
30
31
# File 'lib/umeng_push/client.rb', line 24

def self.android
  Client.new(
    "android",
    UmengPush.configuration.android_appkey,
    UmengPush.configuration.android_app_master_secret,
    UmengPush.configuration.production_mode
  )
end

.iOSObject



15
16
17
18
19
20
21
22
# File 'lib/umeng_push/client.rb', line 15

def self.iOS
  Client.new(
    "iOS",
    UmengPush.configuration.ios_appkey,
    UmengPush.configuration.ios_app_master_secret,
    UmengPush.configuration.production_mode
  )
end

Instance Method Details

#broadcast(params = {}) ⇒ Object

广播



59
60
61
62
63
# File 'lib/umeng_push/client.rb', line 59

def broadcast(params={})
  send_message(params.merge({
      type: "broadcast"
    }))
end

#cancel_task(task_id) ⇒ Object

取消任务



83
84
85
86
87
88
89
# File 'lib/umeng_push/client.rb', line 83

def cancel_task(task_id)
  post("/api/cancel", {
      appkey: appkey,
      timestamp: timestamp,
      task_id: task_id
    })
end

#check_task(task_id) ⇒ Object

查询任务



74
75
76
77
78
79
80
# File 'lib/umeng_push/client.rb', line 74

def check_task(task_id)
  post("/api/status", {
      appkey: appkey,
      timestamp: timestamp,
      task_id: task_id
    })
end

#groupcast(filter = {}, params = {}) ⇒ Object

组播



66
67
68
69
70
71
# File 'lib/umeng_push/client.rb', line 66

def groupcast(filter={}, params={})
  send_message(params.merge({
      type: "groupcast",
      filter: filter
    }))
end

#listcast(device_tokens = [], params = {}) ⇒ Object

组播



51
52
53
54
55
56
# File 'lib/umeng_push/client.rb', line 51

def listcast(device_tokens=[], params={})
  send_message(params.merge({
      type: "listcast",
      device_tokens: device_tokens.join(",")
    }))
end

#send_message(params = {}) ⇒ Object

消息发送



34
35
36
37
38
39
40
# File 'lib/umeng_push/client.rb', line 34

def send_message(params={})
  post("/api/send", params.merge({
      appkey: appkey,
      timestamp: timestamp,
      production_mode: production_mode
    }))
end

#unicast(device_token, params = {}) ⇒ Object

单播



43
44
45
46
47
48
# File 'lib/umeng_push/client.rb', line 43

def unicast(device_token, params={})
  send_message(params.merge({
      type: "unicast",
      device_tokens: device_token
    }))
end