ass 0.0.17 → 0.0.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.md +127 -36
  2. data/VERSION +1 -1
  3. data/lib/ass.rb +6 -4
  4. metadata +4 -4
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ass
2
2
  =======
3
- ####Apple Service Server was written with Ruby/Sinatra and Sequel(Sqlite3), it provides push notification and in app purchase service.####
3
+ ####Apple Service Server was written with Ruby/Sinatra and Sequel(Sqlite3), it provides push notification with web admin interface ####
4
4
 
5
5
  Feature:
6
6
  =======
@@ -32,48 +32,90 @@ Mac:
32
32
  $ port install sqlite # Macport
33
33
 
34
34
  Installation
35
- =======
36
35
 
37
- $ sudo gem install ass
36
+ * Method 1: with OS X builtin Ruby(AKA 'system ruby'), need to run with 'sudo', no extra step
37
+
38
+ ```bash
39
+ $ sudo gem install ass
40
+ ```
41
+
42
+ * Method 2: Install Ruby 1.9 (via RVM or natively) first, no need to run with 'sudo'
43
+
44
+ ```bash
45
+ $ gem install rvm
46
+ $ rvm install 1.9.3
47
+ $ rvm use 1.9.3
48
+ ```
49
+
50
+ * Install ass:
51
+
52
+ ```bash
53
+ $ gem install ass
54
+ ```
38
55
 
39
56
  Usage
40
57
  =======
41
58
 
42
- Prepare pem file:
43
-
44
59
  under the current directory, provide single pem file combined with certificate and key(name pattern: appid_mode.pem), HOWTO ([Check this link](http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12))
45
60
 
46
- cert.pem:
47
- openssl x509 -in aps_development.cer -inform der -out cert.pem
61
+ How to make development pem file
62
+ -------
63
+
64
+ dev_cert.pem:
65
+
66
+ $ openssl x509 -in aps_development.cer -inform der -out dev_cert.pem
67
+
68
+ dev_key.pem:
48
69
 
49
- key.pem:
50
- $ openssl pkcs12 -nocerts -in key.p12 -out key.pem
51
- $ Enter Import Password:
52
- $ MAC verified OK
53
- $ Enter PEM pass phrase:
54
- $ Verifying - Enter PEM pass phrase:
70
+ $ openssl pkcs12 -nocerts -in Certificates.p12 -out dev_key.pem
71
+ $ Enter Import Password:
72
+ $ MAC verified OK
73
+ $ Enter PEM pass phrase:
74
+ $ Verifying - Enter PEM pass phrase:
55
75
 
56
- Development Profile:
57
- cat cert.pem key.pem > appid_development.pem
76
+ Development Pem:
77
+
78
+ $ cat dev_cert.pem dev_key.pem > appid_development.pem
79
+
80
+ How to make produce production pem file
81
+ -------
58
82
 
59
- Distribution Profile:
60
- cat cert.pem key.pem > appid_production.pem
83
+ prod_cert.pem:
61
84
 
85
+ $ openssl x509 -in aps_production.cer -inform der -out prod_cert.pem
62
86
 
63
- * start ass server, default port is 4567 (sinatra's default port)
87
+ prod_key.pem:
88
+
89
+ $ openssl pkcs12 -nocerts -in Certificates.p12 -out prod_key.pem
90
+ $ Enter Import Password:
91
+ $ MAC verified OK
92
+ $ Enter PEM pass phrase:
93
+ $ Verifying - Enter PEM pass phrase:
94
+
95
+ Production Pem:
96
+
97
+ $ cat prod_cert.pem prod_key.pem > appid_production.pem
98
+
99
+ Start Ass server(default port is 4567)
100
+ -------
101
+
102
+ $ ass
64
103
 
65
104
  ![ass usage](https://raw.github.com/eiffelqiu/ass/master/doc/capture1.png)
66
105
  ![ass usage](https://raw.github.com/eiffelqiu/ass/master/doc/capture2.png)
67
-
106
+ ![ass usage](https://raw.github.com/eiffelqiu/ass/master/doc/capture3.png)
107
+ ![ass usage](https://raw.github.com/eiffelqiu/ass/master/doc/capture4.png)
68
108
  Configuration (ass.yml)
69
109
  =======
70
110
 
71
111
  when you run 'ass' first time, it will generate 'ass.yml' config file under current directory. ([Check this link](https://raw.github.com/eiffelqiu/ass/master/ass.yml))
72
112
 
73
113
  port: 4567 ## ASS server port, default is sinatra's port number: 4567
74
- mode: development ## 'development' or 'production' mode, you should provide pem file ({appid}_{mode}.pem) accordingly(such as, app1_development.pem, app1_production.pem).
114
+ mode: development ## 'development' or 'production' mode, you should provide pem file ({appid}_{mode}.pem) accordingly(such as, app1_development.pem, app1_production.pem).
75
115
  cron: cron ## cron job file name, ASS server will generate a demo 'cron' file for demostration only under current directory.
76
116
  timer: 0 # how often you run the cron job, unit: minute. when set with 0, means no cron job execute.
117
+ user: admin # admin username
118
+ pass: pass # admin password
77
119
  apps:
78
120
  - app1 ## appid you want to supprt APNS, ASS Server can give push notification support for many iOS apps, just list the appid here.
79
121
 
@@ -86,29 +128,73 @@ FAQ:
86
128
 
87
129
  In AppDelegate file, add methods below to register device token
88
130
 
89
- - (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
90
- {
91
- NSString * tokenAsString = [[[deviceToken description]
92
- stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]]
93
- stringByReplacingOccurrencesOfString:@" " withString:@""];
94
- NSString *urlAsString = [NSString stringWithFormat:@"http://serverIP:4567/v1/apps/app1/%@", token];
95
- NSURL *url = [NSURL URLWithString:urlAsString];
96
- NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url];
97
- [urlRequest setTimeoutInterval:30.0f];
98
- [urlRequest setHTTPMethod:@"GET"];
99
- NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease];
100
- [NSURLConnection sendAsynchronousRequest:urlRequest queue:queue completionHandler:nil];
131
+ #pragma mark - push notification methods
132
+
133
+ - (void)sendToken:(NSString *)token {
134
+
135
+ NSString *tokenUrl = [NSString stringWithFormat:@"http://serverIP:4567/v1/apps/app1/%@", token];
136
+ NSLog(@"tokenUrl: %@", tokenUrl);
137
+ //prepare NSURL with newly created string
138
+ NSURL *url = [NSURL URLWithString:tokenUrl];
139
+
140
+ //AsynchronousRequest to grab the data
141
+ NSURLRequest *request = [NSURLRequest requestWithURL:url];
142
+ NSOperationQueue *queue = [[NSOperationQueue alloc] init];
143
+
144
+ [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
145
+ if ([data length] > 0 && error == nil) {
146
+ // NSLog(@"send data successfully");
147
+ } else if ([data length] == 0 && error == nil) {
148
+ // NSLog(@"No data");
149
+ } else if (error != nil && error.code == NSURLErrorTimedOut) { //used this NSURLErrorTimedOut from
150
+ // NSLog(@"Token Time out");
151
+ } else if (error != nil) {
152
+ // NSLog(@"Error is: [%@]", [error description]);
153
+ }
154
+ }];
101
155
  }
102
156
 
103
- - (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
157
+ - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
158
+
159
+ if ([((AppDelegate *) [[UIApplication sharedApplication] delegate]) checkNetwork1]) {
160
+ NSString *tokenAsString = [[[deviceToken description]
161
+ stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]]
162
+ stringByReplacingOccurrencesOfString:@" " withString:@""];
163
+ NSLog(@"My token is: [%@]", tokenAsString);
164
+ [self sendToken:tokenAsString];
165
+ }
166
+
167
+ }
168
+
169
+ - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
170
+
171
+ NSLog(@"Failed to get token, error: %@", error);
172
+ }
173
+
174
+ - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
104
175
  {
105
- NSLog(@"Failed to get token, error: %@", error);
176
+ NSString *message = nil;
177
+ NSString *sound = nil;
178
+ NSString *extra = nil;
179
+
180
+ id aps = [userInfo objectForKey:@"aps"];
181
+ extra = [userInfo objectForKey:@"extra"];
182
+ if ([aps isKindOfClass:[NSString class]]) {
183
+ message = aps;
184
+ } else if ([aps isKindOfClass:[NSDictionary class]]) {
185
+ message = [aps objectForKey:@"alert"];
186
+ sound = [aps objectForKey:@"sound"];
187
+ // badge
188
+ }
189
+ if (aps) {
190
+ DLog(@"extra %@",[NSString stringWithFormat:@"sound %@ extra %@", sound, extra ]);
191
+ }
106
192
  }
107
193
 
108
194
  2. How to send push notification? (Server Side)
109
195
  -------
110
196
 
111
- run **curl** command to send push notification message, whatever shell.
197
+ run **curl** command to send push notification message on server' shell.
112
198
 
113
199
  $ curl http://localhost:4567/v1/apps/app1/push/{message}/{pid}
114
200
 
@@ -118,7 +204,12 @@ param1 (message): push notification message you want to send, remember the messa
118
204
 
119
205
  param2 (pid ): unique string to mark the message, for example current timestamp or md5/sha1 digest
120
206
 
207
+ 3. How to send test push notification on web?
208
+ -------
209
+
210
+ open your web browser and access http://localhost:4567/ (localhost should be changed to your server IP address accordingly), click "admin" on top navbar, you will see the Test Sending textbox on the top page, select your app , input your message and click 'send' button to send push notification.
121
211
 
212
+ ![ass usage](https://raw.github.com/eiffelqiu/ass/master/doc/capture5.png)
122
213
 
123
214
  Contributing to ass
124
215
  =======
@@ -134,5 +225,5 @@ Contributing to ass
134
225
  Copyright
135
226
  =======
136
227
 
137
- #####Copyright (c) 2012 Eiffel Qiu. See LICENSE.txt for further details.#####
228
+ #####Copyright (c) 2013 Eiffel Qiu. See LICENSE.txt for further details.#####
138
229
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.17
1
+ 0.0.18
data/lib/ass.rb CHANGED
@@ -213,7 +213,8 @@ class App < Sinatra::Base
213
213
  end
214
214
 
215
215
  error do
216
- @error = params['captures'].first.inspect
216
+ @error = "";
217
+ @error = params['captures'].first.inspect if "#{$mode}".strip == 'development'
217
218
  end
218
219
 
219
220
  post '/v1/send' do
@@ -228,7 +229,7 @@ class App < Sinatra::Base
228
229
  # puts "#{err.class} ##{err}"
229
230
  # end
230
231
  system "curl http://localhost:#{$port}/v1/apps/#{app}/push/#{message}/#{pid}"
231
- redirect '/' if (params[:app] and params[:message])
232
+ redirect '/v1/admin/push' if (params[:app] and params[:message])
232
233
  end
233
234
 
234
235
  get "/v1/admin/:db" do
@@ -242,13 +243,14 @@ class App < Sinatra::Base
242
243
  @o << Token.where(:app => app).order(:id).reverse.paginate(page, 20)
243
244
  }
244
245
  erb :token
245
- end
246
- if (db == 'push') then
246
+ elsif (db == 'push') then
247
247
  @p = []
248
248
  $apps.each_with_index { |app, index|
249
249
  @p << Push.where(:app => app).order(:id).reverse.paginate(page, 20)
250
250
  }
251
251
  erb :push
252
+ else
253
+ erb :not_found
252
254
  end
253
255
  end
254
256
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ass
3
3
  version: !ruby/object:Gem::Version
4
- hash: 61
4
+ hash: 59
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 17
10
- version: 0.0.17
9
+ - 18
10
+ version: 0.0.18
11
11
  platform: ruby
12
12
  authors:
13
13
  - Eiffel Qiu
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-03-27 00:00:00 Z
18
+ date: 2013-04-02 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  type: :runtime