{"id":24351136,"url":"https://github.com/roverplatform/apns-kit","last_synced_at":"2025-10-09T22:06:52.074Z","repository":{"id":62553412,"uuid":"56358165","full_name":"RoverPlatform/apns-kit","owner":"RoverPlatform","description":"A Ruby APNs HTTP/2 gem","archived":false,"fork":false,"pushed_at":"2016-06-15T14:17:27.000Z","size":13,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-30T01:04:49.445Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/RoverPlatform.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-16T00:56:30.000Z","updated_at":"2018-02-19T08:37:03.000Z","dependencies_parsed_at":"2022-11-03T04:30:31.104Z","dependency_job_id":null,"html_url":"https://github.com/RoverPlatform/apns-kit","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RoverPlatform%2Fapns-kit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RoverPlatform%2Fapns-kit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RoverPlatform%2Fapns-kit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RoverPlatform%2Fapns-kit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RoverPlatform","download_url":"https://codeload.github.com/RoverPlatform/apns-kit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248127360,"owners_count":21052239,"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-18T14:58:54.572Z","updated_at":"2025-10-09T22:06:47.045Z","avatar_url":"https://github.com/RoverPlatform.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ApnsKit\n\n**NOTE!** this gem is currently under development and no tests have been written yet.\n\nA simple to use gem that interfaces with Apple's new HTTP/2 APNs Service\n\n## Installation\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'apns_kit', '~\u003e 0.1.1'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install apns_kit\n\n## Usage\n\n```ruby\nrequire 'apns_kit'\n\ncertificate = ApnsKit::Certificate.from_p12_file(File.read(\"path_to_cert.p12\"), \"password_or_nil\")\ncertificate = ApnsKit::Certificate.from_pem_file(File.read(\"path_to_cert.pem\"), \"password_or_nil\")\n\n# create a production client (you can also call ApnsKit::Client.development with the same options)\n# pool_size is the number of open connections defaults to 1 (advisable to keep the default value)\n# heartbeat_interval sends a ping to APNs servers to check if the connection is still alive defaults to 60 seconds\nclient = ApnsKit::Client.production(certificate, pool_size: 1, heartbeat_interval: 30)\n\n# Build the notification \nnotification = ApnsKit::Notification.new (\n    token: \"a1ee474316e40f6cfb028c6c508dd0c4e49a2855e55765586789896d0fd03e22\",\n    alert: \"Hello!\",\n    badge: 1,\n    sound: \"mysound.caf\",\n    content_available: true,\n    data: { event_id: 1 } # data can be named to anything. Supports multiple custom keys as well  \n)\n```\n### Blocking send\nThis will block the calling thread until all notifications have been sent and we get a response for all\n```ruby\n# Can send an individual notifications or an array of them\nresponses = client.send(notification)\n# [#\u003cApnsKit::Response:0x007fc0bc065520 200 (Success) notification=#\u003cApnsKit::Notification:0x007fc0bc0b68d0\u003e\u003e] \n```\n### Non Blocking send\nThis will not block the calling thread but instead use a callback for individual responses\n```ruby\nclient.send_async(notification) do |response|\n    if response.success?\n        puts \"Awesome!\"\n    else\n        puts \"Failed: #{response.message} reason: #{response.reason}\n    end\nend\n```\n\n### Fire and forget\nYou can also skip passing the block\n```ruby\nclient.send_async(notification)\n```\n\n### Client considerations\nIf you do not provide a topic for a notification the client will use the app bundle id in your certificate as the topic.\n\nDo not setup and forget about clients. If you are using short term connections you need to call `client.shutdown` to terminate the connection and the threads that it creates. If however you are using the client as a long running connection you can leave them open. If for some reason the connection is dropped the client will reinitiate the connection on your behalf.\n\n## Logger\nApnsKit will use the Rails logger if its present. If not it creates its own logger to `STDOUT`. You can change and modify the logger however you like\n```ruby\nnew_logger = Logger.new(\"some_path.log\")\nApnsKit.logger = new_logger\n```\n\n# Classes\n### ApnsKit::Response\n```ruby\n# response = \u003cApnsKit::Response:0x007fc0bc065520 200 (Success) notification=#\u003cApnsKit::Notification:0x007fc0bc0b68d0\u003e\u003e\nresponse.id                         # returns the id of the notification\nresponse.status                     # returns the http status\nresponse.message                    # converts the status to a meaningful message\nresponse.success?                   # convenience method checking if the status was 200\nresponse.body                       # the json body of the response\nresponse.failure_reason             # convenience method to pull out the failure reason from the body\nresponse.invalid_token?             # returns true if the token was invalid\nresponse.unregistered?              # returns true if the token wasn't registered\nresponse.bad_device_token?          # returns true if the token wasn't properly formatted\nresponse.device_token_not_for_topic? # The device token does not match the specified topic\nresponse.notification               # the ApnsKit::Notification for this response\n```\n\n### ApnsKit::Notification\n```ruby\nnotification = ApnsKit::Notification.new (\n    token: \"a1ee474316e40f6cfb028c6c508dd0c4e49a2855e55765586789896d0fd03e22\",\n    alert: \"Hello!\",\n    badge: 1,\n    sound: \"\",\n    category: \"\",\n    expiry:  1460992609 # A UNIX epoch date expressed in seconds (UTC),\n    priority: 5,\n    content_available: true,\n    data: { event_id: 1 } # data can be named to anything. Supports multiple custom keys as well  \n)\n```\n### ApnsKit::Certificate\n```ruby\ncertificate = ApnsKit::Certificate.new(File.read(\"path_to_certificate.pem\"), \"password_or_nil\")\n\ncertificate.production?     # returns true if the certificate can be used to connect to APNs production environment\ncertificate.development?    # returns true if the certificate can be used to connect to APNs development environment\ncertificate.universal?      # returns true if the certificate can be used to connect to APNs production and development environment\ncertificate.app_bundle_id   # the app bundle id this certificate was issued for\n```\n## Development\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froverplatform%2Fapns-kit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Froverplatform%2Fapns-kit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froverplatform%2Fapns-kit/lists"}