Module: UmengMsg::Params

Extended by:
Params
Included in:
Params
Defined in:
lib/umeng_msg/params.rb

Instance Method Summary collapse

Instance Method Details

#cancel_params(platform, task_id) ⇒ Object



85
86
87
88
89
90
91
# File 'lib/umeng_msg/params.rb', line 85

def cancel_params(platform, task_id)
  {
    'appkey'    => UmengMsg.appkey(platform),
    'timestamp' => Time.now.to_i.to_s,
    'task_id'   => task_id
  }
end

#check_params(platform, task_id) ⇒ Object



78
79
80
81
82
83
84
# File 'lib/umeng_msg/params.rb', line 78

def check_params(platform, task_id)
  {
    'appkey'    => UmengMsg.appkey(platform),
    'timestamp' => Time.now.to_i.to_s,
    'task_id'   => task_id
  }
end

#push_params(platform, **options) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/umeng_msg/params.rb', line 6

def push_params(platform, **options)
  params = {
    'appkey'          => UmengMsg.appkey(platform),
    'timestamp'       => Time.now.to_i.to_s,
    'type'            => options['type'],
    'device_tokens'   => options['device_tokens'],
    'alias_type'      => options['alias_type'],
    'file_id'         => options['file_id'],
    'policy'          => {
                           'start_time'   => options['start_time'],
                           'expire_time'  => options['expire_time'],
                           'max_send_num' => options['max_send_num'],
                         },
    'production_mode' => UmengMsg.production_mode,
    'description'     => options['description'],
    'thirdparty_id'   => options['thirdparty_id']
  }

  # 平台参数
  ios_payload = {
    'payload' => {
      'aps' => {
        'alert'             => options['alert'],
        'badge'             => options['badge'],
        'sound'             => options['sound'],
        'content-available' => options['content-available'],
        'category'          => options['category']
      },
    }
  }
  android_payload = {
    'payload' => {
      'display_type' => options['display_type'],
      'body' => {
        'ticker'       => options['ticker'],
        'title'        => options['title'],
        'text'         => options['text'],
        'icon'         => options['icon'],
        'largeIcon'    => options['largeIcon'],
        'img'          => options['img'],
        'sound'        => options['sound'],
        'builder_id'   => (options['builder_id'] || 0),
        'play_vibrate' => (options['play_vibrate'] || 'true'),
        'play_lights'  => (options['play_lights'] || 'true'),
        'play_sound'   => (options['play_sound'] || 'true'),
        'after_open'   => (options['after_open'] || 'go_app'),
        'url'          => options['url'],
        'activity'     => options['activity'],
        'custom'       => options['custom']
      },
      'extra' => {
      }
    }

  }

  # TODO 组播过滤
  # if type == "groupcast"
  #   tag_list = targets.split(",")
  #   tag_list.map! { |tag| {tag: tag} }
  #   params = {
  #     filter: {
  #       where: {
  #         "and" => [{ "or" => tag_list }]
  #       }
  #     }
  #   }.merge(params)
  # end

  platform.downcase == 'ios' ? params.merge(ios_payload) : params.merge(android_payload)
end

#upload_params(platform, content) ⇒ Object



93
94
95
96
97
98
99
# File 'lib/umeng_msg/params.rb', line 93

def upload_params(platform, content)
  {
    'appkey'    => UmengMsg.appkey(platform),
    'timestamp' => Time.now.to_i.to_s,
    'content'   => content
  }
end