Class: Pushing::Platforms::ApnPayload
- Inherits:
-
Object
- Object
- Pushing::Platforms::ApnPayload
- Defined in:
- lib/pushing/platforms.rb
Constant Summary collapse
- EMPTY_HASH =
{}.freeze
Instance Attribute Summary collapse
-
#device_token ⇒ Object
readonly
Returns the value of attribute device_token.
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
Class Method Summary collapse
Instance Method Summary collapse
- #headers ⇒ Object
-
#initialize(payload, options, config = EMPTY_HASH) ⇒ ApnPayload
constructor
A new instance of ApnPayload.
- #recipients ⇒ Object
Constructor Details
#initialize(payload, options, config = EMPTY_HASH) ⇒ ApnPayload
Returns a new instance of ApnPayload.
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 |
# File 'lib/pushing/platforms.rb', line 28 def initialize(payload, , config = EMPTY_HASH) @payload = payload @environment = config[:environment] @headers = config[:default_headers] || {} if config[:topic] ActiveSupport::Deprecation.warn "`config.apn.topic' is deprecated and will be removed in 0.3.0. " \ "Please use `config.apn.default_headers' instead:\n\n" \ " config.apn.default_headers = {\n" \ " apns_topic: '#{config[:topic]}'\n" \ " }", caller @headers['apns-topic'] ||= config[:topic] end if .is_a?(String) @device_token = elsif .is_a?(Hash) @device_token = [:device_token] @environment = [:environment] || @environment @headers = @headers.merge([:headers] || EMPTY_HASH) else raise TypeError, "The :apn key only takes a device token as a string or a hash that has `device_token: \"...\"'." end # raise("APNs environment is required.") if @environment.nil? # raise("APNs device token is required.") if @device_token.nil? @environment = @environment.to_sym end |
Instance Attribute Details
#device_token ⇒ Object (readonly)
Returns the value of attribute device_token.
20 21 22 |
# File 'lib/pushing/platforms.rb', line 20 def device_token @device_token end |
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
20 21 22 |
# File 'lib/pushing/platforms.rb', line 20 def environment @environment end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
20 21 22 |
# File 'lib/pushing/platforms.rb', line 20 def payload @payload end |
Class Method Details
.should_render?(options) ⇒ Boolean
24 25 26 |
# File 'lib/pushing/platforms.rb', line 24 def self.should_render?() .is_a?(Hash) ? [:device_token].present? : .present? end |
Instance Method Details
#headers ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/pushing/platforms.rb', line 63 def headers @normalized_headers ||= begin h = @headers.stringify_keys.transform_keys!(&:dasherize) { authorization: h['authorization'], 'apns-id': h['apns-id'] || h['id'], 'apns-expiration': h['apns-expiration'] || h['expiration'], 'apns-priority': h['apns-priority'] || h['priority'], 'apns-topic': h['apns-topic'] || h['topic'], 'apns-collapse-id': h['apns-collapse-id'] || h['collapse-id'], } end end |
#recipients ⇒ Object
59 60 61 |
# File 'lib/pushing/platforms.rb', line 59 def recipients Array("#{@environment}/#{@device_token}") end |