spns 0.2.2 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/README.md +16 -1
  2. data/VERSION +1 -1
  3. data/cron +13 -37
  4. data/lib/spns.rb +6 -4
  5. metadata +18 -2
data/README.md CHANGED
@@ -2,8 +2,15 @@ spns
2
2
  =======
3
3
  Simple Push Notification Server written with Sinatra and Sequel(Sqlite3)
4
4
 
5
+ Feature:
6
+ 1: rubygem, simple to install.
7
+ 2: provide pem file is the only requirement.
8
+ 3: no need to setup database, using sqlite3.
9
+ 4: provide default config file(spns.yml) with default value.
10
+
5
11
  Prerequisites
6
12
  =======
13
+
7
14
  Ruby
8
15
  -------
9
16
  spns is a ruby gem, require ruby installed on your mac machine. Since now all Mac OSX system preinstalled ruby enviroment, that's not a big issue.
@@ -13,6 +20,14 @@ Rubygem(latest)
13
20
  spns require latest rubygem installed, so you need to update your rubygem to latest version, run command below to update your rubygem to the latest one.
14
21
 
15
22
  $ sudo gem update --system # double dash option
23
+
24
+ Sqlite3
25
+ -------
26
+
27
+ * CentOS/Redhat: yum install sqlite3
28
+ * Debian/Ubuntu: apt-get install sqlite3
29
+ * FreeBSD: $ cd /usr/ports/databases/sqlite34 $ sudo make install clean
30
+ * Mac: Homebrew: brew install sqlite3 Port: port install sqlite3
16
31
 
17
32
  Installation
18
33
  =======
@@ -29,7 +44,7 @@ Usage
29
44
 
30
45
  4. start spns server, default port is 4567(sinatra's default port)
31
46
 
32
- $ spns
47
+ ![spns usage](https://raw.github.com/eiffelqiu/spns/master/doc/capture1.png)
33
48
 
34
49
  == Contributing to spns
35
50
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.2.4
data/cron CHANGED
@@ -1,53 +1,29 @@
1
- # -*- coding: utf-8 -*-
2
1
  #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ require 'yaml'
5
+ require 'cgi'
3
6
 
4
7
  ###########################################################################
8
+ ####
5
9
  #### This script is only for demo purpose, you can write this script
6
10
  #### with any language you like(python, perl, shell etc)
7
11
  ####
8
- #### This script fetch earthquake info whose magnitude large than 4 degree
9
- #### within an hour from usgs website and call spns service to send apple
10
- #### push notification
11
12
  ###########################################################################
12
13
 
13
- require 'rubygems'
14
- require 'sequel'
15
- require 'socket'
16
- require 'openssl'
17
- require 'cgi'
18
- require 'rufus/scheduler'
19
- require 'feedzirra'
20
- require 'yaml'
21
-
22
14
  ############################################################
23
15
  ## Configuration Setup
24
16
  ############################################################
25
17
  env = ENV['SINATRA_ENV'] || "development"
26
18
  config = YAML.load_file("#{Dir.pwd}/spns.yml")
27
- $timer = config['timer'] || 1
28
- $cron = config['cron'] || 'cron'
29
19
  $port = config['port'] || 4567
30
- $mode = config['mode'] || env
31
- $certificate = config["#{env}"][0]['certificate'] || 'ck.pem'
20
+
21
+ ############################################################
22
+ ## Using curl command to send push notification message
23
+ ############################################################
32
24
 
33
- # fetching a single feed
34
- feed = Feedzirra::Feed.fetch_and_parse("http://earthquake.usgs.gov/earthquakes/feed/atom/1.0/hour")
25
+ @message = CGI::escape("sample push notification message")
26
+ @pid = "#{Time.now.to_i}"
35
27
 
36
- messages = ''
37
- big = 0
38
- pid = ''
39
- feed.entries.each do |o|
40
- t = o.title.split(',')
41
- pids = o.id.split(':')
42
- pid = pids[3]
43
- m = t[0].split(' ')
44
- if m[1].to_i >= 4 then
45
- big = m[1].to_i if big < m[1].to_i
46
- messages = CGI::escape("Earthquake:#{o.title}")
47
- puts "Earthquake:#{o.title}"
48
- end
49
- end
50
- puts "curl http://localhost:#{$port}/v1/app/push/#{messages}/#{pid}"
51
- if big >= 1 then
52
- system "curl http://localhost:#{$port}/v1/app/push/#{messages}/#{pid}"
53
- end
28
+ puts "curl http://localhost:#{$port}/v1/app/push/#{@message}/#{@pid}"
29
+ system "curl http://localhost:#{$port}/v1/app/push/#{@message}/#{@pid}"
data/lib/spns.rb CHANGED
@@ -1,5 +1,5 @@
1
- # -*- coding: utf-8 -*-
2
1
  #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
3
 
4
4
  require 'rubygems'
5
5
  require 'sinatra'
@@ -21,7 +21,9 @@ $timer = config['timer'] || 1
21
21
  $cron = config['cron'] || 'cron'
22
22
  $port = config['port'] || 4567
23
23
  $mode = config['mode'] || env
24
- $certificate = config["#{env}"][0]['certificate'] || 'ck.pem'
24
+ $certificate = config["#{$mode}"][0]['certificate'] || 'ck.pem'
25
+ ROOTDIR = File.expand_path(File.join(File.dirname(__FILE__),'..'))
26
+ VERSION = File.open("#{ROOTDIR}/VERSION", "rb").read
25
27
 
26
28
  ############################################################
27
29
  ## Certificate Key Setup
@@ -36,7 +38,7 @@ unless File.exist?("#{Dir.pwd}/#{$certificate}") then
36
38
  exit
37
39
  else
38
40
  puts "*"*80
39
- puts "Simple Push Notification Server is Running..."
41
+ puts "Simple Push Notification Server is Running (#{VERSION}) ..."
40
42
  puts "Mode: #{$mode}"
41
43
  puts "Port: #{$port}"
42
44
  puts "Certificate File: '#{Dir.pwd}/#{$certificate}'"
@@ -78,7 +80,7 @@ scheduler = Rufus::Scheduler.start_new
78
80
 
79
81
  scheduler.every "#{$timer}m" do
80
82
  puts "running job: '#{Dir.pwd}/#{$cron}' every #{$timer} #{($timer == 1) ? 'minute' : 'minutes'}"
81
- system "#{Dir.pwd}/#{$cron}"
83
+ system "./#{$cron}"
82
84
  end
83
85
 
84
86
  ############################################################
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spns
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,6 +11,22 @@ bindir: bin
11
11
  cert_chain: []
12
12
  date: 2012-09-11 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sqlite3
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
14
30
  - !ruby/object:Gem::Dependency
15
31
  name: sinatra
16
32
  requirement: !ruby/object:Gem::Requirement
@@ -299,7 +315,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
299
315
  version: '0'
300
316
  segments:
301
317
  - 0
302
- hash: 888853487025371327
318
+ hash: 1770229218471308952
303
319
  required_rubygems_version: !ruby/object:Gem::Requirement
304
320
  none: false
305
321
  requirements: