Sha256: 85f9f8133a3bcd5f62771581aea249e177b537e2fffee7dc93056b6408cb11c1

Contents?: true

Size: 1.12 KB

Versions: 3

Compression:

Stored size: 1.12 KB

Contents

require 'umengo/util'
require 'umengo/params'

module Umengo
  module Service
    include Umengo::Util

    # 消息发送
    # POST http://msg.umeng.com/api/send?sign=mysign
    def push(type, opts={})
      uri = 'api/send'
      data = opts.fetch(:data, {}).merge({
        appkey: @appkey,
        timestamp: Time.now.to_i
      })

      payload = opts.fetch(:payload, { display_type: "notifcation"} )

      params = Params.new(
        data,
        payload,
        opts[:body],
        opts[:extra],
        opts[:policy]
      ).send "build_#{type}"

      perform(uri, params)
    end

    # 查看状态
    # POST http://msg.umeng.com/api/status?sign=mysign
    def status(task_id)
      uri = 'api/status'
      params = {
        appkey: @appkey,
        timestamp: Time.now.to_i,
        task_id: task_id
      }

      perform(uri, params)
    end

    #取消任务
    #POST http://msg.umeng.com/api/cancel?sign=mysign
    def cancel(task_id)
      uri = 'api/cancel'
      params = {
        appkey: @appkey,
        timestamp: Time.now.to_i,
        task_id: task_id
      }

      perform(uri, params)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
umengo-0.3.0 lib/umengo/service.rb
umengo-0.2.0 lib/umengo/service.rb
umengo-0.1.0 lib/umengo/service.rb