push-apns 1.0.4 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/lib/push-apns/version.rb +1 -1
  3. data/lib/push/apns/binary_notification_validator.rb +13 -1
  4. data/lib/push/configuration_apns.rb +1 -1
  5. data/lib/push/message_apns.rb +58 -18
  6. data/spec/dummy/Rakefile +6 -0
  7. data/spec/dummy/app/assets/images/.keep +0 -0
  8. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  9. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  10. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  11. data/spec/dummy/app/mailers/.keep +0 -0
  12. data/spec/dummy/app/models/.keep +0 -0
  13. data/spec/dummy/app/models/concerns/.keep +0 -0
  14. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  15. data/spec/dummy/bin/bundle +3 -0
  16. data/spec/dummy/bin/rails +4 -0
  17. data/spec/dummy/bin/rake +4 -0
  18. data/spec/dummy/bin/setup +29 -0
  19. data/spec/dummy/config.ru +4 -0
  20. data/spec/dummy/config/application.rb +25 -0
  21. data/spec/dummy/config/boot.rb +5 -0
  22. data/spec/dummy/config/database.yml +25 -0
  23. data/spec/dummy/config/environment.rb +5 -0
  24. data/spec/dummy/config/environments/development.rb +41 -0
  25. data/spec/dummy/config/environments/production.rb +79 -0
  26. data/spec/dummy/config/environments/test.rb +42 -0
  27. data/spec/dummy/config/initializers/assets.rb +11 -0
  28. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  29. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  30. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  31. data/spec/dummy/config/initializers/inflections.rb +16 -0
  32. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  33. data/spec/dummy/config/initializers/session_store.rb +3 -0
  34. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  35. data/spec/dummy/config/locales/en.yml +23 -0
  36. data/spec/dummy/config/routes.rb +56 -0
  37. data/spec/dummy/config/secrets.yml +22 -0
  38. data/spec/dummy/db/migrate/20160602100607_create_push.rb +49 -0
  39. data/spec/dummy/db/schema.rb +59 -0
  40. data/spec/dummy/lib/assets/.keep +0 -0
  41. data/spec/dummy/lib/push/feedback_processor.rb +28 -0
  42. data/spec/dummy/log/.keep +0 -0
  43. data/spec/push/message_apns_spec.rb +137 -0
  44. data/spec/spec_helper.rb +14 -0
  45. metadata +144 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6d8fd74a35925a321646bd48be98bb16ca81b47b
4
- data.tar.gz: 52ed265ad2fe8c0bfc30be4b76acc5c5df8de3df
3
+ metadata.gz: a8006ceeba9466f4247ff88d322e2dc2a95e4c6c
4
+ data.tar.gz: 5801f214584d08f6caa8247c6a698172c0b142db
5
5
  SHA512:
6
- metadata.gz: fc4bcde17bfa7ef69438ec37337912bfcc000352654283ba544af1309cd0d8bf94227a6831608c3aa25cd344e9bab30a8667862c5e8e70d58381d87172a8bc42
7
- data.tar.gz: 43627b54eeca02245988e98bfedf52bd6891b61b3a767e1802e05a86e3b476aae5dd9ea54b809d8dda20d514c1b52332cced2c6b5cbcd080c4109bbe174fb76b
6
+ metadata.gz: b66649efce34bc628a2282524c2ed42f5012b8ab245f3719a0a8eb248a70e5572fc1e40a0439fa5003481f447ed42b234833b3cca2b34c4c5388897d7d075c36
7
+ data.tar.gz: 1fbe1623468c625882c9165576459dc3d7474b1bdd6d449a1a71f07c2305418e3d4bdb52036434727eb03e9d3552b9ee353c0826b1a5a23f2cab3db17ecc53f6
@@ -1,3 +1,3 @@
1
1
  module PushApns
2
- VERSION = "1.0.4"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -6,7 +6,19 @@ module Push
6
6
  if record.payload_size > 256
7
7
  record.errors[:base] << "APN notification cannot be larger than 256 bytes. Try condensing your alert and device attributes."
8
8
  end
9
+
10
+ if [5, 10].include?(record.priority) == false
11
+ record.errors[:priority] << "APN priority must be 5 or 10."
12
+ end
13
+
14
+ if record.alert.nil? &&
15
+ record.badge.nil? &&
16
+ record.sound.nil? &&
17
+ record.content_available.present? &&
18
+ record.priority == 10
19
+ record.errors[:priority] << "APN priority cannot be 10 for a push that contains only the content_available key."
20
+ end
9
21
  end
10
22
  end
11
23
  end
12
- end
24
+ end
@@ -11,4 +11,4 @@ module Push
11
11
  :apns
12
12
  end
13
13
  end
14
- end
14
+ end
@@ -2,27 +2,31 @@ module Push
2
2
  class MessageApns < Push::Message
3
3
  SELECT_TIMEOUT = 0.2
4
4
  ERROR_TUPLE_BYTES = 6
5
+ APNS_PRIORITY_IMMEDIATE = 10
6
+ APNS_PRIORITY_CONSERVE_POWER = 5
5
7
  APN_ERRORS = {
6
- 1 => "Processing error",
7
- 2 => "Missing device token",
8
- 3 => "Missing topic",
9
- 4 => "Missing payload",
10
- 5 => "Missing token size",
11
- 6 => "Missing topic size",
12
- 7 => "Missing payload size",
13
- 8 => "Invalid token",
14
- 255 => "None (unknown error)"
15
- }
16
- store :properties, accessors: [:alert, :badge, :sound, :expiry, :attributes_for_device, :content_available]
17
- attr_accessible :app, :device, :alert, :badge, :sound, :expiry, :attributes_for_device, :content_available if defined?(ActiveModel::MassAssignmentSecurity)
8
+ 1 => "Processing error".freeze,
9
+ 2 => "Missing device token".freeze,
10
+ 3 => "Missing topic".freeze,
11
+ 4 => "Missing payload".freeze,
12
+ 5 => "Missing token size".freeze,
13
+ 6 => "Missing topic size".freeze,
14
+ 7 => "Missing payload size".freeze,
15
+ 8 => "Invalid token".freeze,
16
+ 10 => "Shutdown".freeze,
17
+ 255 => "None (unknown error)".freeze
18
+ }.freeze
19
+ store :properties, accessors: [:alert, :badge, :sound, :expiry, :attributes_for_device, :content_available, :priority]
20
+ attr_accessible :app, :device, :alert, :badge, :sound, :expiry, :attributes_for_device, :content_available, :priority if defined?(ActiveModel::MassAssignmentSecurity)
18
21
 
19
22
  validates :badge, :numericality => true, :allow_nil => true
20
23
  validates :expiry, :numericality => true, :presence => true
24
+ validates :priority, :numericality => true, :allow_nil => true
21
25
  validates :device, :format => { :with => /\A[a-z0-9]{64}\z/ }
22
26
  validates_with Push::Apns::BinaryNotificationValidator
23
27
 
24
28
  def attributes_for_device=(attrs)
25
- raise ArgumentError, "attributes_for_device must be a Hash" if !attrs.is_a?(Hash)
29
+ raise ArgumentError, "attributes_for_device must be a Hash" unless attrs.is_a?(Hash)
26
30
  properties[:attributes_for_device] = MultiJson.dump(attrs)
27
31
  end
28
32
 
@@ -43,11 +47,14 @@ module Push
43
47
  MultiJson.load(string_or_json) rescue string_or_json
44
48
  end
45
49
 
46
- # This method conforms to the enhanced binary format.
47
- # http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingWIthAPS/CommunicatingWIthAPS.html#//apple_ref/doc/uid/TP40008194-CH101-SW4
48
50
  def to_message(options = {})
49
- id_for_pack = options[:for_validation] ? 0 : id
50
- [1, id_for_pack, expiry, 0, 32, device, payload_size, payload].pack("cNNccH*na*")
51
+ frame = ""
52
+ frame << device_token_item
53
+ frame << payload_item
54
+ frame << identifier_item(options)
55
+ frame << expiration_item
56
+ frame << priority_item
57
+ [2, frame.bytesize].pack("cN") + frame
51
58
  end
52
59
 
53
60
  def use_connection
@@ -62,8 +69,41 @@ module Push
62
69
  payload.bytesize
63
70
  end
64
71
 
72
+ def priority
73
+ if properties[:alert].nil? &&
74
+ properties[:badge].nil? &&
75
+ properties[:sound].nil? &&
76
+ properties[:content_available].present?
77
+ APNS_PRIORITY_CONSERVE_POWER
78
+ else
79
+ properties[:priority].present? ? properties[:priority] : APNS_PRIORITY_IMMEDIATE
80
+ end
81
+ end
82
+
65
83
  private
66
84
 
85
+ def device_token_item
86
+ [1, 32, device].pack("cnH*")
87
+ end
88
+
89
+ def payload_item
90
+ json = payload
91
+ [2, json.bytesize, json].pack("cna*")
92
+ end
93
+
94
+ def identifier_item(options)
95
+ frame_id = options[:for_validation] ? 0 : id
96
+ [3, 4, frame_id].pack("cnN")
97
+ end
98
+
99
+ def expiration_item
100
+ [4, 4, expiry.to_i].pack("cnN")
101
+ end
102
+
103
+ def priority_item
104
+ [5, 1, priority].pack("cnc")
105
+ end
106
+
67
107
  def as_json
68
108
  json = ActiveSupport::OrderedHash.new
69
109
  json['aps'] = ActiveSupport::OrderedHash.new
@@ -100,4 +140,4 @@ module Push
100
140
  end
101
141
  end
102
142
  end
103
- end
143
+ end
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Rails.application.load_tasks
File without changes
@@ -0,0 +1,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
File without changes
File without changes
File without changes
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
6
+ <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pathname'
3
+
4
+ # path to your application root.
5
+ APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
6
+
7
+ Dir.chdir APP_ROOT do
8
+ # This script is a starting point to setup your application.
9
+ # Add necessary setup steps to this file:
10
+
11
+ puts "== Installing dependencies =="
12
+ system "gem install bundler --conservative"
13
+ system "bundle check || bundle install"
14
+
15
+ # puts "\n== Copying sample files =="
16
+ # unless File.exist?("config/database.yml")
17
+ # system "cp config/database.yml.sample config/database.yml"
18
+ # end
19
+
20
+ puts "\n== Preparing database =="
21
+ system "bin/rake db:setup"
22
+
23
+ puts "\n== Removing old logs and tempfiles =="
24
+ system "rm -f log/*"
25
+ system "rm -rf tmp/cache"
26
+
27
+ puts "\n== Restarting application server =="
28
+ system "touch tmp/restart.txt"
29
+ end
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Rails.application
@@ -0,0 +1,25 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'rails/all'
4
+
5
+ Bundler.require(*Rails.groups)
6
+ require "push-apns"
7
+
8
+ module Dummy
9
+ class Application < Rails::Application
10
+ # Settings in config/environments/* take precedence over those specified here.
11
+ # Application configuration should go into files in config/initializers
12
+ # -- all .rb files in that directory are automatically loaded.
13
+
14
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
15
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
16
+ # config.time_zone = 'Central Time (US & Canada)'
17
+
18
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
19
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
20
+ # config.i18n.default_locale = :de
21
+
22
+ # Do not swallow errors in after_commit/after_rollback callbacks.
23
+ config.active_record.raise_in_transactional_callbacks = true
24
+ end
25
+ end
@@ -0,0 +1,5 @@
1
+ # Set up gems listed in the Gemfile.
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
3
+
4
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
5
+ $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
@@ -0,0 +1,25 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3
3
+ #
4
+ # Ensure the SQLite 3 gem is defined in your Gemfile
5
+ # gem 'sqlite3'
6
+ #
7
+ default: &default
8
+ adapter: sqlite3
9
+ pool: 5
10
+ timeout: 5000
11
+
12
+ development:
13
+ <<: *default
14
+ database: db/development.sqlite3
15
+
16
+ # Warning: The database defined as "test" will be erased and
17
+ # re-generated from your development database when you run "rake".
18
+ # Do not set this db to the same as development or production.
19
+ test:
20
+ <<: *default
21
+ database: db/test.sqlite3
22
+
23
+ production:
24
+ <<: *default
25
+ database: db/production.sqlite3
@@ -0,0 +1,5 @@
1
+ # Load the Rails application.
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the Rails application.
5
+ Rails.application.initialize!
@@ -0,0 +1,41 @@
1
+ Rails.application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb.
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the web server when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Do not eager load code on boot.
10
+ config.eager_load = false
11
+
12
+ # Show full error reports and disable caching.
13
+ config.consider_all_requests_local = true
14
+ config.action_controller.perform_caching = false
15
+
16
+ # Don't care if the mailer can't send.
17
+ config.action_mailer.raise_delivery_errors = false
18
+
19
+ # Print deprecation notices to the Rails logger.
20
+ config.active_support.deprecation = :log
21
+
22
+ # Raise an error on page load if there are pending migrations.
23
+ config.active_record.migration_error = :page_load
24
+
25
+ # Debug mode disables concatenation and preprocessing of assets.
26
+ # This option may cause significant delays in view rendering with a large
27
+ # number of complex assets.
28
+ config.assets.debug = true
29
+
30
+ # Asset digests allow you to set far-future HTTP expiration dates on all assets,
31
+ # yet still be able to expire them through the digest params.
32
+ config.assets.digest = true
33
+
34
+ # Adds additional error checking when serving assets at runtime.
35
+ # Checks for improperly declared sprockets dependencies.
36
+ # Raises helpful error messages.
37
+ config.assets.raise_runtime_errors = true
38
+
39
+ # Raises error for missing translations
40
+ # config.action_view.raise_on_missing_translations = true
41
+ end
@@ -0,0 +1,79 @@
1
+ Rails.application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb.
3
+
4
+ # Code is not reloaded between requests.
5
+ config.cache_classes = true
6
+
7
+ # Eager load code on boot. This eager loads most of Rails and
8
+ # your application in memory, allowing both threaded web servers
9
+ # and those relying on copy on write to perform better.
10
+ # Rake tasks automatically ignore this option for performance.
11
+ config.eager_load = true
12
+
13
+ # Full error reports are disabled and caching is turned on.
14
+ config.consider_all_requests_local = false
15
+ config.action_controller.perform_caching = true
16
+
17
+ # Enable Rack::Cache to put a simple HTTP cache in front of your application
18
+ # Add `rack-cache` to your Gemfile before enabling this.
19
+ # For large-scale production use, consider using a caching reverse proxy like
20
+ # NGINX, varnish or squid.
21
+ # config.action_dispatch.rack_cache = true
22
+
23
+ # Disable serving static files from the `/public` folder by default since
24
+ # Apache or NGINX already handles this.
25
+ config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
26
+
27
+ # Compress JavaScripts and CSS.
28
+ config.assets.js_compressor = :uglifier
29
+ # config.assets.css_compressor = :sass
30
+
31
+ # Do not fallback to assets pipeline if a precompiled asset is missed.
32
+ config.assets.compile = false
33
+
34
+ # Asset digests allow you to set far-future HTTP expiration dates on all assets,
35
+ # yet still be able to expire them through the digest params.
36
+ config.assets.digest = true
37
+
38
+ # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
39
+
40
+ # Specifies the header that your server uses for sending files.
41
+ # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
42
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
43
+
44
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
45
+ # config.force_ssl = true
46
+
47
+ # Use the lowest log level to ensure availability of diagnostic information
48
+ # when problems arise.
49
+ config.log_level = :debug
50
+
51
+ # Prepend all log lines with the following tags.
52
+ # config.log_tags = [ :subdomain, :uuid ]
53
+
54
+ # Use a different logger for distributed setups.
55
+ # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
56
+
57
+ # Use a different cache store in production.
58
+ # config.cache_store = :mem_cache_store
59
+
60
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server.
61
+ # config.action_controller.asset_host = 'http://assets.example.com'
62
+
63
+ # Ignore bad email addresses and do not raise email delivery errors.
64
+ # Set this to true and configure the email server for immediate delivery to raise delivery errors.
65
+ # config.action_mailer.raise_delivery_errors = false
66
+
67
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
68
+ # the I18n.default_locale when a translation cannot be found).
69
+ config.i18n.fallbacks = true
70
+
71
+ # Send deprecation notices to registered listeners.
72
+ config.active_support.deprecation = :notify
73
+
74
+ # Use default logging formatter so that PID and timestamp are not suppressed.
75
+ config.log_formatter = ::Logger::Formatter.new
76
+
77
+ # Do not dump schema after migrations.
78
+ config.active_record.dump_schema_after_migration = false
79
+ end
@@ -0,0 +1,42 @@
1
+ Rails.application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb.
3
+
4
+ # The test environment is used exclusively to run your application's
5
+ # test suite. You never need to work with it otherwise. Remember that
6
+ # your test database is "scratch space" for the test suite and is wiped
7
+ # and recreated between test runs. Don't rely on the data there!
8
+ config.cache_classes = true
9
+
10
+ # Do not eager load code on boot. This avoids loading your whole application
11
+ # just for the purpose of running a single test. If you are using a tool that
12
+ # preloads Rails for running tests, you may have to set it to true.
13
+ config.eager_load = false
14
+
15
+ # Configure static file server for tests with Cache-Control for performance.
16
+ config.serve_static_files = true
17
+ config.static_cache_control = 'public, max-age=3600'
18
+
19
+ # Show full error reports and disable caching.
20
+ config.consider_all_requests_local = true
21
+ config.action_controller.perform_caching = false
22
+
23
+ # Raise exceptions instead of rendering exception templates.
24
+ config.action_dispatch.show_exceptions = false
25
+
26
+ # Disable request forgery protection in test environment.
27
+ config.action_controller.allow_forgery_protection = false
28
+
29
+ # Tell Action Mailer not to deliver emails to the real world.
30
+ # The :test delivery method accumulates sent emails in the
31
+ # ActionMailer::Base.deliveries array.
32
+ config.action_mailer.delivery_method = :test
33
+
34
+ # Randomize the order test cases are executed.
35
+ config.active_support.test_order = :random
36
+
37
+ # Print deprecation notices to the stderr.
38
+ config.active_support.deprecation = :stderr
39
+
40
+ # Raises error for missing translations
41
+ # config.action_view.raise_on_missing_translations = true
42
+ end
@@ -0,0 +1,11 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Version of your assets, change this if you want to expire all your assets.
4
+ Rails.application.config.assets.version = '1.0'
5
+
6
+ # Add additional assets to the asset load path
7
+ # Rails.application.config.assets.paths << Emoji.images_path
8
+
9
+ # Precompile additional assets.
10
+ # application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
11
+ # Rails.application.config.assets.precompile += %w( search.js )
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
+ # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
+
6
+ # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7
+ # Rails.backtrace_cleaner.remove_silencers!
@@ -0,0 +1,3 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ Rails.application.config.action_dispatch.cookies_serializer = :json
@@ -0,0 +1,4 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Configure sensitive parameters which will be filtered from the log file.
4
+ Rails.application.config.filter_parameters += [:password]
@@ -0,0 +1,16 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new inflection rules using the following format. Inflections
4
+ # are locale specific, and you may define rules for as many different
5
+ # locales as you wish. All of these examples are active by default:
6
+ # ActiveSupport::Inflector.inflections(:en) do |inflect|
7
+ # inflect.plural /^(ox)$/i, '\1en'
8
+ # inflect.singular /^(ox)en/i, '\1'
9
+ # inflect.irregular 'person', 'people'
10
+ # inflect.uncountable %w( fish sheep )
11
+ # end
12
+
13
+ # These inflection rules are supported but not enabled by default:
14
+ # ActiveSupport::Inflector.inflections(:en) do |inflect|
15
+ # inflect.acronym 'RESTful'
16
+ # end
@@ -0,0 +1,4 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new mime types for use in respond_to blocks:
4
+ # Mime::Type.register "text/richtext", :rtf
@@ -0,0 +1,3 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ Rails.application.config.session_store :cookie_store, key: '_dummy_session'
@@ -0,0 +1,14 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # This file contains settings for ActionController::ParamsWrapper which
4
+ # is enabled by default.
5
+
6
+ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
+ ActiveSupport.on_load(:action_controller) do
8
+ wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
9
+ end
10
+
11
+ # To enable root element in JSON for ActiveRecord objects.
12
+ # ActiveSupport.on_load(:active_record) do
13
+ # self.include_root_in_json = true
14
+ # end
@@ -0,0 +1,23 @@
1
+ # Files in the config/locales directory are used for internationalization
2
+ # and are automatically loaded by Rails. If you want to use locales other
3
+ # than English, add the necessary files in this directory.
4
+ #
5
+ # To use the locales, use `I18n.t`:
6
+ #
7
+ # I18n.t 'hello'
8
+ #
9
+ # In views, this is aliased to just `t`:
10
+ #
11
+ # <%= t('hello') %>
12
+ #
13
+ # To use a different locale, set it with `I18n.locale`:
14
+ #
15
+ # I18n.locale = :es
16
+ #
17
+ # This would use the information in config/locales/es.yml.
18
+ #
19
+ # To learn more, please read the Rails Internationalization guide
20
+ # available at http://guides.rubyonrails.org/i18n.html.
21
+
22
+ en:
23
+ hello: "Hello world"
@@ -0,0 +1,56 @@
1
+ Rails.application.routes.draw do
2
+ # The priority is based upon order of creation: first created -> highest priority.
3
+ # See how all your routes lay out with "rake routes".
4
+
5
+ # You can have the root of your site routed with "root"
6
+ # root 'welcome#index'
7
+
8
+ # Example of regular route:
9
+ # get 'products/:id' => 'catalog#view'
10
+
11
+ # Example of named route that can be invoked with purchase_url(id: product.id)
12
+ # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
13
+
14
+ # Example resource route (maps HTTP verbs to controller actions automatically):
15
+ # resources :products
16
+
17
+ # Example resource route with options:
18
+ # resources :products do
19
+ # member do
20
+ # get 'short'
21
+ # post 'toggle'
22
+ # end
23
+ #
24
+ # collection do
25
+ # get 'sold'
26
+ # end
27
+ # end
28
+
29
+ # Example resource route with sub-resources:
30
+ # resources :products do
31
+ # resources :comments, :sales
32
+ # resource :seller
33
+ # end
34
+
35
+ # Example resource route with more complex sub-resources:
36
+ # resources :products do
37
+ # resources :comments
38
+ # resources :sales do
39
+ # get 'recent', on: :collection
40
+ # end
41
+ # end
42
+
43
+ # Example resource route with concerns:
44
+ # concern :toggleable do
45
+ # post 'toggle'
46
+ # end
47
+ # resources :posts, concerns: :toggleable
48
+ # resources :photos, concerns: :toggleable
49
+
50
+ # Example resource route within a namespace:
51
+ # namespace :admin do
52
+ # # Directs /admin/products/* to Admin::ProductsController
53
+ # # (app/controllers/admin/products_controller.rb)
54
+ # resources :products
55
+ # end
56
+ end
@@ -0,0 +1,22 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key is used for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+
6
+ # Make sure the secret is at least 30 characters and all random,
7
+ # no regular words or you'll be exposed to dictionary attacks.
8
+ # You can use `rake secret` to generate a secure secret key.
9
+
10
+ # Make sure the secrets in this file are kept private
11
+ # if you're sharing your code publicly.
12
+
13
+ development:
14
+ secret_key_base: b782370a5ae7ab624ecfea230512310c4c230ffad9a003625ee7ed106565909df519bc62a5ae712c9462c3db011e72f66e8bf3a7f4206a519fdfb8f28e3841e2
15
+
16
+ test:
17
+ secret_key_base: 277ff6fe985366d27e515f1540a5ba3a838d36ed09c42d58f391520027f4923f102a4739279b8d668729f9d935805b7ac89991b35d292b06d76fb6a9f4da565f
18
+
19
+ # Do not keep production secrets in the repository,
20
+ # instead read values from the environment.
21
+ production:
22
+ secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
@@ -0,0 +1,49 @@
1
+ class CreatePush < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :push_configurations do |t|
4
+ t.string :type, :null => false
5
+ t.string :app, :null => false
6
+ t.text :properties, :null => true
7
+ t.boolean :enabled, :null => false, :default => false
8
+ t.integer :connections, :null => false, :default => 1
9
+ t.timestamps
10
+ end
11
+
12
+ create_table :push_messages do |t|
13
+ t.string :app, :null => false
14
+ t.string :device, :null => false
15
+ t.string :type, :null => false
16
+ t.text :properties, :null => true
17
+ t.boolean :delivered, :null => false, :default => false
18
+ t.timestamp :delivered_at, :null => true
19
+ t.boolean :failed, :null => false, :default => false
20
+ t.timestamp :failed_at, :null => true
21
+ t.integer :error_code, :null => true
22
+ t.string :error_description, :null => true
23
+ t.timestamp :deliver_after, :null => true
24
+ t.timestamps
25
+ end
26
+
27
+ add_index :push_messages, [:delivered, :failed, :deliver_after]
28
+
29
+ create_table :push_feedback do |t|
30
+ t.string :app, :null => false
31
+ t.string :device, :null => false
32
+ t.string :type, :null => false
33
+ t.string :follow_up, :null => false
34
+ t.timestamp :failed_at, :null => false
35
+ t.boolean :processed, :null => false, :default => false
36
+ t.timestamp :processed_at, :null => true
37
+ t.text :properties, :null => true
38
+ t.timestamps
39
+ end
40
+
41
+ add_index :push_feedback, :processed
42
+ end
43
+
44
+ def self.down
45
+ drop_table :push_feedback
46
+ drop_table :push_messages
47
+ drop_table :push_configurations
48
+ end
49
+ end
@@ -0,0 +1,59 @@
1
+ # encoding: UTF-8
2
+ # This file is auto-generated from the current state of the database. Instead
3
+ # of editing this file, please use the migrations feature of Active Record to
4
+ # incrementally modify your database, and then regenerate this schema definition.
5
+ #
6
+ # Note that this schema.rb definition is the authoritative source for your
7
+ # database schema. If you need to create the application database on another
8
+ # system, you should be using db:schema:load, not running all the migrations
9
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
11
+ #
12
+ # It's strongly recommended that you check this file into your version control system.
13
+
14
+ ActiveRecord::Schema.define(version: 20160602100607) do
15
+
16
+ create_table "push_configurations", force: :cascade do |t|
17
+ t.string "type", null: false
18
+ t.string "app", null: false
19
+ t.text "properties"
20
+ t.boolean "enabled", default: false, null: false
21
+ t.integer "connections", default: 1, null: false
22
+ t.datetime "created_at"
23
+ t.datetime "updated_at"
24
+ end
25
+
26
+ create_table "push_feedback", force: :cascade do |t|
27
+ t.string "app", null: false
28
+ t.string "device", null: false
29
+ t.string "type", null: false
30
+ t.string "follow_up", null: false
31
+ t.datetime "failed_at", null: false
32
+ t.boolean "processed", default: false, null: false
33
+ t.datetime "processed_at"
34
+ t.text "properties"
35
+ t.datetime "created_at"
36
+ t.datetime "updated_at"
37
+ end
38
+
39
+ add_index "push_feedback", ["processed"], name: "index_push_feedback_on_processed"
40
+
41
+ create_table "push_messages", force: :cascade do |t|
42
+ t.string "app", null: false
43
+ t.string "device", null: false
44
+ t.string "type", null: false
45
+ t.text "properties"
46
+ t.boolean "delivered", default: false, null: false
47
+ t.datetime "delivered_at"
48
+ t.boolean "failed", default: false, null: false
49
+ t.datetime "failed_at"
50
+ t.integer "error_code"
51
+ t.string "error_description"
52
+ t.datetime "deliver_after"
53
+ t.datetime "created_at"
54
+ t.datetime "updated_at"
55
+ end
56
+
57
+ add_index "push_messages", ["delivered", "failed", "deliver_after"], name: "index_push_messages_on_delivered_and_failed_and_deliver_after"
58
+
59
+ end
File without changes
@@ -0,0 +1,28 @@
1
+ module Push
2
+ class FeedbackProcessor
3
+ def self.process(feedback)
4
+ if feedback.instance_of? Push::FeedbackGcm
5
+ if feedback.follow_up == 'delete'
6
+ # TODO: delete gcm device
7
+
8
+ elsif feedback.follow_up == 'update'
9
+ # TODO: update gcm device
10
+ # device = feedback.update_to
11
+
12
+ end
13
+ elsif feedback.instance_of? Push::FeedbackC2dm
14
+ if feedback.follow_up == 'delete'
15
+ # TODO: delete c2dm device
16
+
17
+ end
18
+ elsif feedback.instance_of? Push::FeedbackApns
19
+ if feedback.follow_up == 'delete'
20
+ # TODO: delete apns device
21
+
22
+ end
23
+ else
24
+ Push::Daemon.logger.info("[FeedbackProcessor] Unknown feedback type")
25
+ end
26
+ end
27
+ end
28
+ end
File without changes
@@ -0,0 +1,137 @@
1
+ require 'spec_helper'
2
+
3
+ describe Push::MessageApns do
4
+ let(:app) { 'com.test.app' }
5
+ let(:device) { 'ce8be6272e43e85516033e24b4c289220eeda4879c477160b2545e95b68b5969' }
6
+ let(:expiry) { 1.day.to_i }
7
+ let(:badge) { 1 }
8
+ let(:attributes_for_device) {
9
+ {
10
+ test: 1
11
+ }
12
+ }
13
+ let(:sound) { 'default' }
14
+ let(:alert) { 'We have a new push notification for you' }
15
+ let(:content_available) { 1 }
16
+ let(:priority) { 10 }
17
+ let(:notification_options) {
18
+ {
19
+ app: app,
20
+ device: device,
21
+ expiry: expiry,
22
+ badge: badge,
23
+ attributes_for_device: attributes_for_device,
24
+ sound: sound,
25
+ alert: alert,
26
+ content_available: content_available,
27
+ priority: priority
28
+ }
29
+ }
30
+ let(:instance) { Push::MessageApns.create(notification_options) }
31
+
32
+ describe "#badge" do
33
+ subject { instance.badge }
34
+ it { should == badge }
35
+ end
36
+
37
+ describe "#alert" do
38
+ subject { instance.alert }
39
+ it { should == alert }
40
+ end
41
+
42
+ describe "#app" do
43
+ subject { instance.app }
44
+ it { should == app }
45
+ end
46
+
47
+ describe "#sound" do
48
+ subject { instance.sound }
49
+ it { should == sound }
50
+ end
51
+
52
+ describe "#expiry" do
53
+ subject { instance.expiry }
54
+ it { should == expiry }
55
+ end
56
+
57
+ describe "#device" do
58
+ subject { instance.device }
59
+ it { should == device }
60
+ end
61
+
62
+ describe "#content_available" do
63
+ subject { instance.content_available }
64
+ it { should == content_available }
65
+ end
66
+
67
+ describe "#priority" do
68
+ subject { instance.priority }
69
+ it { should == priority }
70
+ end
71
+
72
+ describe "#attributes_for_device" do
73
+ subject { instance.attributes_for_device }
74
+ it { should == { "test" => 1 } }
75
+ end
76
+
77
+ describe "#payload" do
78
+ it "should create compliant json structure" do
79
+ expect(instance.payload).to eq(MultiJson.dump({
80
+ "aps" => {
81
+ "alert" => alert,
82
+ "badge" => badge,
83
+ "sound" => sound,
84
+ "content-available" => content_available
85
+ },
86
+ "test" => "1"
87
+ }))
88
+ end
89
+ end
90
+
91
+ describe "#to_message" do
92
+ it "should create a message with command 2" do
93
+ command, _1, _2 = instance.to_message.unpack("cNa*")
94
+ expect(command).to eq(2)
95
+ end
96
+
97
+ it "should create a message with correct frame length" do
98
+ _1, length, _2 = instance.to_message.unpack("cNa*")
99
+ expect(length).to eq(176)
100
+ end
101
+
102
+ def items
103
+ _1, _2, items_stream = instance.to_message.unpack("cNa*")
104
+ items = []
105
+ until items_stream.empty?
106
+ item_id, item_length, items_stream = items_stream.unpack("cna*")
107
+ item_data, items_stream = items_stream.unpack("a#{item_length}a*")
108
+ items << [item_id, item_length, item_data]
109
+ end
110
+ items
111
+ end
112
+
113
+ it "should include five items" do
114
+ expect(items.size).to eq(5)
115
+ end
116
+
117
+ it "should include item #1 with the token as hexadecimal" do
118
+ expect(items).to include([1, 32, [device].pack("H*")])
119
+ end
120
+
121
+ it "should include item #2 with the payload as JSON" do
122
+ expect(items).to include([2, 120, "{\"aps\":{\"alert\":\"We have a new push notification for you\",\"badge\":1,\"sound\":\"default\",\"content-available\":1},\"test\":\"1\"}"])
123
+ end
124
+
125
+ it "should include item #3 with the identifier" do
126
+ expect(items).to include([3, 4, [1].pack("N")])
127
+ end
128
+
129
+ it "should include item #4 with the expiry" do
130
+ expect(items).to include([4, 4, [expiry].pack("N")])
131
+ end
132
+
133
+ it "should include item #5 with the priority" do
134
+ expect(items).to include([5, 1, [priority].pack("c")])
135
+ end
136
+ end
137
+ end
@@ -0,0 +1,14 @@
1
+ ENV["RAILS_ENV"] = "test"
2
+
3
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
4
+
5
+ require "rails/test_help"
6
+ require "rspec/rails"
7
+ require "multi_json"
8
+
9
+ # Checks for pending migrations before tests are run.
10
+ ActiveRecord::Migration.maintain_test_schema!
11
+
12
+ RSpec.configure do |config|
13
+ config.use_transactional_fixtures = true
14
+ end
metadata CHANGED
@@ -1,41 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: push-apns
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Pesman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-21 00:00:00.000000000 Z
11
+ date: 2016-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: push-core
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: 1.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: sqlite3
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '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: '3.4'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: activerecord
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
+ - !ruby/object:Gem::Dependency
84
+ name: multi_json
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
39
95
  - !ruby/object:Gem::Version
40
96
  version: '0'
41
97
  description: APNS support for the modular push daemon.
@@ -56,6 +112,45 @@ files:
56
112
  - lib/push/daemon/apns_support/feedback_receiver.rb
57
113
  - lib/push/feedback_apns.rb
58
114
  - lib/push/message_apns.rb
115
+ - spec/dummy/Rakefile
116
+ - spec/dummy/app/assets/images/.keep
117
+ - spec/dummy/app/controllers/application_controller.rb
118
+ - spec/dummy/app/controllers/concerns/.keep
119
+ - spec/dummy/app/helpers/application_helper.rb
120
+ - spec/dummy/app/mailers/.keep
121
+ - spec/dummy/app/models/.keep
122
+ - spec/dummy/app/models/concerns/.keep
123
+ - spec/dummy/app/views/layouts/application.html.erb
124
+ - spec/dummy/bin/bundle
125
+ - spec/dummy/bin/rails
126
+ - spec/dummy/bin/rake
127
+ - spec/dummy/bin/setup
128
+ - spec/dummy/config.ru
129
+ - spec/dummy/config/application.rb
130
+ - spec/dummy/config/boot.rb
131
+ - spec/dummy/config/database.yml
132
+ - spec/dummy/config/environment.rb
133
+ - spec/dummy/config/environments/development.rb
134
+ - spec/dummy/config/environments/production.rb
135
+ - spec/dummy/config/environments/test.rb
136
+ - spec/dummy/config/initializers/assets.rb
137
+ - spec/dummy/config/initializers/backtrace_silencers.rb
138
+ - spec/dummy/config/initializers/cookies_serializer.rb
139
+ - spec/dummy/config/initializers/filter_parameter_logging.rb
140
+ - spec/dummy/config/initializers/inflections.rb
141
+ - spec/dummy/config/initializers/mime_types.rb
142
+ - spec/dummy/config/initializers/session_store.rb
143
+ - spec/dummy/config/initializers/wrap_parameters.rb
144
+ - spec/dummy/config/locales/en.yml
145
+ - spec/dummy/config/routes.rb
146
+ - spec/dummy/config/secrets.yml
147
+ - spec/dummy/db/migrate/20160602100607_create_push.rb
148
+ - spec/dummy/db/schema.rb
149
+ - spec/dummy/lib/assets/.keep
150
+ - spec/dummy/lib/push/feedback_processor.rb
151
+ - spec/dummy/log/.keep
152
+ - spec/push/message_apns_spec.rb
153
+ - spec/spec_helper.rb
59
154
  homepage: https://github.com/tompesman/push-apns
60
155
  licenses: []
61
156
  metadata: {}
@@ -65,18 +160,57 @@ require_paths:
65
160
  - lib
66
161
  required_ruby_version: !ruby/object:Gem::Requirement
67
162
  requirements:
68
- - - '>='
163
+ - - ">="
69
164
  - !ruby/object:Gem::Version
70
165
  version: '0'
71
166
  required_rubygems_version: !ruby/object:Gem::Requirement
72
167
  requirements:
73
- - - '>='
168
+ - - ">="
74
169
  - !ruby/object:Gem::Version
75
170
  version: '0'
76
171
  requirements: []
77
172
  rubyforge_project:
78
- rubygems_version: 2.4.5
173
+ rubygems_version: 2.5.1
79
174
  signing_key:
80
175
  specification_version: 4
81
176
  summary: APNS (iOS/Apple) part of the modular push daemon.
82
- test_files: []
177
+ test_files:
178
+ - spec/dummy/Rakefile
179
+ - spec/dummy/app/assets/images/.keep
180
+ - spec/dummy/app/controllers/application_controller.rb
181
+ - spec/dummy/app/controllers/concerns/.keep
182
+ - spec/dummy/app/helpers/application_helper.rb
183
+ - spec/dummy/app/mailers/.keep
184
+ - spec/dummy/app/models/.keep
185
+ - spec/dummy/app/models/concerns/.keep
186
+ - spec/dummy/app/views/layouts/application.html.erb
187
+ - spec/dummy/bin/bundle
188
+ - spec/dummy/bin/rails
189
+ - spec/dummy/bin/rake
190
+ - spec/dummy/bin/setup
191
+ - spec/dummy/config.ru
192
+ - spec/dummy/config/application.rb
193
+ - spec/dummy/config/boot.rb
194
+ - spec/dummy/config/database.yml
195
+ - spec/dummy/config/environment.rb
196
+ - spec/dummy/config/environments/development.rb
197
+ - spec/dummy/config/environments/production.rb
198
+ - spec/dummy/config/environments/test.rb
199
+ - spec/dummy/config/initializers/assets.rb
200
+ - spec/dummy/config/initializers/backtrace_silencers.rb
201
+ - spec/dummy/config/initializers/cookies_serializer.rb
202
+ - spec/dummy/config/initializers/filter_parameter_logging.rb
203
+ - spec/dummy/config/initializers/inflections.rb
204
+ - spec/dummy/config/initializers/mime_types.rb
205
+ - spec/dummy/config/initializers/session_store.rb
206
+ - spec/dummy/config/initializers/wrap_parameters.rb
207
+ - spec/dummy/config/locales/en.yml
208
+ - spec/dummy/config/routes.rb
209
+ - spec/dummy/config/secrets.yml
210
+ - spec/dummy/db/migrate/20160602100607_create_push.rb
211
+ - spec/dummy/db/schema.rb
212
+ - spec/dummy/lib/assets/.keep
213
+ - spec/dummy/lib/push/feedback_processor.rb
214
+ - spec/dummy/log/.keep
215
+ - spec/push/message_apns_spec.rb
216
+ - spec/spec_helper.rb