j7w1 0.0.13 → 0.0.14

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: 4046fbb0005d6a0246a41c8e633de82dc68056ad
4
- data.tar.gz: 871c3075045b04ca677db37be620cf8dc0c96747
3
+ metadata.gz: 173f6f7c6ae362a1a8cf8068f1c12a2c949c7533
4
+ data.tar.gz: 252cccea60908318b7a567df86158223c89a2c1a
5
5
  SHA512:
6
- metadata.gz: eaaf337cc20c7eaa47f01de60525cd45e4910aeb4bdff87b82fde235a1c4083592672c82185b45683af34a071632a05e5c61720f94af8ae201c80c6a27d57063
7
- data.tar.gz: dc5272e30548103715894a83a4a7103e4a52fcee796616fc93ac18d741045fd49250f7d15fa45820760cb8222697292b6ed503c49e5749ff2302527af93edbd6
6
+ metadata.gz: ca59c342c914b49279d5a115d2880c890175324717068baec8695ee8d43c5fb996ab1935836fcfdf94ba8f472625364d2687b05d39403f8263d1f2a12bf73b48
7
+ data.tar.gz: a4d32b1d44c5a03994b10ca4e19be3b3b8412bd4092478dc9703ac3bc3376facd96b03f97d2aa49c6397c65d233142c1a26d312c75c259fe7947ad4b47d15621
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # J7W1
2
2
 
3
- A gem to send the push notification to mobile app via Amazon Simple Notification Service (SNS). Currently supports only iOS platform, but the support for Android is also scheduled.
3
+ A gem to send the push notification to mobile app via Amazon Simple Notification Service (SNS). Currently supports only iOS platform at production quality. The support for Android is experimentally implemented.
4
4
 
5
5
  ## Installation
6
6
 
@@ -39,6 +39,8 @@ Configuration is expected to have the structure as below:
39
39
  app_endpoint:
40
40
  ios:
41
41
  arn: "<The ARN of your app.>"
42
+ android:
43
+ arn: "<The ARN of your android app.>"
42
44
  account:
43
45
  access_key_id: "<Your Access Key>"
44
46
  secret_access_key: "<Your Secret Key>"
@@ -81,4 +83,4 @@ The generator j7w1:model must be useful for you. It provides the items below:
81
83
 
82
84
  ## Author
83
85
 
84
- TOYODA Naoto https://github.com/condor
86
+ TOYODA Naoto https://github.com/condor
@@ -2,13 +2,19 @@ module J7W1
2
2
  class Configuration
3
3
  include J7W1::Util
4
4
 
5
+ module MobileEndpoint
6
+ def arn
7
+ self[:arn]
8
+ end
9
+ end
10
+
5
11
  module IOSEndpoint
6
- def sandbox?
7
- @sandbox
12
+ def self.extended(obj)
13
+ obj.__send__ :extend, MobileEndpoint
8
14
  end
9
15
 
10
- def arn
11
- self[:arn]
16
+ def sandbox?
17
+ @sandbox
12
18
  end
13
19
 
14
20
  def confirm_sandbox
@@ -17,8 +23,8 @@ module J7W1
17
23
  end
18
24
 
19
25
  module AndroidEndpoint
20
- def arn
21
- self[:arn]
26
+ def self.extended(obj)
27
+ obj.__send__ :extend, MobileEndpoint
22
28
  end
23
29
  end
24
30
 
@@ -34,7 +40,9 @@ module J7W1
34
40
  ios_endpoint.extend(IOSEndpoint)
35
41
  ios_endpoint.confirm_sandbox
36
42
  end
37
- android_endpoint.extend(AndroidEndpoint) if android_endpoint
43
+ if android_endpoint
44
+ android_endpoint.extend(AndroidEndpoint)
45
+ end
38
46
  account.extend(Account)
39
47
  end
40
48
 
@@ -4,6 +4,18 @@ module J7W1
4
4
  AWS::SNS.new configuration.account
5
5
  end
6
6
 
7
+ APS_TABLE = {
8
+ message: :alert,
9
+ badge: :badge,
10
+ sound: :sound,
11
+ }.freeze
12
+
13
+ ANDROID_TABLE = {
14
+ message: :message,
15
+ badge: :badge,
16
+ sound: :sound,
17
+ }.freeze
18
+
7
19
  def create_ios_application(name, certs, private_key, options)
8
20
  sandbox = !(options[:sandbox] == false)
9
21
  configuration = options[:sns_configuration] || J7W1.configuration
@@ -39,8 +51,16 @@ module J7W1
39
51
  sns_client ||= create_sns_client(sns_configuration || J7W1.configuration)
40
52
 
41
53
  sns_config = J7W1.configuration
42
- app_arn = platform == :ios ? sns_config.ios_endpoint.arn :
43
- sns_config.android_endpoint.arn
54
+
55
+ app_arn =
56
+ case platform
57
+ when :ios
58
+ sns_config.ios_endpoint.arn
59
+ when :android
60
+ sns_config.android_endpoint.arn
61
+ else
62
+
63
+ end
44
64
 
45
65
  endpoint =
46
66
  sns_client.client.create_platform_endpoint(
@@ -70,7 +90,7 @@ module J7W1
70
90
  sns_client = options[:sns_client]
71
91
 
72
92
  message_value = {}
73
- message_value.merge!(alert: message) unless message.blank?
93
+ message_value.merge!(message: message) unless message.blank?
74
94
  message_value.merge!(badge: badge) unless badge.blank?
75
95
  message_value.merge!(sound: sound) unless sound.blank?
76
96
 
@@ -86,10 +106,10 @@ module J7W1
86
106
 
87
107
  private
88
108
  def payload_for(message_value, platform)
89
- case platform
90
- when 'ios'
109
+ case platform.to_sym
110
+ when :ios
91
111
  ios_payload_for(message_value)
92
- when 'android'
112
+ when :android
93
113
  android_payload_for(message_value)
94
114
  end
95
115
  end
@@ -97,11 +117,23 @@ module J7W1
97
117
  def ios_payload_for(message_value)
98
118
  prefix = J7W1.configuration.ios_endpoint.sandbox? ?
99
119
  :APNS_SANDBOX : :APNS
100
- {prefix => {aps: message_value}.to_json}
120
+
121
+ {prefix => {aps: message_content_with_table(message_value, APS_TABLE)}.to_json}
101
122
  end
102
123
 
103
124
  def android_payload_for(message_value)
104
- # TODO Android Push Implementation
125
+ {
126
+ gcm: {
127
+ data: message_content_with_table(message_value, ANDROID_TABLE)
128
+ }.to_json
129
+ }
130
+ end
131
+
132
+ def message_content_with_table(content, table)
133
+ table.keys.reduce({}) do |h, key|
134
+ h[table[key]] = content[key]
135
+ h
136
+ end
105
137
  end
106
138
 
107
139
  def content_from(argument)
data/lib/j7w1/util.rb CHANGED
@@ -6,8 +6,9 @@ module J7W1
6
6
  case platform
7
7
  when :ios, :'iphone os', :'ipad os'
8
8
  :ios
9
+ when :android
10
+ :android
9
11
  else
10
- # TODO Android
11
12
  platform
12
13
  end
13
14
  end
data/lib/j7w1/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module J7W1
2
- VERSION = "0.0.13"
2
+ VERSION = "0.0.14"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: j7w1
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - condor
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-16 00:00:00.000000000 Z
11
+ date: 2013-12-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk