ruby-push-notifications 1.0.1 → 1.1.0

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: 6a56beebcc92083bc2f71294a56bc9ee3bc76eaa
4
- data.tar.gz: 0d26991e228d5e85b6e326aeeaab62b3f718b32d
3
+ metadata.gz: 233dc6f0f402cb52394547c792773699f75c920a
4
+ data.tar.gz: 375783019646d00e93261ef0b032fa59547a4ab6
5
5
  SHA512:
6
- metadata.gz: 97d469ba85e823407ee4d196b480ebb1a33437fdeaca7bac666d8006555e93c4440f493312bc6f0fbcf3133fcdc0f39e8b64ea94d8f7b4a5a2bf0a4f5b3ea592
7
- data.tar.gz: 071ee1997208978781c887538c5699cce6546d59acb52bdd8981ecfc33aa09c456ac595512cfa554d59abdce3619396a03472923d851503b5e2a5fc4ecc69e96
6
+ metadata.gz: f5bbf5568795d0026087b4e84a6856cf1de77738c1cac3daae2f136f9e16f221734b1becf2304d5ea24104cece5820926407b152a5b1a02290595dd4c4b163fe
7
+ data.tar.gz: 2f5a20d5a059bbf43c9116d3eb8af2cd4d5b5f00435cc6c674de1bf215746f7926742f6a92b30ac8863ed1a8769c0597e13e882de464cb1947d66f526ab410a0
data/CHANGELOG.md CHANGED
@@ -3,6 +3,8 @@ All notable changes to this project will be documented in this file.
3
3
  This project adheres to [Semantic Versioning](http://semver.org/).
4
4
 
5
5
  ## [unrealeased] - [unrealease date]
6
+ - **Added**: Option (`url`) to set custom GCM endpoint (Android)
7
+ - **Added**: Option (`host`) to set custom APNS environment (iOS)
6
8
 
7
9
  ## 1.0.1 - 2017-01-12
8
10
  - **Fixed**: Loading issue when `'forwardable'` wasn't previously required.
data/examples/apns.rb CHANGED
@@ -16,6 +16,10 @@ pusher = RubyPushNotifications::APNS::APNSPusher.new(File.read('/path/to/your/ap
16
16
  # Connect timeout defaults to 30s
17
17
  # pusher = RubyPushNotifications::APNS::APNSPusher.new(File.read('/path/to/your/apps/certificate.pem'), true, password, { connect_timeout: 20 })
18
18
 
19
+ # Manually set APNS environment (e.g. useful for load testing)
20
+ # When option `host` is given it always uses this environment, `sandbox` param is ignored.
21
+ # pusher = RubyPushNotifications::APNS::APNSPusher.new(File.read('/path/to/your/apps/certificate.pem'), true, password, { host: "gateway.push.example.com" })
22
+
19
23
  pusher.push [notification]
20
24
  p 'Notification sending results:'
21
25
  p "Success: #{notification.success}, Failed: #{notification.failed}"
data/examples/gcm.rb CHANGED
@@ -15,6 +15,9 @@ pusher = RubyPushNotifications::GCM::GCMPusher.new "Your app's GCM key"
15
15
  # Open and read timeouts default to 30s
16
16
  # pusher = RubyPushNotifications::GCM::GCMPusher.new "Your app's GCM key", { open_timeout: 10, read_timeout: 10 }
17
17
 
18
+ # Manually set GCM URL (e.g. useful for load testing)
19
+ # pusher = RubyPushNotifications::GCM::GCMPusher.new "Your app's GCM key", { url: "https://example.com/gcm/send" }
20
+
18
21
  pusher.push [notification]
19
22
  p 'Notification sending results:'
20
23
  p "Success: #{notification.success}, Failed: #{notification.failed}"
@@ -26,6 +26,7 @@ module RubyPushNotifications
26
26
  # @param sandbox [Boolean]. Whether to use the sandbox environment or not.
27
27
  # @param pass [String] optional. Passphrase for the certificate.
28
28
  # @param options [Hash] optional. Options for #open. Currently supports:
29
+ # * host [String]: Hostname of the APNS environment. Defaults to the official APNS hostname.
29
30
  # * connect_timeout [Integer]: how long the socket will wait for when opening the APNS socket. Defaults to 30.
30
31
  # @return [APNSConnection]. The recently stablished connection.
31
32
  def self.open(cert, sandbox, pass = nil, options = {})
@@ -33,7 +34,7 @@ module RubyPushNotifications
33
34
  ctx.key = OpenSSL::PKey::RSA.new cert, pass
34
35
  ctx.cert = OpenSSL::X509::Certificate.new cert
35
36
 
36
- h = host sandbox
37
+ h = options.fetch(:host, host(sandbox))
37
38
  socket = Socket.tcp h, APNS_PORT, nil, nil, connect_timeout: options.fetch(:connect_timeout, 30)
38
39
  ssl = OpenSSL::SSL::SSLSocket.new socket, ctx
39
40
  ssl.connect
@@ -16,6 +16,7 @@ module RubyPushNotifications
16
16
  # @param certificate [String]. The PEM encoded APNS certificate.
17
17
  # @param sandbox [Boolean]. Whether the certificate is an APNS sandbox or not.
18
18
  # @param options [Hash] optional. Options for APNSPusher. Currently supports:
19
+ # * host [String]: Hostname of the APNS environment. Defaults to the official APNS hostname.
19
20
  # * connect_timeout [Integer]: Number of seconds to wait for the connection to open. Defaults to 30.
20
21
  def initialize(certificate, sandbox, password = nil, options = {})
21
22
  @certificate = certificate
@@ -28,6 +28,7 @@ module RubyPushNotifications
28
28
  # @param key [String]. The GCM sender id to use
29
29
  # (https://developer.android.com/google/gcm/gcm.html#senderid)
30
30
  # @param options [Hash] optional. Options for #post. Currently supports:
31
+ # * url [String]: URL of the GCM endpoint. Defaults to the official GCM URL.
31
32
  # * open_timeout [Integer]: Number of seconds to wait for the connection to open. Defaults to 30.
32
33
  # * read_timeout [Integer]: Number of seconds to wait for one block to be read. Defaults to 30.
33
34
  # @return [GCMResponse]. The GCMResponse that encapsulates the received response
@@ -37,9 +38,9 @@ module RubyPushNotifications
37
38
  AUTHORIZATION_HEADER => "key=#{key}"
38
39
  }
39
40
 
40
- url = URI.parse GCM_URL
41
+ url = URI.parse options.fetch(:url, GCM_URL)
41
42
  http = Net::HTTP.new url.host, url.port
42
- http.use_ssl = true
43
+ http.use_ssl = url.scheme == 'https'
43
44
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
44
45
  http.open_timeout = options.fetch(:open_timeout, 30)
45
46
  http.read_timeout = options.fetch(:read_timeout, 30)
@@ -12,6 +12,7 @@ module RubyPushNotifications
12
12
  # @param key [String]. GCM sender id to use
13
13
  # ((https://developer.android.com/google/gcm/gcm.html#senderid))
14
14
  # @param options [Hash] optional. Options for GCMPusher. Currently supports:
15
+ # * url [String]: URL of the GCM endpoint. Defaults to the official GCM URL.
15
16
  # * open_timeout [Integer]: Number of seconds to wait for the connection to open. Defaults to 30.
16
17
  # * read_timeout [Integer]: Number of seconds to wait for one block to be read. Defaults to 30.
17
18
  def initialize(key, options = {})
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  Gem::Specification.new do |spec|
3
3
  spec.name = "ruby-push-notifications"
4
- spec.version = "1.0.1"
4
+ spec.version = "1.1.0"
5
5
  spec.authors = ['Carlos Alonso']
6
6
  spec.email = ['info@mrcalonso.com']
7
7
  spec.summary = %q{iOS, Android and Windows Phone Push Notifications made easy!}
@@ -28,6 +28,13 @@ module RubyPushNotifications
28
28
  expect(OpenSSL::PKey::RSA).to receive(:new).with(cert, 'password')
29
29
  expect(APNSConnection.open(cert, true, 'password')).to be_a APNSConnection
30
30
  end
31
+
32
+ context 'when :host option is present' do
33
+ it 'opens a connection with a custom APNS' do
34
+ expect(Socket).to receive(:tcp).with('gateway.push.example.com', 2195, nil, nil, { connect_timeout: 30 }).and_return tcp_socket
35
+ APNSConnection.open cert, true, 'password', { host: "gateway.push.example.com" }
36
+ end
37
+ end
31
38
  end
32
39
 
33
40
  describe '#close' do
@@ -23,6 +23,20 @@ module RubyPushNotifications
23
23
  once
24
24
  end
25
25
 
26
+ context 'when :url option is present' do
27
+ it 'posts data to a custom GCM endpoint' do
28
+ stub_request(:post, 'https://example.com/gcm/send').
29
+ to_return status: [200, 'OK'], body: response
30
+
31
+ GCMConnection.post body, key, url: 'https://example.com/gcm/send'
32
+
33
+ expect(WebMock).
34
+ to have_requested(:post, 'https://example.com/gcm/send').
35
+ with(body: body, headers: { 'Content-Type' => 'application/json', 'Authorization' => "key=#{key}" }).
36
+ once
37
+ end
38
+ end
39
+
26
40
  it 'returns the response encapsulated in a GCMResponse object' do
27
41
  expect(GCMConnection.post body, key).to eq GCMResponse.new(200, response)
28
42
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-push-notifications
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carlos Alonso
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-20 00:00:00.000000000 Z
11
+ date: 2017-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: builder