{"id":24160470,"url":"https://github.com/simpleweb/acts_as_pushable","last_synced_at":"2025-10-04T08:37:24.865Z","repository":{"id":59150432,"uuid":"60543453","full_name":"simpleweb/acts_as_pushable","owner":"simpleweb","description":"Add iOS \u0026 Android device and push notification support in your Rails application.","archived":false,"fork":false,"pushed_at":"2017-03-06T10:38:47.000Z","size":290,"stargazers_count":12,"open_issues_count":1,"forks_count":2,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-04-26T00:25:30.521Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simpleweb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-06-06T16:30:51.000Z","updated_at":"2022-08-09T08:09:55.000Z","dependencies_parsed_at":"2022-09-13T11:00:39.417Z","dependency_job_id":null,"html_url":"https://github.com/simpleweb/acts_as_pushable","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simpleweb%2Facts_as_pushable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simpleweb%2Facts_as_pushable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simpleweb%2Facts_as_pushable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simpleweb%2Facts_as_pushable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simpleweb","download_url":"https://codeload.github.com/simpleweb/acts_as_pushable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233626881,"owners_count":18704811,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-12T16:14:17.807Z","updated_at":"2025-10-04T08:37:24.759Z","avatar_url":"https://github.com/simpleweb.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ActsAsPushable\n\n[![Build Status](https://semaphoreci.com/api/v1/projects/28a53ae7-389f-4d93-9f8a-51c4b0756cf7/840599/badge.svg)](https://semaphoreci.com/simpleweb/acts_as_pushable)\n[![Gem Version](https://badge.fury.io/rb/acts_as_pushable.svg)](https://badge.fury.io/rb/acts_as_pushable)\n\nA gem for Ruby on Rails that makes managing devices and push notifications for both iOS and Android easy and reliable.\n\n## Setup\n\nAdd ActsAsPushable to your Gemfile\n\n  ```shell\n  gem 'acts_as_pushable'\n  bundle install\n  ```\n\nor just install it -\n\n  ```shell\n  gem install acts_as_pushable\n  ```\n\n## Quick start\n\nRun the generator to create the migrations and initializer template -\n\n  ```shell\n  rails generate act_as_pushable:install\n  rake db:migrate\n  ```\n\nThis a file at `config/initializers/acts_as_pushable.rb` that you can modify to match your settings. Follow the quick start guides for the platforms that you want to support.\n\nNext add `acts_as_pushable` the following to the model that you want to have devices, this is usually the `User` model. It should look something like this -\n\n  ```ruby\n  class User \u003c ActiveRecord::Base\n    acts_as_pushable\n  end\n  ```\n\n## Quick start - iOS\n\nBefore we start you'll need a push certificate for both APN Development and APN Production. You can find instructions on how to do this [here](https://developer.apple.com/library/ios/documentation/IDEs/Conceptual/AppDistributionGuide/AddingCapabilities/AddingCapabilities.html#//apple_ref/doc/uid/TP40012582-CH26-SW11).\n\n\u003e **Important:** You should do both production and development and include them in all deployment environments. These relate to the two environments that Apple provide rather than your environments.\n\nOnce you have the certificate from Apple, you will need to export your key and the installed certificate as p12 files. Here how you do this -\n\n1. In Keychain Access find your installed certificate\n2. Right click the certificate, it should have an arrow next to it if install correctly, then export it.\n  ![export](https://cloud.githubusercontent.com/assets/1238468/15851982/5a9bb9e0-2c97-11e6-8407-2e4797673dff.jpg)\n3. Next convert the p12 file to a pem file by running the following command.\n  ```\n  $ openssl pkcs12 -in cert.p12 -out apple_push_notification.pem -nodes -clcerts\n  ```\n4. The output pem file should be put in one of the following locations depending on it's type -\n  - `config/acts_as_pushable/apn/production.pem`\n  - `config/acts_as_pushable/apn/development.pem`\n\n\u003e Note: You can change the location that the pem file is loaded stored in the `acts_as_pushable.rb` initializer.\n\n## Quick start - Android\n\n1. Register for GCM (Google Cloud Messaging) at [developers.google.com](https://developers.google.com/cloud-messaging/).\n2. Enter your key into the `acts_as_pushable.rb` initializer. You can get this from the [Google API Developer Console](https://console.developers.google.com). It should be entered as such -\n\n  ```ruby\n  ActsAsPushable.configure do |config|\n    config.gcm_key = 'replace_me_with_your_api_key'\n  end\n  ```\n\n## Add a device\n\nYou can add a device to any model with `acts_as_pushable`. In these examples we'll use a model named `User` as an example.\n\n  ```ruby\n  user = User.create\n  user.add_device({\n    token: 'the_token_generated_by_the_device',\n    platform: \"ios\",\n    platform_version: \"9.3\",\n    push_environment: \"development\",\n  })\n  ```\n\n## Send a push notification to a user\n\nSending a push notification to a user will send the message to all of their valid device tokens both on iOS \u0026 Android\n\n  ```ruby\n  user = User.find(id)\n  user.send_push_notification(title: 'My App', message: 'this is a test', options)\n  ```\n\n\u003e You might want to consider doing this inside a worker.\n\n## Send a push notification to a specific device\n\n  ```ruby\n  user = User.find(id)\n  device = user.devices.first\n\n  case device.platform\n  when \"ios\"\n    # iOS does not support titles\n    device.send_push_notification(message: 'this is a test', options)\n  when \"android\"\n    device.send_push_notification(message: 'this is a test', { title: 'My App' })\n  end\n  ```\n\n\u003e You might want to consider doing this inside a worker.\n\n## Sending silent push notifications to iOS Devices\n\nYou can send silent push notifications with no message to iOS devices. This is useful when you just want to update the badge count on the home screen.\n\n  ```ruby\n  user = User.find(id)\n  user.send_push_notification(title: false, message: false, content_available: false, count: 2)\n  ```\n\n## Apple Feedback Service\n\nOccasionally you'll want to cleanup old tokens that have been invalidated for various reasons. You can do this by running -\n\n```\nActsAsPushable::APN::FeedbackService.run\n```\n\nWe'd recommnd running this on a daily/weekly cron job.\n\n\u003e Note: With Android this happens at the time of sending a notification, no action is required.\n\n---\n\n## Setup for development\n\nClone the repository -\n\n  ```shell\n  git clone git@github.com:simpleweb/acts_as_pushable.git\n  cd acts_as_pushable\n  bundle install\n  ```\n\n#### Run the specs with RSpec\n\n  ```\n  rspec\n  ```\n\n## Other useful resources\n\n- [Bullet Proof Push](https://www.youtube.com/watch?v=k5J6t-y1bws) _15 minute talk by [Adam Butler](http://twitter.com/labfoo)_ - The ideas that this gem is based on.\n- [simpleweb/ios-development-for-teams](https://github.com/simpleweb/ios-development-for-teams) - A guide by the author of this gem on setting up Certificates, ID's and Provisioning profiles that work well for teams.\n- [nomad/houston](https://github.com/nomad/houston) - Powers the APN part of this gem\n- [spacialdb/gcm](https://github.com/spacialdb/gcm) - Powers the GCM part of this gem.\n\n## Contributing\n\nThis project follows the [GitHub Flow workflow](https://guides.github.com/introduction/flow/). All contributions should be provided as descriptive atomic pull requests.\n\nThe gem should be versioned in accordance to [Semantic Versioning 2.0.0](http://semver.org/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimpleweb%2Facts_as_pushable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimpleweb%2Facts_as_pushable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimpleweb%2Facts_as_pushable/lists"}