Sha256: 24b319681d50442cdf994f1527d72ffd3f6e921fcd1aba5222687ecd1b4a2a73

Contents?: true

Size: 1.16 KB

Versions: 2

Compression:

Stored size: 1.16 KB

Contents

# -*- encoding : utf-8 -*-
require 'cgi'
require 'leancloud/error'

module AV
  class Push
    attr_accessor :channels
    attr_accessor :channel
    attr_accessor :where
    attr_accessor :type
    attr_accessor :expiration_time_interval
    attr_accessor :expiration_time
    attr_accessor :push_time
    attr_accessor :data
    attr_accessor :production

    def initialize(data, channel = "")
      @data = data
      @channel = channel
    end

    def save
      uri   = Protocol.push_uri

      body = { :data => @data, :channel => @channel }

      if @channels
        body.merge!({ :channels => @channels })
        body.delete :channel
      end

      if @where
        body.merge!({ :where => @where })
        body.delete :channel
      end

      body.merge!({ :expiration_interval => @expiration_time_interval }) if @expiration_time_interval
      body.merge!({ :expiration_time => @expiration_time }) if @expiration_time
      body.merge!({ :push_time => @push_time }) if @push_time
      body.merge!({ :type => @type }) if @type
      body.merge!({ :prod => 'dev' }) if not @production

      response = AV.client.request uri, :post, body.to_json, nil
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
leancloud-ruby-client-0.1.1 lib/leancloud/push.rb
leancloud-ruby-client-0.1.0 lib/leancloud/push.rb