push_to_sns 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ad9057539c78782ad4272ae2f7512b049ef936d9
4
- data.tar.gz: ba38b3f2353d564a6742bb245722e66b02b272d4
3
+ metadata.gz: bdb88b92dcd3dc7f89ad71992c1f05bcb496765f
4
+ data.tar.gz: 2c64da57edee3c5d6a8b668b26fde82861a6c89e
5
5
  SHA512:
6
- metadata.gz: 2adc4366f07897ff8785e2df0f5add0a0f566d2590a2c296ca28e66970f9f4ae5fb251ed926e876aa39513a4304afc8912bdc2d3307fdc12d366cc569b66763e
7
- data.tar.gz: 64f605e044a03a23433e8da8b490090ef2b689c3101d212a00bf3224cb309d3e974d60a49ff93b9086fc46f38f57db346f4e8c55ae05d5c20770e6cbe7fe1b11
6
+ metadata.gz: e11f5cbead59e666895f74ce48f5dbb1b2964c74a304acad1694751876ad955bc6cf0230ffca7cff0dfb4af1438e6b7e4f47afad0ef763497e3b80a84819f197
7
+ data.tar.gz: d3da5122c6ac0d62601d7d22fc009671b423de37cbc0de4d2f29eda298f310f159f1e860a14718751c19db011c7e6583afa9aab83cb0fe5f9127ea442998255b
@@ -9,9 +9,13 @@ module PushToSNS
9
9
  private
10
10
 
11
11
  def default_payload
12
- {
12
+ basic_message = {
13
13
  message: payload[:message] || DEFAULT_MESSAGE
14
14
  }
15
+ basic_message[:smallIcon] = payload[:badge] if payload[:badge]
16
+ basic_message[:sound] = payload[:sound] if payload[:sound]
17
+
18
+ basic_message
15
19
  end
16
20
  end
17
21
  end
@@ -3,12 +3,18 @@ module PushToSNS
3
3
  DEFAULT_MESSAGE = "IOS Push Notification"
4
4
 
5
5
  def message
6
- {
6
+ basic_message = {
7
7
  apns => {
8
- aps: { alert: payload[:message] || DEFAULT_MESSAGE },
8
+ aps: {
9
+ alert: payload[:message] || DEFAULT_MESSAGE
10
+ },
9
11
  data: payload
10
- }.to_json
12
+ }
11
13
  }
14
+ basic_message[apns][:aps][:badge] = payload[:badge] if payload[:badge]
15
+ basic_message[apns][:aps][:sound] = payload[:sound] if payload[:sound]
16
+ basic_message[apns] = basic_message[apns].to_json
17
+ basic_message
12
18
  end
13
19
 
14
20
  private
@@ -23,7 +23,12 @@ module PushToSNS
23
23
  private
24
24
 
25
25
  def full_notification_for_device(device)
26
- defaults = { type: type, message: message }
26
+ defaults = {
27
+ type: call_or_read(type, device),
28
+ message: call_or_read(message, device),
29
+ badge: call_or_read(badge, device),
30
+ sound: call_or_read(sound, device)
31
+ }.reject { |key, value| value.nil? }
27
32
  defaults.merge(notification(device))
28
33
  end
29
34
 
@@ -35,22 +40,37 @@ module PushToSNS
35
40
  @message ||= self.class.message
36
41
  end
37
42
 
38
- class << self
39
- attr_accessor :input_type, :input_message
43
+ def badge
44
+ @badge ||= self.class.badge
45
+ end
40
46
 
41
- def type(input_type = nil)
42
- if input_type.nil?
43
- self.input_type
44
- else
45
- self.input_type = input_type
46
- end
47
+ def sound
48
+ @sound ||= self.class.sound
49
+ end
50
+
51
+ private
52
+
53
+ def call_or_read(proc_or_object, *arguments)
54
+ if proc_or_object.respond_to?(:call)
55
+ proc_or_object.call(*arguments)
56
+ else
57
+ proc_or_object
47
58
  end
59
+ end
60
+
61
+ class << self
62
+ [:type, :message, :badge, :sound].each do |method_name|
63
+ property_name = "input_#{method_name}".to_sym
64
+ attr_accessor property_name
48
65
 
49
- def message(input_message = nil)
50
- if input_message.nil?
51
- self.input_message
52
- else
53
- self.input_message = input_message
66
+ define_method(method_name) do |input = nil, &block|
67
+ if input.nil? && block.nil?
68
+ public_send(property_name)
69
+ elsif input.nil? && !block.nil?
70
+ public_send("#{property_name}=", block)
71
+ elsif !input.nil?
72
+ public_send("#{property_name}=", input)
73
+ end
54
74
  end
55
75
  end
56
76
  end
@@ -1,3 +1,3 @@
1
1
  module PushToSNS
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: push_to_sns
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - juliogarciag
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-10 00:00:00.000000000 Z
11
+ date: 2015-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler