Sha256: b2d03ba09ec1bf1f95f9443949fb1da2ece565ca948f30b709b58052af58d141
Contents?: true
Size: 1.32 KB
Versions: 3
Compression:
Stored size: 1.32 KB
Contents
module Umengo class Params attr_accessor :data, :payload, :body, :extra, :policy def initialize(data, payload, body, extra, policy) @data = data @payload = payload @body = body || {} @extra = extra || {} @policy = policy || {} end def build_ios check_require(data, [:appkey, :timestamp, :type]) @data[:payload] = payload check_require(body, [:alert]) @data[:payload][:aps] = body build_default_ios! end def build_android check_require(data, [:appkey, :timestamp, :type]) display_type = payload.fetch(:display_type, "notifcation") @data[:payload] = payload case display_type when "notifcation" check_require(body, [:ticker, :title, :text, :after_open]) when "message" check_require(body, [:custom]) end @data[:payload][:body] = body build_default_android! end private def check_require(hash, keys) keys.each do |k| raise NotEnoughRequireParamsError, "key #{k}" unless hash.has_key?(k) end end def build_default_ios! @data[:policy] = policy if policy.any? @data end def build_default_android! @data[:payload][:extra] = extra if extra.any? @data[:policy] = policy if policy.any? @data end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
umengo-0.3.0 | lib/umengo/params.rb |
umengo-0.2.0 | lib/umengo/params.rb |
umengo-0.1.0 | lib/umengo/params.rb |