rails-push-notifications 0.2.1 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b0de203db302e805cb1ba91599cc359030a2bb27
4
- data.tar.gz: e5904ff7a0ba379a794bc411fb47a5ed0438a1db
3
+ metadata.gz: 221e44ec52855989da2f9a2e67b70ddec144576b
4
+ data.tar.gz: 2cce49cbd19011f0f703f6a4199ce8f854a5cc08
5
5
  SHA512:
6
- metadata.gz: 12c843c8178294da33778841bc849bdd47955c2657abd16f33876c3cdff13879652128a7609dcb9c6f270f0a42bce1da3ac29519a4d9c9169fd3b626f632d6a8
7
- data.tar.gz: 8b539dcdca8a9242c952880a7f3da8776e9c7a5a257fddc75f6dd8d47745ce536b21b25aa0c7b1da587c1891ef4e2574a565dcab2ecb044986afff4702a77f1d
6
+ metadata.gz: 4e0c997bb94f8e50f79f6fe706793f7ecb5759e116c473c3f695a598a8ec609634441a1281bfed7ea8da911d3edf40ce9b0e3e4eb7b89cb3db51765ef77db0f2
7
+ data.tar.gz: ca6224bfb6e432604bed94d8fbe70c5bc69f07fa675cb583857e2fb314ac476cb479ce8e364313417786eac7a6e0e3bf0ee52d8aaea31b30c2dbcdd8b15090cd
data/README.md CHANGED
@@ -1,14 +1,15 @@
1
1
  # Rpn (Ruby on Rails Push Notifications)
2
- [![Build Status](https://travis-ci.org/calonso/rails-push-notifications.svg)](https://travis-ci.org/calonso/rails-push-notifications) [![Code Climate](https://codeclimate.com/github/calonso/rails-push-notifications/badges/gpa.svg)](https://codeclimate.com/github/calonso/rails-push-notifications)[![Test Coverage](https://codeclimate.com/github/calonso/rails-push-notifications/badges/coverage.svg)](https://codeclimate.com/github/calonso/rails-push-notifications/coverage)
2
+ [![Build Status](https://travis-ci.org/calonso/rails-push-notifications.svg)](https://travis-ci.org/calonso/rails-push-notifications) [![Code Climate](https://codeclimate.com/github/calonso/rails-push-notifications/badges/gpa.svg)](https://codeclimate.com/github/calonso/rails-push-notifications) [![Test Coverage](https://codeclimate.com/github/calonso/rails-push-notifications/badges/coverage.svg)](https://codeclimate.com/github/calonso/rails-push-notifications/coverage)
3
3
  ## Professional iOS, Android and Windows Phone push notifications for Ruby on Rails
4
4
 
5
- Rpn is an intuitive and easy to use gem that will allow you to easily add Push Notifications to your project.
5
+ RailsPushNotifications is an intuitive and easy to use gem that will allow you to easily add Push Notifications to your project.
6
6
 
7
- Rpn supports:
7
+ RailsPushNotifications key features:
8
8
 
9
9
  * Multiple Apple/Android/WinPhone applications/configurations
10
10
  * Single and Bulk notifications
11
11
  * Fully customizable notification's contents
12
+ * Detailed feedback on each individual notification's push results.
12
13
 
13
14
  ## Live example
14
15
 
@@ -20,7 +21,7 @@ The source code for that project is here: [https://github.com/calonso/rails_push
20
21
  ## Installation
21
22
  To install the gem simply add this line to your Gemfile
22
23
 
23
- gem 'rails-push-notifications', '~> 0.2'
24
+ gem 'rails-push-notifications', '~> 0.2.0'
24
25
 
25
26
  and then install it by running
26
27
 
@@ -136,7 +137,8 @@ any improvement/bug you may find.
136
137
  Please, feel free to contribute in building any of those or adding more stuff to this list!
137
138
 
138
139
  * Better generation of the data for each kind of notification. Hiding the particulars
139
- to avoid bugs
140
+ to avoid bugs.
141
+ * Rake task to push all notifications from all applications.
140
142
 
141
143
  ## Contributing
142
144
 
data/Rakefile CHANGED
@@ -1,4 +1,7 @@
1
+ require "rubygems"
2
+ require "bundler/setup"
1
3
  require 'bundler'
4
+ require 'appraisal'
2
5
 
3
6
  require 'rspec/core/rake_task'
4
7
 
@@ -6,3 +9,7 @@ RSpec::Core::RakeTask.new(:spec)
6
9
 
7
10
  task :default => :spec
8
11
 
12
+ if !ENV["APPRAISAL_INITIALIZED"] && !ENV["TRAVIS"]
13
+ task :default => :appraisal
14
+ end
15
+
@@ -1,6 +1,6 @@
1
1
  Description:
2
- Generate migrations needed to create RPN tables
2
+ Generate migrations needed to create RailsPushNotifications tables
3
3
 
4
4
  Example:
5
- rails generate ror_push_notifications:migrations
5
+ rails generate rails_push_notifications:migrations
6
6
 
@@ -1,22 +1,34 @@
1
1
  module RailsPushNotifications
2
+ #
3
+ # This class represents an Apple iOS application.
4
+ #
5
+ # @author Carlos Alonso
6
+ #
2
7
  class APNSApp < BaseApp
3
8
  self.table_name = 'rails_push_notifications_apns_apps'
4
9
 
10
+ # Requires a development certificate
5
11
  validates :apns_dev_cert, presence: true
12
+ # Requires a production certificate
6
13
  validates :apns_prod_cert, presence: true
7
14
 
8
15
  before_validation { |app| app.sandbox_mode = true if app.sandbox_mode.nil? }
9
16
 
10
17
  private
11
18
 
19
+ # @return [String] the certificate(dev or prod) to use
12
20
  def cert
13
21
  sandbox_mode ? apns_dev_cert : apns_prod_cert
14
22
  end
15
23
 
24
+ # @return [RubyPushNotifications::APNS::APNSPusher] configured and
25
+ # ready to push
16
26
  def build_pusher
17
27
  RubyPushNotifications::APNS::APNSPusher.new cert, sandbox_mode
18
28
  end
19
29
 
30
+ # @return [RubyPushNotifications::APNS::APNSNotification]. The type of
31
+ # notifications this app manages
20
32
  def notification_type
21
33
  RubyPushNotifications::APNS::APNSNotification
22
34
  end
@@ -1,10 +1,20 @@
1
1
  module RailsPushNotifications
2
+ #
3
+ # Abstract. This class is the base of all application entity type.
4
+ #
5
+ # @author Carlos Alonso
6
+ #
2
7
  class BaseApp < ActiveRecord::Base
3
8
 
4
9
  self.abstract_class = true
5
10
 
11
+ # has_many notifications
6
12
  has_many :notifications, as: :app
7
13
 
14
+ #
15
+ # This method will find all notifications owned by this app and
16
+ # push them.
17
+ #
8
18
  def push_notifications
9
19
  pending = find_pending
10
20
  to_send = pending.map do |notification|
@@ -19,6 +29,9 @@ module RailsPushNotifications
19
29
 
20
30
  protected
21
31
 
32
+ #
33
+ # Method that searches the owned notifications for those not yet sent
34
+ #
22
35
  def find_pending
23
36
  notifications.where sent: false
24
37
  end
@@ -1,15 +1,25 @@
1
1
  module RailsPushNotifications
2
+ #
3
+ # This class represents an Android GCM application.
4
+ #
5
+ # @author Carlos Alonso
6
+ #
2
7
  class GCMApp < BaseApp
3
8
  self.table_name = 'rails_push_notifications_gcm_apps'
4
9
 
10
+ # Requires a gcm_key
5
11
  validates :gcm_key, presence: true
6
12
 
7
13
  private
8
14
 
15
+ # @return [RubyPushNotifications::GCM::GCMPusher] configured and
16
+ # ready to push
9
17
  def build_pusher
10
18
  RubyPushNotifications::GCM::GCMPusher.new gcm_key
11
19
  end
12
20
 
21
+ # @return [RubyPushNotifications::GCM::GCMNotification]. The type of
22
+ # notifications this app manages
13
23
  def notification_type
14
24
  RubyPushNotifications::GCM::GCMNotification
15
25
  end
@@ -1,15 +1,25 @@
1
1
  module RailsPushNotifications
2
+ #
3
+ # This class represents an Windows Phone application.
4
+ #
5
+ # @author Carlos Alonso
6
+ #
2
7
  class MPNSApp < BaseApp
3
8
  self.table_name = 'rails_push_notifications_mpns_apps'
4
9
 
10
+ # Requires the certificate
5
11
  validates :cert, presence: true
6
12
 
7
13
  private
8
14
 
15
+ # @return [RubyPushNotifications::MPNS::MPNSPusher] configured and
16
+ # ready to push
9
17
  def build_pusher
10
18
  RubyPushNotifications::MPNS::MPNSPusher.new cert
11
19
  end
12
20
 
21
+ # @return [RubyPushNotifications::MPNS::MPNSNotification]. The type of
22
+ # notifications this app manages
13
23
  def notification_type
14
24
  RubyPushNotifications::MPNS::MPNSNotification
15
25
  end
@@ -1,23 +1,36 @@
1
1
  module RailsPushNotifications
2
+ #
3
+ # This class represents the Notification Entity.
4
+ #
5
+ # @author Carlos Alonso
6
+ #
2
7
  class Notification < ActiveRecord::Base
3
8
 
4
9
  self.table_name = 'rails_push_notifications_notifications'
5
10
 
11
+ # belongs_to an app
6
12
  belongs_to :app, polymorphic: true
7
13
 
14
+ # Requires an app
8
15
  validates :app, presence: true
16
+ # Requires data
9
17
  validates :data, presence: true
18
+ # Requires at least one destination
10
19
  validates :destinations, presence: true, length: { minimum: 1 }
11
20
 
12
21
  serialize :data, Hash
13
22
  serialize :destinations, Array
14
23
  serialize :results
15
24
 
25
+ # Automatically manages the sent flag, setting it to true as soon as
26
+ # it is assigned results.
16
27
  before_save do |record|
17
28
  record.sent = !record.results.nil?
18
29
  true
19
30
  end
20
31
 
32
+ # Automatically manages the success and failed fields, setting them to the
33
+ # value specified by the results assigned.
21
34
  before_save do |record|
22
35
  if record.results_changed? && record.results
23
36
  record.success = record.results.success
@@ -1,4 +1,9 @@
1
1
  module RailsPushNotifications
2
+ #
3
+ # This class exports the migrations generator to Rails
4
+ #
5
+ # @author Carlos Alonso
6
+ #
2
7
  class RailsPushNotificationsRailtie < Rails::Railtie
3
8
  generators do
4
9
  require 'generators/rails-push-notifications/migrations_generator'
@@ -1,3 +1,3 @@
1
1
  module RailsPushNotifications
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.2'
3
3
  end
@@ -40,6 +40,7 @@ module RailsPushNotifications
40
40
  it 'has to be a Hash' do
41
41
  expect do
42
42
  notification.data = 'dummy text'
43
+ notification.save
43
44
  end.to raise_error ActiveRecord::SerializationTypeMismatch
44
45
  end
45
46
  end
@@ -53,6 +54,7 @@ module RailsPushNotifications
53
54
  it 'has to be an array' do
54
55
  expect do
55
56
  notification.destinations = 'dummy destinations'
57
+ notification.save
56
58
  end.to raise_error ActiveRecord::SerializationTypeMismatch
57
59
  end
58
60
 
@@ -0,0 +1,47 @@
1
+ require 'rails'
2
+ require 'rails/all'
3
+ require 'action_view/testing/resolvers'
4
+ require 'rails/test_help'
5
+
6
+ require 'rails-push-notifications'
7
+
8
+ class RailsPushNotificationsApp < Rails::Application
9
+ config.root = File.expand_path("../../..", __FILE__)
10
+ config.cache_classes = true
11
+
12
+ config.eager_load = false
13
+ config.serve_static_assets = true
14
+ config.static_cache_control = "public, max-age=3600"
15
+
16
+ config.consider_all_requests_local = true
17
+ config.action_controller.perform_caching = false
18
+
19
+ config.action_dispatch.show_exceptions = false
20
+
21
+ config.action_controller.allow_forgery_protection = false
22
+
23
+ config.active_support.deprecation = :stderr
24
+
25
+ config.middleware.delete "Rack::Lock"
26
+ config.middleware.delete "ActionDispatch::Flash"
27
+ config.middleware.delete "ActionDispatch::BestStandardsSupport"
28
+ config.secret_token = "49837489qkuweoiuoqwehisuakshdjksadhaisdy78o34y138974xyqp9rmye8yrpiokeuioqwzyoiuxftoyqiuxrhm3iou1hrzmjk"
29
+ routes.append do
30
+ get "/" => "welcome#index"
31
+ end
32
+ end
33
+
34
+ class ApplicationController < ActionController::Base
35
+ include Rails.application.routes.url_helpers
36
+ layout 'application'
37
+ self.view_paths = [ActionView::FixtureResolver.new(
38
+ "layouts/application.html.erb" => '<%= yield %>',
39
+ "welcome/index.html.erb"=> 'Hello from index.html.erb',
40
+ )]
41
+
42
+ def index
43
+ end
44
+
45
+ end
46
+
47
+ RailsPushNotificationsApp.initialize!
@@ -4,24 +4,34 @@ CodeClimate::TestReporter.start
4
4
 
5
5
  Bundler.setup
6
6
 
7
+ require 'rails'
8
+
7
9
  ENV['RAILS_ENV'] = 'test'
8
- ENV['DATABASE_URL'] = 'sqlite3::memory:'
9
10
 
10
- require 'rails_apps/rails4'
11
- require 'rspec/rails'
12
- Bundler.require :default, :development
11
+ case "#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}"
12
+ when '3.2'
13
+ ENV['DATABASE_URL'] = 'sqlite3://localhost/:memory:'
14
+ require 'rails_apps/rails3_2'
15
+ require 'active_record/migration'
16
+ when '4.0'
17
+ ENV['DATABASE_URL'] = 'sqlite3://localhost/:memory:'
18
+ require 'rails_apps/rails4'
19
+ when '4.1', '4.2'
20
+ ENV['DATABASE_URL'] = 'sqlite3::memory:'
21
+ require 'rails_apps/rails4'
22
+ else
23
+ raise NotImplementedError.new "Rails Friendly URLs gem doesn't support Rails #{Rails.version}"
24
+ end
25
+
26
+ Bundler.require :default
27
+ Bundler.require :development
28
+
13
29
  require 'webmock/rspec'
30
+ require 'rspec/rails'
14
31
  require 'ruby-push-notifications'
15
32
 
16
33
  Dir["./spec/support/**/*.rb"].sort.each { |f| require f }
17
34
 
18
- require 'rails-push-notifications'
19
-
20
- ActiveRecord::Base.establish_connection(
21
- :adapter => 'sqlite3',
22
- :database => ':memory:'
23
- )
24
-
25
35
  files = Dir.glob(File.join(File.dirname(__FILE__), '..', 'lib', 'generators', 'rails-push-notifications', 'templates', 'migrations', '*.rb'))
26
36
 
27
37
  migrations = []
@@ -35,7 +45,13 @@ end
35
45
 
36
46
  migrations.sort_by(&:version)
37
47
 
38
- ActiveRecord::Migrator.new(:up, migrations).migrate
48
+ migrator = ActiveRecord::Migrator.new(:up, migrations)
49
+
50
+ if Rails::VERSION::MAJOR == 3
51
+ migrator.instance_variable_set(:@migrations, migrations)
52
+ end
53
+
54
+ migrator.migrate
39
55
 
40
56
  RSpec.configure do |config|
41
57
  config.use_transactional_fixtures = true
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-push-notifications
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carlos Alonso
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-21 00:00:00.000000000 Z
11
+ date: 2015-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.1'
19
+ version: '3.2'
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
- version: '4.1'
26
+ version: '3.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: ruby-push-notifications
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.1'
33
+ version: '0.3'
34
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: '0.1'
40
+ version: '0.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: sqlite3
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -153,6 +153,7 @@ files:
153
153
  - spec/generators/migrations_generator_spec.rb
154
154
  - spec/log/test.log
155
155
  - spec/notification_spec.rb
156
+ - spec/rails_apps/rails3_2.rb
156
157
  - spec/rails_apps/rails4.rb
157
158
  - spec/spec_helper.rb
158
159
  - spec/support/factory_girl.rb
@@ -190,6 +191,7 @@ test_files:
190
191
  - spec/generators/migrations_generator_spec.rb
191
192
  - spec/log/test.log
192
193
  - spec/notification_spec.rb
194
+ - spec/rails_apps/rails3_2.rb
193
195
  - spec/rails_apps/rails4.rb
194
196
  - spec/spec_helper.rb
195
197
  - spec/support/factory_girl.rb