handy_apn 0.1.1 → 0.1.2
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 +4 -4
- data/Rakefile +6 -1
- data/bin/handy_apn +101 -0
- data/handy_apn.gemspec +17 -15
- data/lib/handy_apn.rb +7 -0
- data/lib/handy_apn/apn_configuration.rb +7 -0
- data/lib/handy_apn/apn_connection.rb +0 -1
- data/lib/handy_apn/apn_send_helper.rb +30 -26
- data/lib/handy_apn/rakefile.rb +14 -23
- data/lib/handy_apn/version.rb +1 -1
- metadata +65 -23
- data/bin/console +0 -14
- data/bin/setup +0 -7
- data/lib/handy_apn/colored_logger.rb +0 -44
- data/lib/handy_apn/logger.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e01a9c1ab9a2c9d7d5d1c3b48c6ae08a9adcdde
|
4
|
+
data.tar.gz: e77a6a449c25ce239f71744fbffe2a1f9ab690f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4067f2d2d0d3ad5c6d9cb56e53621d16c046407d86a365bae823453f0d644ea2cfc3c14820284a2bad34980683dbb4973f0a84ab4772ebe0842329ae568f9cae
|
7
|
+
data.tar.gz: f1a0c08576572c0578dff02c6b86cdf01eaeb553e460264fc532b54e66919884dc4c4ff3940b96a92aca6294dd2a176b55fb9b77b8f4efd4e07ad733e2e483ee
|
data/Rakefile
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
2
|
require "rspec/core/rake_task"
|
3
|
-
require "
|
3
|
+
require "bundler"
|
4
|
+
Bundler.setup
|
5
|
+
|
6
|
+
gemspec = eval(File.read("handy_apn.gemspec"))
|
7
|
+
|
8
|
+
require "handy_apn/rakefile"
|
4
9
|
|
5
10
|
RSpec::Core::RakeTask.new(:spec)
|
6
11
|
|
data/bin/handy_apn
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "commander/import"
|
5
|
+
require "handy_apn"
|
6
|
+
|
7
|
+
HighLine.track_eof = false # Fix for built-in Ruby
|
8
|
+
Signal.trap("INT") {} # Suppress backtrace when exiting command
|
9
|
+
|
10
|
+
program :version, HandyApn::VERSION
|
11
|
+
program :description, 'A command-line interface for sending push notifications'
|
12
|
+
|
13
|
+
program :help, 'Author', 'Sushma Satish <sushmasatish@gmail.com>'
|
14
|
+
program :help, 'Website', 'https://github.com/sushmasatish'
|
15
|
+
program :help_formatter, :compact
|
16
|
+
|
17
|
+
default_command :help
|
18
|
+
|
19
|
+
command :push do |c|
|
20
|
+
c.syntax = 'handy_apn push TOKEN [...]'
|
21
|
+
c.summary = 'Sends an Apple Push Notification to specified devices'
|
22
|
+
c.description = ''
|
23
|
+
|
24
|
+
c.example 'description', 'handy_apn push <token> -m "Hello, World"'
|
25
|
+
c.option '-m', '--alert ALERT', 'Body of the alert to send in the push notification'
|
26
|
+
c.option '-e', '--environment ENV', [:production, :development], 'Environment to send push notification (production or development (default))'
|
27
|
+
c.option '-c', '--certificate CERTIFICATE', 'Path to certificate (.pem) file'
|
28
|
+
c.option '-p', '--[no]-passphrase', 'Prompt for a certificate passphrase'
|
29
|
+
|
30
|
+
c.action do |args, options|
|
31
|
+
say_error "One or more device tokens required" and abort if args.empty?
|
32
|
+
|
33
|
+
@environment = options.environment.downcase.to_sym rescue :development
|
34
|
+
say_error "Invalid environment,'#{@environment}' (should be either :development or :production)" and abort unless [:development, :production].include?(@environment)
|
35
|
+
|
36
|
+
@should_send_message_to_apn_prod = (@environment == :production)
|
37
|
+
|
38
|
+
@certificate = options.certificate
|
39
|
+
say_error "Missing certificate file option (-c /path/to/certificate.pem)" and abort unless @certificate
|
40
|
+
say_error "Could not find certificate file '#{@certificate}'" and abort unless File.exists?(@certificate)
|
41
|
+
|
42
|
+
@passphrase = options.passphrase ? password : ""
|
43
|
+
|
44
|
+
@alert = options.alert
|
45
|
+
|
46
|
+
unless @alert or @badge or @content_available or @data
|
47
|
+
placeholder = "Enter your alert message"
|
48
|
+
@alert = ask_editor placeholder
|
49
|
+
say_error "Payload contents required" and abort if @alert.nil? or @alert == placeholder
|
50
|
+
end
|
51
|
+
|
52
|
+
args.each do |token|
|
53
|
+
ApnSendHelper.new(@certificate,
|
54
|
+
@passphrase,
|
55
|
+
token,
|
56
|
+
@should_send_message_to_apn_prod,
|
57
|
+
@alert).send_push_notification()
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# command :feedback do |c|
|
63
|
+
# c.syntax = 'apn feedback [...]'
|
64
|
+
# c.summary = 'Queries the APN Feedback Service for failed device tokens.'
|
65
|
+
# c.description = ''
|
66
|
+
|
67
|
+
# c.example 'description', 'apn feedback -c /path/to/apple_push_certificate.pem'
|
68
|
+
# c.option '-c', '--certificate CERTIFICATE', 'Path to certificate (.pem) file'
|
69
|
+
# c.option '-e', '--environment ENV', [:production, :development], 'Environment to send push notification (production or development (default))'
|
70
|
+
# c.option '-p', '--[no]-passphrase', 'Prompt for a certificate passphrase'
|
71
|
+
|
72
|
+
# c.action do |args, options|
|
73
|
+
|
74
|
+
# @environment = options.environment.downcase.to_sym rescue :development
|
75
|
+
# say_error "Invalid environment,'#{@environment}' (should be either :development or :production)" and abort unless [:development, :production].include?(@environment)
|
76
|
+
|
77
|
+
# @certificate = options.certificate
|
78
|
+
# say_error "Missing certificate file option (-c /path/to/certificate.pem)" and abort unless @certificate
|
79
|
+
# say_error "Could not find certificate file '#{@certificate}'" and abort unless File.exists?(@certificate)
|
80
|
+
|
81
|
+
# @passphrase = options.passphrase ? password : ""
|
82
|
+
|
83
|
+
# client = (@environment == :production) ? Houston::Client.production : Houston::Client.development
|
84
|
+
# client.certificate = File.read(@certificate)
|
85
|
+
# client.passphrase = @passphrase
|
86
|
+
|
87
|
+
# begin
|
88
|
+
# feedbackDevices = client.unregistered_devices
|
89
|
+
|
90
|
+
# if feedbackDevices.any? && feedbackDevices.length > 0
|
91
|
+
# puts feedbackDevices.to_json
|
92
|
+
# else
|
93
|
+
# say_ok "No feedback available"
|
94
|
+
# end
|
95
|
+
|
96
|
+
# rescue => message
|
97
|
+
# say_error "Exception querying feedback: #{message}" and abort
|
98
|
+
# end
|
99
|
+
|
100
|
+
# end
|
101
|
+
# end
|
data/handy_apn.gemspec
CHANGED
@@ -1,29 +1,31 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
4
3
|
require 'handy_apn/version'
|
5
4
|
|
6
5
|
Gem::Specification.new do |spec|
|
7
6
|
spec.name = "handy_apn"
|
8
|
-
spec.version = HandyApn::VERSION
|
9
7
|
spec.authors = ["Sushma Satish"]
|
10
8
|
spec.email = ["sushmasatish@gmail.com"]
|
11
|
-
|
9
|
+
spec.license = "MIT"
|
10
|
+
spec.homepage = "https://github.com/sushmasatish/handy_apn"
|
11
|
+
spec.version = HandyApn::VERSION
|
12
|
+
spec.platform = Gem::Platform::RUBY
|
12
13
|
spec.summary = %q{Provides a handy tool to check your certificate and send apple push notification instantly.}
|
13
14
|
spec.description = %q{Once the Apple push notification certificates are created, use the rake task to send push notification to the device instantly.}
|
14
|
-
|
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
|
-
|
15
|
+
|
23
16
|
spec.add_dependency "configatron"
|
17
|
+
spec.add_dependency "coloured_logger"
|
18
|
+
spec.add_dependency "commander", "~> 4.1"
|
19
|
+
spec.add_dependency "json"
|
20
|
+
spec.add_dependency "houston"
|
24
21
|
|
25
22
|
spec.add_development_dependency "bundler", "~> 1.9"
|
26
23
|
spec.add_development_dependency "rake", "~> 10.0"
|
27
24
|
spec.add_development_dependency "rspec"
|
28
|
-
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
27
|
+
spec.bindir = "bin"
|
28
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
29
31
|
end
|
data/lib/handy_apn.rb
CHANGED
@@ -1,4 +1,11 @@
|
|
1
|
+
require "coloured_logger"
|
2
|
+
require "configatron"
|
3
|
+
require "json"
|
1
4
|
require "handy_apn/version"
|
5
|
+
require "handy_apn/string_helper"
|
6
|
+
require "handy_apn/apn_configuration"
|
7
|
+
require "handy_apn/apn_connection"
|
8
|
+
require "handy_apn/apn_send_helper"
|
2
9
|
|
3
10
|
module HandyApn
|
4
11
|
# Your code goes here...
|
@@ -0,0 +1,7 @@
|
|
1
|
+
configatron.apn.port = 2195
|
2
|
+
configatron.apn.dev.host = 'gateway.sandbox.push.apple.com'
|
3
|
+
configatron.apn.prod.host = 'gateway.push.apple.com'
|
4
|
+
|
5
|
+
configatron.apn.feedback.port = 2196
|
6
|
+
configatron.apn.dev.feedback.host = 'feedback.sandbox.push.apple.com'
|
7
|
+
configatron.apn.prod.feedback.host = 'gateway.push.apple.com'
|
@@ -1,55 +1,56 @@
|
|
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
1
|
class ApnSendHelper
|
7
2
|
|
8
3
|
attr_reader :device_token
|
9
|
-
attr_reader :
|
10
|
-
attr_reader :
|
4
|
+
attr_reader :should_send_message_to_apn_prod
|
5
|
+
attr_reader :apn_pem_file_path
|
11
6
|
attr_reader :apn_pass_phrase
|
7
|
+
attr_reader :message
|
12
8
|
|
13
|
-
def initialize(
|
14
|
-
@
|
9
|
+
def initialize(apn_pem_file_path, apn_pass_phrase, device_token, should_send_message_to_apn_prod, message)
|
10
|
+
@apn_pem_file_path = apn_pem_file_path
|
15
11
|
@apn_pass_phrase = apn_pass_phrase
|
16
12
|
@device_token = device_token
|
17
|
-
@
|
13
|
+
@should_send_message_to_apn_prod = should_send_message_to_apn_prod
|
14
|
+
@message = "Testing: #{Time.now}"
|
15
|
+
if (message &&
|
16
|
+
message.strip.length > 0)
|
17
|
+
@message = message.strip
|
18
|
+
end
|
18
19
|
end
|
19
20
|
|
20
21
|
def send_push_notification
|
21
22
|
result = false
|
22
23
|
|
23
|
-
if !StringHelper.is_valid(
|
24
|
-
|
24
|
+
if !StringHelper.is_valid(apn_pem_file_path)
|
25
|
+
ColouredLogger::CLogger.debug(__method__,
|
25
26
|
"Cannot send push notification as no certificate file is provided.")
|
26
27
|
return result
|
27
28
|
end
|
28
29
|
|
29
30
|
if !StringHelper.is_valid(apn_pass_phrase)
|
30
|
-
|
31
|
+
ColouredLogger::CLogger.debug(__method__,
|
31
32
|
"Cannot send push notification as pass-pharse is not provided for the certificate.")
|
32
33
|
return result
|
33
34
|
end
|
34
35
|
|
35
36
|
if !StringHelper.is_valid(device_token)
|
36
|
-
|
37
|
+
ColouredLogger::CLogger.debug(__method__,
|
37
38
|
"Cannot send push notification as device_token is not provided.")
|
38
39
|
return result
|
39
40
|
end
|
40
41
|
|
41
|
-
|
42
|
-
"Sending push notification to device_token #{@device_token} - #{@
|
42
|
+
ColouredLogger::CLogger.debug(__method__,
|
43
|
+
"Sending push notification to device_token #{@device_token} - #{@should_send_message_to_apn_prod}")
|
43
44
|
|
44
45
|
reset_apn_configurations
|
45
46
|
|
46
47
|
begin
|
47
48
|
ApnConnection.open_for_delivery() do |conn, sock|
|
48
|
-
conn.write(ApnSendHelper.data_to_send(@device_token))
|
49
|
+
conn.write(ApnSendHelper.data_to_send(@device_token, @message))
|
49
50
|
end
|
50
51
|
result = true
|
51
52
|
rescue Exception => err
|
52
|
-
|
53
|
+
ColouredLogger::CLogger.debug(__method__,
|
53
54
|
"Incurred while sending notifications [#{err.message}]")
|
54
55
|
end
|
55
56
|
|
@@ -57,18 +58,18 @@ class ApnSendHelper
|
|
57
58
|
end
|
58
59
|
|
59
60
|
def reset_apn_configurations
|
60
|
-
configatron.apn.cert = @
|
61
|
+
configatron.apn.cert = @apn_pem_file_path
|
61
62
|
configatron.apn.passphrase = @apn_pass_phrase
|
62
63
|
|
63
|
-
if @
|
64
|
+
if @should_send_message_to_apn_prod
|
64
65
|
configatron.apn.host = configatron.apn.prod.host
|
65
66
|
else
|
66
67
|
configatron.apn.host = configatron.apn.dev.host
|
67
68
|
end
|
68
69
|
end
|
69
70
|
|
70
|
-
def self.data_to_send(device_token)
|
71
|
-
json = self.to_apple_json
|
71
|
+
def self.data_to_send(device_token, msg)
|
72
|
+
json = self.to_apple_json(msg)
|
72
73
|
message = "\0\0 #{self.to_hexa(device_token)}\0#{json.length.chr}#{json}"
|
73
74
|
raise ApnErrorsHelper::ExceededMessageSizeError.new(message) if message.size.to_i > 256
|
74
75
|
message
|
@@ -78,16 +79,19 @@ class ApnSendHelper
|
|
78
79
|
[device_token.delete(' ')].pack('H*')
|
79
80
|
end
|
80
81
|
|
81
|
-
def self.apple_hash
|
82
|
+
def self.apple_hash(msg)
|
82
83
|
result = {}
|
83
84
|
result['aps'] = {}
|
84
|
-
result['aps']['alert'] =
|
85
|
+
result['aps']['alert'] = msg
|
85
86
|
result['aps']['badge'] = 1
|
86
87
|
result['aps']['sound'] = "1.aiff"
|
88
|
+
|
89
|
+
ColouredLogger::CLogger.info(__method__, "Message: #{result}")
|
90
|
+
|
87
91
|
result
|
88
92
|
end
|
89
93
|
|
90
|
-
def self.to_apple_json
|
91
|
-
self.apple_hash.to_json
|
94
|
+
def self.to_apple_json(msg)
|
95
|
+
self.apple_hash(msg).to_json
|
92
96
|
end
|
93
97
|
end
|
data/lib/handy_apn/rakefile.rb
CHANGED
@@ -1,38 +1,29 @@
|
|
1
|
-
require "
|
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'
|
1
|
+
require "handy_apn"
|
13
2
|
|
14
3
|
namespace :apn do
|
15
4
|
|
16
|
-
desc "
|
17
|
-
task :
|
18
|
-
|
5
|
+
desc "send_message - Params: apn_pem_file_path, apn_pass_phrase, device_token, should_send_message_to_apn_prod, message_text"
|
6
|
+
task :send_message, [:apn_pem_file_path, :apn_pass_phrase, :device_token, :should_send_message_to_apn_prod, :message_text] do |task, args|
|
7
|
+
ColouredLogger::CLogger.info(task, "STARTED - Running send_message Task.")
|
19
8
|
|
20
9
|
device_token = args[:device_token]
|
21
|
-
|
22
|
-
|
10
|
+
should_send_message_to_apn_prod = false # False means dev.
|
11
|
+
apn_pem_file_path = args[:apn_pem_file_path]
|
23
12
|
apn_pass_phrase = args[:apn_pass_phrase]
|
13
|
+
message_text = args[:message_text]
|
24
14
|
|
25
|
-
unless args[:
|
26
|
-
if args[:
|
27
|
-
|
15
|
+
unless args[:should_send_message_to_apn_prod].nil?
|
16
|
+
if args[:should_send_message_to_apn_prod].downcase == "true"
|
17
|
+
should_send_message_to_apn_prod = true
|
28
18
|
end
|
29
19
|
end
|
30
20
|
|
31
|
-
ApnSendHelper.new(
|
21
|
+
ApnSendHelper.new(apn_pem_file_path,
|
32
22
|
apn_pass_phrase,
|
33
23
|
device_token,
|
34
|
-
|
24
|
+
should_send_message_to_apn_prod,
|
25
|
+
message_text).send_push_notification()
|
35
26
|
|
36
|
-
|
27
|
+
ColouredLogger::CLogger.info(task, "FINISHED - Running send_message Task.")
|
37
28
|
end
|
38
29
|
end
|
data/lib/handy_apn/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: handy_apn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sushma Satish
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: configatron
|
@@ -25,41 +25,41 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: coloured_logger
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
34
|
-
type: :
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: commander
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
48
|
-
type: :
|
47
|
+
version: '4.1'
|
48
|
+
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '4.1'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: json
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
|
-
type: :
|
62
|
+
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
@@ -67,7 +67,49 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: houston
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: bundler
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.9'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.9'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '10.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '10.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rspec
|
71
113
|
requirement: !ruby/object:Gem::Requirement
|
72
114
|
requirements:
|
73
115
|
- - ">="
|
@@ -84,7 +126,8 @@ description: Once the Apple push notification certificates are created, use the
|
|
84
126
|
task to send push notification to the device instantly.
|
85
127
|
email:
|
86
128
|
- sushmasatish@gmail.com
|
87
|
-
executables:
|
129
|
+
executables:
|
130
|
+
- handy_apn
|
88
131
|
extensions: []
|
89
132
|
extra_rdoc_files: []
|
90
133
|
files:
|
@@ -95,20 +138,19 @@ files:
|
|
95
138
|
- Gemfile
|
96
139
|
- README.md
|
97
140
|
- Rakefile
|
98
|
-
- bin/
|
99
|
-
- bin/setup
|
141
|
+
- bin/handy_apn
|
100
142
|
- handy_apn.gemspec
|
101
143
|
- lib/handy_apn.rb
|
144
|
+
- lib/handy_apn/apn_configuration.rb
|
102
145
|
- lib/handy_apn/apn_connection.rb
|
103
146
|
- lib/handy_apn/apn_errors_helper.rb
|
104
147
|
- lib/handy_apn/apn_send_helper.rb
|
105
|
-
- lib/handy_apn/colored_logger.rb
|
106
|
-
- lib/handy_apn/logger.rb
|
107
148
|
- lib/handy_apn/rakefile.rb
|
108
149
|
- lib/handy_apn/string_helper.rb
|
109
150
|
- lib/handy_apn/version.rb
|
110
151
|
homepage: https://github.com/sushmasatish/handy_apn
|
111
|
-
licenses:
|
152
|
+
licenses:
|
153
|
+
- MIT
|
112
154
|
metadata: {}
|
113
155
|
post_install_message:
|
114
156
|
rdoc_options: []
|
@@ -125,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
167
|
- !ruby/object:Gem::Version
|
126
168
|
version: '0'
|
127
169
|
requirements: []
|
128
|
-
rubyforge_project:
|
170
|
+
rubyforge_project:
|
129
171
|
rubygems_version: 2.2.2
|
130
172
|
signing_key:
|
131
173
|
specification_version: 4
|
data/bin/console
DELETED
@@ -1,14 +0,0 @@
|
|
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
DELETED
@@ -1,44 +0,0 @@
|
|
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
|
data/lib/handy_apn/logger.rb
DELETED
@@ -1,15 +0,0 @@
|
|
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
|