j7w1 0.0.25 → 0.0.26

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: 01fea4879c09440293db4bbaf42f0d8bb22b2691
4
- data.tar.gz: 004a6963ec9a4a14fe2104c37a6ec668d518cb7e
3
+ metadata.gz: 52a2b3685c81bfad527b4cb9bc43714b026c9796
4
+ data.tar.gz: ffd32b5f4a8215d1798aa1f94940ef13b4746858
5
5
  SHA512:
6
- metadata.gz: e04db9946063b6979f00aeeebd74e21c95abcbce78fcc29c28a57bd16f70f5f8d7b827a5219878461f99bb0d1f534646b1556145e6d387f7bb50b25ebe02cd99
7
- data.tar.gz: 4f26a63ab7e50f672cf8b3fd00b600f2776bd2eb3f83205b3c5f864a43806da9da0bdc73cfc44873b871596f76bf0ffcb86dadad3d990b591db854a1875c8b9c
6
+ metadata.gz: 2ea3959139837c519c972caae8fdb2fdd6d00a5a59830da65cf5a20b99b7ac9d2007a1e2af27e26ec35bf30bb057468198608aa27b4ae5822bb71bb494afd7d6
7
+ data.tar.gz: 32c522339222f1e91c614ef482f52e8d8d77effb19d61c2b3ad725cdcf23648720fe2901ff5f8d89cccb46f9ea6986f9a120c9b66a391a07048b84e1aa7d4aa0
@@ -4,7 +4,10 @@ module J7W1
4
4
  AWS::SNS.new configuration.account
5
5
  end
6
6
 
7
- APNS_MAX_MESSAGE_SIZE = 40
7
+ APNS_MAX_PAYLOAD = 256
8
+
9
+ SHORTEN_REPLACEMENT = '...'.freeze
10
+ SHORTEN_REPLACEMENT_LENGTH = SHORTEN_REPLACEMENT.length
8
11
 
9
12
  INPUT_PAYLOAD_TABLE = {
10
13
  ios: {
@@ -87,6 +90,20 @@ module J7W1
87
90
  nil
88
91
  end
89
92
 
93
+ def create_topic(name, options)
94
+ sns_client = options[:sns_client]
95
+ sns_client ||= create_sns_client(sns_configuration || J7W1.configuration)
96
+
97
+ sns_client.topics.create name
98
+ end
99
+
100
+ def subscribe_topic(topic_name, endpoint_arn, options)
101
+ sns_client = options[:sns_client]
102
+ sns_client ||= create_sns_client(sns_configuration || J7W1.configuration)
103
+
104
+ sns_client.topics[name]
105
+ end
106
+
90
107
  def push(endpoint_arn, platform, options = {})
91
108
  return unless endpoint_arn && platform
92
109
 
@@ -133,16 +150,37 @@ module J7W1
133
150
  prefix = J7W1.configuration.ios_endpoint.sandbox? ?
134
151
  :APNS_SANDBOX : :APNS
135
152
 
136
- if message_value[:message] && message_value[:message].length > APNS_MAX_MESSAGE_SIZE
137
- message_value[:message] = message_value[:message][0...(APNS_MAX_MESSAGE_SIZE - 3)] + '...'
138
- end
139
-
140
153
  content = {
141
154
  aps: message_content(message_value, platform: :ios),
142
155
  }
143
156
  content.merge! data: data if data
144
157
 
145
- {prefix => content.to_json}
158
+ {prefix => ios_truncated_payload(content)}
159
+ end
160
+
161
+ def ios_truncated_payload(data)
162
+ payload = data.to_json
163
+
164
+ # Truncation is skipped when the payload is sufficiently lightweight.
165
+ return payload if (limit_break = payload.bytesize - APNX_MAX_PAYLOAD) >= 0
166
+
167
+ # Raise error if shortening of the alert cannot make the payload sufficiently short.
168
+ size_to_reduce = limit_break + SHORTEN_REPLACEMENT_LENGTH
169
+ raise "Payload is too heavy (#{payload.length})" unless
170
+ data[:alert] && data[:alert].bytesize > size_to_reduce
171
+
172
+ # Chopping the alert from its last -> first to avoid destroying the character's border
173
+ # and keep its content as long as possible.
174
+ chopped_length = 0
175
+ chopped_count = 0
176
+ while chopped_length < size_to_reduce
177
+ chopped_length += data[:alert][-1].bytesize
178
+ chopped_count += 1
179
+ end
180
+ data[:alert][-chopped_count..-1] = SHORTEN_REPLACEMENT
181
+ # Problem won't be occur because at least a character is truncated.
182
+
183
+ data.to_json
146
184
  end
147
185
 
148
186
  def android_payload_for(message_value, data)
data/lib/j7w1/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module J7W1
2
- VERSION = "0.0.25"
2
+ VERSION = "0.0.26"
3
3
  end
metadata CHANGED
@@ -1,97 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: j7w1
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.25
4
+ version: 0.0.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - condor
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-22 00:00:00.000000000 Z
11
+ date: 2015-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.17'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.17'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.3'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: activerecord
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '4.0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '4.0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: simplecov
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  description: Mobile apps push client
@@ -135,17 +135,17 @@ require_paths:
135
135
  - lib
136
136
  required_ruby_version: !ruby/object:Gem::Requirement
137
137
  requirements:
138
- - - '>='
138
+ - - ">="
139
139
  - !ruby/object:Gem::Version
140
140
  version: '0'
141
141
  required_rubygems_version: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - '>='
143
+ - - ">="
144
144
  - !ruby/object:Gem::Version
145
145
  version: '0'
146
146
  requirements: []
147
147
  rubyforge_project:
148
- rubygems_version: 2.0.14
148
+ rubygems_version: 2.4.5
149
149
  signing_key:
150
150
  specification_version: 4
151
151
  summary: Mobile apps push client