handy_apn 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.rvmrc +60 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/README.md +55 -0
- data/Rakefile +7 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/handy_apn.gemspec +28 -0
- data/lib/handy_apn.rb +5 -0
- data/lib/handy_apn/apn_connection.rb +74 -0
- data/lib/handy_apn/apn_errors_helper.rb +16 -0
- data/lib/handy_apn/apn_send_helper.rb +93 -0
- data/lib/handy_apn/colored_logger.rb +44 -0
- data/lib/handy_apn/logger.rb +15 -0
- data/lib/handy_apn/rakefile.rb +38 -0
- data/lib/handy_apn/string_helper.rb +19 -0
- data/lib/handy_apn/version.rb +3 -0
- metadata +134 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7d412598e9d97c0cd8e719e0edfcd5e950e1cc7c
|
4
|
+
data.tar.gz: b314841804c837ff5041eb1f22c7bbd999205934
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b5c8eeafda384feab4882c75303ec34bdf53a547a5c0738c96240f7efa6fd21df4fdfc5e329fd1f93a7ef65b74c7b08773fd7ad22830997d6b59762af0339a41
|
7
|
+
data.tar.gz: 2a4bbc09c0f62d22588b810e1a61add2db5fc0c61733ac55a649056dcb2fe9271611e76c1a7024ceecf772c16a779793e5337b7a3f0a22115c4d2057ed8db5bd
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
+
# development environment upon cd'ing into the directory
|
5
|
+
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
|
7
|
+
# Only full ruby name is supported here, for short names use:
|
8
|
+
# echo "rvm use 2.1.2@handy_apn" > .rvmrc
|
9
|
+
environment_id="ruby-2.1.2@handy_apn"
|
10
|
+
|
11
|
+
# Uncomment the following lines if you want to verify rvm version per project
|
12
|
+
# rvmrc_rvm_version="1.26.11 (latest)" # 1.10.1 seems like a safe start
|
13
|
+
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | __rvm_awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
|
14
|
+
# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
|
15
|
+
# return 1
|
16
|
+
# }
|
17
|
+
|
18
|
+
# First we attempt to load the desired environment directly from the environment
|
19
|
+
# file. This is very fast and efficient compared to running through the entire
|
20
|
+
# CLI and selector. If you want feedback on which environment was used then
|
21
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
22
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
|
23
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
24
|
+
then
|
25
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
26
|
+
for __hook in "${rvm_path:-$HOME/.rvm}/hooks/after_use"*
|
27
|
+
do
|
28
|
+
if [[ -f "${__hook}" && -x "${__hook}" && -s "${__hook}" ]]
|
29
|
+
then \. "${__hook}" || true
|
30
|
+
fi
|
31
|
+
done
|
32
|
+
unset __hook
|
33
|
+
if (( ${rvm_use_flag:=1} >= 2 )) # display only when forced
|
34
|
+
then
|
35
|
+
if [[ $- == *i* ]] # check for interactive shells
|
36
|
+
then printf "%b" "Using: $(tput setaf 2 2>/dev/null)$GEM_HOME$(tput sgr0 2>/dev/null)\n" # show the user the ruby and gemset they are using in green
|
37
|
+
else printf "%b" "Using: $GEM_HOME\n" # don't use colors in non-interactive shells
|
38
|
+
fi
|
39
|
+
fi
|
40
|
+
else
|
41
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
42
|
+
rvm --create "$environment_id" || {
|
43
|
+
echo "Failed to create RVM environment '${environment_id}'."
|
44
|
+
return 1
|
45
|
+
}
|
46
|
+
fi
|
47
|
+
|
48
|
+
# If you use bundler, this might be useful to you:
|
49
|
+
# if [[ -s Gemfile ]] && {
|
50
|
+
# ! builtin command -v bundle >/dev/null ||
|
51
|
+
# builtin command -v bundle | GREP_OPTIONS="" \command \grep $rvm_path/bin/bundle >/dev/null
|
52
|
+
# }
|
53
|
+
# then
|
54
|
+
# printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
|
55
|
+
# gem install bundler
|
56
|
+
# fi
|
57
|
+
# if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
|
58
|
+
# then
|
59
|
+
# bundle install | GREP_OPTIONS="" \command \grep -vE '^Using|Your bundle is complete'
|
60
|
+
# fi
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# HandyApn
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/handy_apn`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'handy_apn'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install handy_apn
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
$ require 'handy_apn'
|
26
|
+
$ rake --tasks
|
27
|
+
$ rake apn:send_push_notification[full_file_path_to_dot_pem,pass_phrase_for_certificate,device_token,is_dev_or_prod]
|
28
|
+
|
29
|
+
Note:
|
30
|
+
|
31
|
+
* full_file_path_to_dot_cer - absolute location of the file along with file name and should be for .pem
|
32
|
+
|
33
|
+
* device_token - should be separated by space after 8 characters as shown in example below.
|
34
|
+
|
35
|
+
* is_dev_or_prod - false - connects to APN-Dev service - gateway.sandbox.push.apple.com
|
36
|
+
|
37
|
+
|
38
|
+
$ rake apn:send_push_notification["/Users/blah/apn_certificates/aps_development.pem","blah","eb8328c8 3f42a4dd e7eb8e96 5535b0c7 653032eb 070e54d9 c55133a6 da32c94f",false]
|
39
|
+
|
40
|
+
## How to create apple push notification certificate
|
41
|
+
|
42
|
+
I have referred to instructions from raywenderlich.
|
43
|
+
|
44
|
+
http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1
|
45
|
+
|
46
|
+
## Development
|
47
|
+
|
48
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
49
|
+
|
50
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
51
|
+
|
52
|
+
## Contributing
|
53
|
+
|
54
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/sushmasatish/handy_apn.
|
55
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "handy_apn"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/handy_apn.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'handy_apn/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "handy_apn"
|
8
|
+
spec.version = HandyApn::VERSION
|
9
|
+
spec.authors = ["Sushma Satish"]
|
10
|
+
spec.email = ["sushmasatish@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Provides a handy tool to check your certificate and send apple push notification instantly.}
|
13
|
+
spec.description = %q{Once the Apple push notification certificates are created, use the rake task to send push notification to the device instantly.}
|
14
|
+
spec.homepage = "https://github.com/sushmasatish/handy_apn"
|
15
|
+
|
16
|
+
spec.rubyforge_project = "handy_apn"
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
spec.add_development_dependency "json"
|
27
|
+
spec.add_development_dependency "configatron"
|
28
|
+
end
|
data/lib/handy_apn.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'socket'
|
2
|
+
require 'openssl'
|
3
|
+
require 'configatron'
|
4
|
+
|
5
|
+
module ApnConnection
|
6
|
+
|
7
|
+
class << self
|
8
|
+
|
9
|
+
# Yields up an SSL socket to write notifications to.
|
10
|
+
# The connections are close automatically.
|
11
|
+
#
|
12
|
+
# Example:
|
13
|
+
# APN::Configuration.open_for_delivery do |conn|
|
14
|
+
# conn.write('my cool notification')
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# Configuration parameters are:
|
18
|
+
#
|
19
|
+
# configatron.apn.passphrase = ''
|
20
|
+
# configatron.apn.port = 2195
|
21
|
+
# configatron.apn.host = 'gateway.sandbox.push.apple.com' # Development
|
22
|
+
# configatron.apn.host = 'gateway.push.apple.com' # Production
|
23
|
+
# configatron.apn.cert = File.join(rails_root, 'config', 'apple_push_notification_development.pem')) # Development
|
24
|
+
# configatron.apn.cert = File.join(rails_root, 'config', 'apple_push_notification_production.pem')) # Production
|
25
|
+
def open_for_delivery(options = {}, &block)
|
26
|
+
open(options, &block)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Yields up an SSL socket to receive feedback from.
|
30
|
+
# The connections are close automatically.
|
31
|
+
# Configuration parameters are:
|
32
|
+
#
|
33
|
+
# configatron.apn.feedback.passphrase = ''
|
34
|
+
# configatron.apn.feedback.port = 2196
|
35
|
+
# configatron.apn.feedback.host = 'feedback.sandbox.push.apple.com' # Development
|
36
|
+
# configatron.apn.feedback.host = 'feedback.push.apple.com' # Production
|
37
|
+
# configatron.apn.feedback.cert = File.join(rails_root, 'config', 'apple_push_notification_development.pem')) # Development
|
38
|
+
# configatron.apn.feedback.cert = File.join(rails_root, 'config', 'apple_push_notification_production.pem')) # Production
|
39
|
+
def open_for_feedback(options = {}, &block)
|
40
|
+
options = {:cert => configatron.apn.feedback.cert,
|
41
|
+
:passphrase => configatron.apn.feedback.passphrase,
|
42
|
+
:host => configatron.apn.feedback.host,
|
43
|
+
:port => configatron.apn.feedback.port}.merge(options)
|
44
|
+
open(options, &block)
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
def open(options = {}, &block) # :nodoc:
|
49
|
+
options = {:cert => configatron.apn.cert,
|
50
|
+
:passphrase => configatron.apn.passphrase,
|
51
|
+
:host => configatron.apn.host,
|
52
|
+
:port => configatron.apn.port}.merge(options)
|
53
|
+
|
54
|
+
cert = File.read(options[:cert])
|
55
|
+
# cert = options[:cert]
|
56
|
+
ctx = OpenSSL::SSL::SSLContext.new
|
57
|
+
ctx.key = OpenSSL::PKey::RSA.new(cert, options[:passphrase])
|
58
|
+
ctx.cert = OpenSSL::X509::Certificate.new(cert)
|
59
|
+
ctx.ca_file = options[:ca_file]
|
60
|
+
|
61
|
+
sock = TCPSocket.new(options[:host], options[:port])
|
62
|
+
ssl = OpenSSL::SSL::SSLSocket.new(sock, ctx)
|
63
|
+
ssl.sync = true
|
64
|
+
ssl.connect
|
65
|
+
|
66
|
+
yield ssl, sock if block_given?
|
67
|
+
|
68
|
+
ssl.close
|
69
|
+
sock.close
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
end # Connection
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module ApnErrorsHelper
|
2
|
+
# Raised when a notification message to Apple is longer than 256 bytes.
|
3
|
+
class ExceededMessageSizeError < StandardError
|
4
|
+
|
5
|
+
def initialize(message) # :nodoc:
|
6
|
+
super("The maximum size allowed for a notification payload is 256 bytes: '#{message}'")
|
7
|
+
end
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
class MissingCertificateError < StandardError
|
12
|
+
def initialize
|
13
|
+
super("This app has no certificate")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require "./lib/handy_apn/colored_logger.rb"
|
2
|
+
require "./lib/handy_apn/string_helper.rb"
|
3
|
+
require "./lib/handy_apn/apn_connection.rb"
|
4
|
+
require "./lib/handy_apn/apn_send_helper.rb"
|
5
|
+
|
6
|
+
class ApnSendHelper
|
7
|
+
|
8
|
+
attr_reader :device_token
|
9
|
+
attr_reader :is_dev_or_prod
|
10
|
+
attr_reader :apn_cer_file_full_path
|
11
|
+
attr_reader :apn_pass_phrase
|
12
|
+
|
13
|
+
def initialize(apn_cer_file_full_path, apn_pass_phrase, device_token, is_dev_or_prod)
|
14
|
+
@apn_cer_file_full_path = apn_cer_file_full_path
|
15
|
+
@apn_pass_phrase = apn_pass_phrase
|
16
|
+
@device_token = device_token
|
17
|
+
@is_dev_or_prod = is_dev_or_prod
|
18
|
+
end
|
19
|
+
|
20
|
+
def send_push_notification
|
21
|
+
result = false
|
22
|
+
|
23
|
+
if !StringHelper.is_valid(apn_cer_file_full_path)
|
24
|
+
ColoredLogger.debug(__method__,
|
25
|
+
"Cannot send push notification as no certificate file is provided.")
|
26
|
+
return result
|
27
|
+
end
|
28
|
+
|
29
|
+
if !StringHelper.is_valid(apn_pass_phrase)
|
30
|
+
ColoredLogger.debug(__method__,
|
31
|
+
"Cannot send push notification as pass-pharse is not provided for the certificate.")
|
32
|
+
return result
|
33
|
+
end
|
34
|
+
|
35
|
+
if !StringHelper.is_valid(device_token)
|
36
|
+
ColoredLogger.debug(__method__,
|
37
|
+
"Cannot send push notification as device_token is not provided.")
|
38
|
+
return result
|
39
|
+
end
|
40
|
+
|
41
|
+
ColoredLogger.debug(__method__,
|
42
|
+
"Sending push notification to device_token #{@device_token} - #{@is_dev_or_prod}")
|
43
|
+
|
44
|
+
reset_apn_configurations
|
45
|
+
|
46
|
+
begin
|
47
|
+
ApnConnection.open_for_delivery() do |conn, sock|
|
48
|
+
conn.write(ApnSendHelper.data_to_send(@device_token))
|
49
|
+
end
|
50
|
+
result = true
|
51
|
+
rescue Exception => err
|
52
|
+
ColoredLogger.debug(__method__,
|
53
|
+
"Incurred while sending notifications [#{err.message}]")
|
54
|
+
end
|
55
|
+
|
56
|
+
result
|
57
|
+
end
|
58
|
+
|
59
|
+
def reset_apn_configurations
|
60
|
+
configatron.apn.cert = @apn_cer_file_full_path
|
61
|
+
configatron.apn.passphrase = @apn_pass_phrase
|
62
|
+
|
63
|
+
if @is_dev_or_prod
|
64
|
+
configatron.apn.host = configatron.apn.prod.host
|
65
|
+
else
|
66
|
+
configatron.apn.host = configatron.apn.dev.host
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.data_to_send(device_token)
|
71
|
+
json = self.to_apple_json
|
72
|
+
message = "\0\0 #{self.to_hexa(device_token)}\0#{json.length.chr}#{json}"
|
73
|
+
raise ApnErrorsHelper::ExceededMessageSizeError.new(message) if message.size.to_i > 256
|
74
|
+
message
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.to_hexa(device_token)
|
78
|
+
[device_token.delete(' ')].pack('H*')
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.apple_hash
|
82
|
+
result = {}
|
83
|
+
result['aps'] = {}
|
84
|
+
result['aps']['alert'] = "Testing: #{Time.now}"
|
85
|
+
result['aps']['badge'] = 1
|
86
|
+
result['aps']['sound'] = "1.aiff"
|
87
|
+
result
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.to_apple_json
|
91
|
+
self.apple_hash.to_json
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
require "./lib/handy_apn/logger.rb"
|
3
|
+
|
4
|
+
class ColoredLogger
|
5
|
+
include Singleton
|
6
|
+
|
7
|
+
attr_reader :logger
|
8
|
+
|
9
|
+
SEVERITY_TO_COLOR_MAP = {'DEBUG'=>'36', 'INFO'=>'32', 'WARN'=>'33', 'ERROR'=>'31', 'FATAL'=>'31', 'UNKNOWN'=>'37', 'PERF'=>'35'}
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@logger = Logger.new(STDOUT)
|
13
|
+
# Logger.LEVEL = DEBUG - logs all levels, INFO - would not log debug level.
|
14
|
+
@logger.level = Logger::DEBUG
|
15
|
+
@logger.formatter = proc do |severity, time, progname, msg|
|
16
|
+
formatted_severity = sprintf("%-5s",severity.to_s)
|
17
|
+
formatted_time = sprintf("[%s]", time.strftime("%Y-%m-%d %H:%M:%S"))
|
18
|
+
date_color ='1;34'
|
19
|
+
severity_color = SEVERITY_TO_COLOR_MAP[severity]
|
20
|
+
"\033[#{date_color}m#{formatted_time} \033[#{severity_color}m #{formatted_severity} \033[0m-- #{msg.to_s.strip}\n"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# low-level information for developers
|
25
|
+
def self.debug(method, message)
|
26
|
+
formatted_method = sprintf("%-20s", method)
|
27
|
+
ColoredLogger.instance.logger.debug("#{formatted_method}: #{message}");
|
28
|
+
end
|
29
|
+
|
30
|
+
# generic (useful) information about system operation
|
31
|
+
def self.info(method, message)
|
32
|
+
formatted_method = sprintf("%-20s", method)
|
33
|
+
ColoredLogger.instance.logger.info("#{formatted_method}: #{message}");
|
34
|
+
end
|
35
|
+
|
36
|
+
# Logs time taken to execute a task
|
37
|
+
def self.log_time(method, start_time, task_name)
|
38
|
+
end_time = Time.now
|
39
|
+
formatted_method = sprintf("%-20s", method)
|
40
|
+
time_taken = end_time - start_time
|
41
|
+
formatted_time_taken = sprintf("[%.4f sec]", time_taken)
|
42
|
+
ColoredLogger.instance.logger.perf("#{formatted_method}: Time taken to #{task_name} - \033[35m#{formatted_time_taken}\033[0m");
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
class Logger
|
4
|
+
def self.custom_level(tag)
|
5
|
+
SEV_LABEL << tag
|
6
|
+
idx = SEV_LABEL.size - 1
|
7
|
+
|
8
|
+
define_method(tag.downcase.gsub(/\W+/, '_').to_sym) do |progname, &block|
|
9
|
+
add(idx, nil, progname, &block)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# Adding PERF custom level
|
14
|
+
custom_level 'PERF'
|
15
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require "configatron"
|
2
|
+
require "json"
|
3
|
+
require "./lib/handy_apn/colored_logger.rb"
|
4
|
+
require "./lib/handy_apn/apn_send_helper.rb"
|
5
|
+
|
6
|
+
configatron.apn.port = 2195
|
7
|
+
configatron.apn.dev.host = 'gateway.sandbox.push.apple.com'
|
8
|
+
configatron.apn.prod.host = 'gateway.push.apple.com'
|
9
|
+
|
10
|
+
configatron.apn.feedback.port = 2196
|
11
|
+
configatron.apn.dev.feedback.host = 'feedback.sandbox.push.apple.com'
|
12
|
+
configatron.apn.prod.feedback.host = 'gateway.push.apple.com'
|
13
|
+
|
14
|
+
namespace :apn do
|
15
|
+
|
16
|
+
desc "send_push_notification - Params: apn_cer_file_full_path, apn_pass_phrase, device_token, is_dev_or_prod"
|
17
|
+
task :send_push_notification, [:apn_cer_file_full_path, :apn_pass_phrase, :device_token, :is_dev_or_prod] do |task, args|
|
18
|
+
ColoredLogger.info(task, "STARTED - Running send_push_notification Task.")
|
19
|
+
|
20
|
+
device_token = args[:device_token]
|
21
|
+
is_dev_or_prod = false # False means dev.
|
22
|
+
apn_cer_file_full_path = args[:apn_cer_file_full_path]
|
23
|
+
apn_pass_phrase = args[:apn_pass_phrase]
|
24
|
+
|
25
|
+
unless args[:is_dev_or_prod].nil?
|
26
|
+
if args[:is_dev_or_prod].downcase == "true"
|
27
|
+
is_dev_or_prod = true
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
ApnSendHelper.new(apn_cer_file_full_path,
|
32
|
+
apn_pass_phrase,
|
33
|
+
device_token,
|
34
|
+
is_dev_or_prod).send_push_notification()
|
35
|
+
|
36
|
+
ColoredLogger.info(task, "FINISHED - Running send_push_notification Task.")
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class StringHelper
|
2
|
+
def self.is_valid(string_to_check)
|
3
|
+
result = true
|
4
|
+
|
5
|
+
if string_to_check.nil? ||
|
6
|
+
string_to_check.length == 0
|
7
|
+
|
8
|
+
result = false
|
9
|
+
|
10
|
+
elsif string_to_check.downcase == "nil"
|
11
|
+
string_to_check.downcase == "null"
|
12
|
+
|
13
|
+
result = false
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
result
|
18
|
+
end
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: handy_apn
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sushma Satish
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-06-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.9'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: json
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: configatron
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Once the Apple push notification certificates are created, use the rake
|
84
|
+
task to send push notification to the device instantly.
|
85
|
+
email:
|
86
|
+
- sushmasatish@gmail.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- ".rvmrc"
|
94
|
+
- ".travis.yml"
|
95
|
+
- Gemfile
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- bin/console
|
99
|
+
- bin/setup
|
100
|
+
- handy_apn.gemspec
|
101
|
+
- lib/handy_apn.rb
|
102
|
+
- lib/handy_apn/apn_connection.rb
|
103
|
+
- lib/handy_apn/apn_errors_helper.rb
|
104
|
+
- lib/handy_apn/apn_send_helper.rb
|
105
|
+
- lib/handy_apn/colored_logger.rb
|
106
|
+
- lib/handy_apn/logger.rb
|
107
|
+
- lib/handy_apn/rakefile.rb
|
108
|
+
- lib/handy_apn/string_helper.rb
|
109
|
+
- lib/handy_apn/version.rb
|
110
|
+
homepage: https://github.com/sushmasatish/handy_apn
|
111
|
+
licenses: []
|
112
|
+
metadata: {}
|
113
|
+
post_install_message:
|
114
|
+
rdoc_options: []
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
requirements: []
|
128
|
+
rubyforge_project: handy_apn
|
129
|
+
rubygems_version: 2.2.2
|
130
|
+
signing_key:
|
131
|
+
specification_version: 4
|
132
|
+
summary: Provides a handy tool to check your certificate and send apple push notification
|
133
|
+
instantly.
|
134
|
+
test_files: []
|