pusher-push-notifications 0.3.1 → 1.3.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
  SHA256:
3
- metadata.gz: f5f179801f663e3f2ef76bbad684fe37dfb003636ae39356f832565c351dccdc
4
- data.tar.gz: 36b660566d424a15eeecf8d1c6d5731e3d7af4393b78318d677e7eec86eda2d6
3
+ metadata.gz: 0c2390e1a4a59aac3d17169ef09419fee58805d3d2f3679d07b93f3079f8b98f
4
+ data.tar.gz: 718bd77ac234dedc626dcb4c21f7a9e445a22e0c4c15279f22b3a7ada844e369
5
5
  SHA512:
6
- metadata.gz: d566ba46b0a2cbe7f784f1e3093aed15df19dabf68bad4a1e7df448e55e230b3136298595025429712ebe103998454d4504aaa82a2905223da52d8f25649c93a
7
- data.tar.gz: ead9faa60b578fb70acc4ed8677e11c96a94bba9ed34994cfe0acee05d3e56b534f92a96cf1d492e5df24d231530ad15e3fec6d6d5b84ab86b3a3264712eec86
6
+ metadata.gz: 05b38f814043989418b15f64cd51c4181a9f9baf7f19cb7110fc5cd511056e03eedcce1366612a9dda477cfcdb82bba50af03ab757c69f90269ae883d4bf1807
7
+ data.tar.gz: '08631394abc01bcd223e371bc81ae939ae23ce97f0fb621a1cb6d41dca9779f4c9e91e4639a3b9493bc3ee0eb81de53f2a8a7552ea21bda5e4f3826eaf578cd5'
@@ -5,19 +5,23 @@ AllCops:
5
5
  TargetRubyVersion: 2.4.0
6
6
 
7
7
  Metrics/LineLength:
8
- Max: 100
8
+ Enabled:
9
+ Max: 80
10
+
11
+ Style/GuardClause:
12
+ Enabled: false
9
13
 
10
14
  Metrics/MethodLength:
11
- Exclude:
12
- - 'spec/**/*.rb'
15
+ Enabled: false
13
16
 
14
- Exclude:
15
- - 'spec/**/*.rb'
17
+ Metrics/AbcSize:
18
+ Enabled: false
16
19
 
17
20
  Metrics/ModuleLength:
18
21
  Exclude:
19
- - 'spec/**/*.rb'
22
+ - "spec/**/*.rb"
20
23
 
21
24
  Metrics/BlockLength:
22
25
  Exclude:
23
- - 'spec/**/*.rb'
26
+ - "spec/**/*.rb"
27
+ - "pusher-push-notifications.gemspec"
@@ -3,3 +3,6 @@ language: ruby
3
3
  rvm:
4
4
  - 2.4.2
5
5
  before_install: gem install bundler -v 1.16.0
6
+ script:
7
+ - bundle exec rake
8
+ - bundle exec rubocop
@@ -0,0 +1,36 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
6
+ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased](https://github.com/pusher/push-notifications-ruby/compare/v1.3.0...HEAD)
9
+
10
+ ## [1.3.0](https://github.com/pusher/push-notifications-ruby/compare/v1.2.1...v1.3.0) - 2020-07-01
11
+
12
+ Added
13
+
14
+ Support for multiple instances of Beams clients to exist for more advanced use cases.
15
+
16
+ ## [1.2.1](https://github.com/pusher/push-notifications-ruby/compare/v1.2.0...v1.2.1) - 2020-06-26
17
+
18
+ Fixed
19
+
20
+ Endpoint also allows the scheme to be configured to enable for local development.
21
+
22
+ ## [1.2.0](https://github.com/pusher/push-notifications-ruby/compare/v1.1.0...v1.2.0) - 2020-06-25
23
+
24
+ Added
25
+
26
+ Support for "endpoint" overrides to allow for internal integration testing.
27
+
28
+ ## [1.1.0](https://github.com/pusher/push-notifications-ruby/compare/v1.0.0...v1.1.0) - 2019-02-22
29
+
30
+ Added
31
+
32
+ Support for "Authenticated Users" feature: publishToUsers, generateToken and deleteUser.
33
+
34
+ ## [1.0.0](https://github.com/pusher/push-notifications-ruby/compare/v0.3.0...v1.0.0) - 2018-07-31
35
+
36
+ - General availability (GA) release.
data/Gemfile CHANGED
@@ -6,5 +6,3 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
6
 
7
7
  # Specify your gem's dependencies in pusher-push_notifications.gemspec
8
8
  gemspec
9
-
10
- gem 'codecov', :require => false, :group => :test
@@ -1,22 +1,23 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pusher-push-notifications (0.3.1)
5
- caze
6
- rest-client
4
+ pusher-push-notifications (1.3.0)
5
+ caze (~> 0)
6
+ jwt (~> 2.1, >= 2.1.0)
7
+ rest-client (~> 2.0, >= 2.0.2)
7
8
 
8
9
  GEM
9
10
  remote: https://rubygems.org/
10
11
  specs:
11
- activesupport (5.1.5)
12
+ activesupport (5.2.2)
12
13
  concurrent-ruby (~> 1.0, >= 1.0.2)
13
- i18n (~> 0.7)
14
+ i18n (>= 0.7, < 2)
14
15
  minitest (~> 5.1)
15
16
  tzinfo (~> 1.1)
16
17
  addressable (2.5.2)
17
18
  public_suffix (>= 2.0.2, < 4.0)
18
19
  ast (2.3.0)
19
- byebug (9.1.0)
20
+ byebug (10.0.2)
20
21
  caze (0.2.2)
21
22
  activesupport (>= 3)
22
23
  codecov (0.1.10)
@@ -24,7 +25,7 @@ GEM
24
25
  simplecov
25
26
  url
26
27
  coderay (1.1.2)
27
- concurrent-ruby (1.0.5)
28
+ concurrent-ruby (1.1.4)
28
29
  coveralls (0.8.21)
29
30
  json (>= 1.8, < 3)
30
31
  simplecov (~> 0.14.1)
@@ -35,34 +36,36 @@ GEM
35
36
  safe_yaml (~> 1.0.0)
36
37
  diff-lcs (1.3)
37
38
  docile (1.1.5)
38
- domain_name (0.5.20170404)
39
+ domain_name (0.5.20180417)
39
40
  unf (>= 0.0.5, < 1.0.0)
40
41
  dotenv (2.2.1)
41
42
  hashdiff (0.3.7)
42
43
  http-cookie (1.0.3)
43
44
  domain_name (~> 0.5)
44
- i18n (0.9.5)
45
+ i18n (1.5.3)
45
46
  concurrent-ruby (~> 1.0)
46
47
  json (2.1.0)
47
- method_source (0.9.0)
48
- mime-types (3.1)
48
+ jwt (2.1.0)
49
+ method_source (0.9.2)
50
+ mime-types (3.2.2)
49
51
  mime-types-data (~> 3.2015)
50
- mime-types-data (3.2016.0521)
52
+ mime-types-data (3.2018.0812)
51
53
  minitest (5.11.3)
52
54
  netrc (0.11.0)
53
55
  parallel (1.12.1)
54
56
  parser (2.4.0.2)
55
57
  ast (~> 2.3)
56
58
  powerpack (0.1.1)
57
- pry (0.11.3)
59
+ pry (0.12.2)
58
60
  coderay (~> 1.1.0)
59
61
  method_source (~> 0.9.0)
60
- pry-byebug (3.5.1)
61
- byebug (~> 9.1)
62
+ pry-byebug (3.6.0)
63
+ byebug (~> 10.0)
62
64
  pry (~> 0.10)
63
65
  public_suffix (3.0.1)
64
66
  rainbow (3.0.0)
65
67
  rake (10.5.0)
68
+ rb-readline (0.5.5)
66
69
  rest-client (2.0.2)
67
70
  http-cookie (>= 1.0.2, < 2.0)
68
71
  mime-types (>= 1.16, < 4.0)
@@ -117,16 +120,17 @@ PLATFORMS
117
120
 
118
121
  DEPENDENCIES
119
122
  bundler (~> 1.16)
120
- codecov
123
+ codecov (~> 0)
121
124
  coveralls (~> 0.8.21)
122
125
  dotenv (~> 2.2, >= 2.2.1)
123
- pry-byebug
126
+ pry-byebug (~> 3.6, >= 3.6.0)
124
127
  pusher-push-notifications!
125
128
  rake (~> 10.0)
129
+ rb-readline (~> 0)
126
130
  rspec (~> 3.0)
127
- rubocop
131
+ rubocop (>= 0.49.0)
128
132
  vcr (~> 3.0, >= 3.0.3)
129
133
  webmock (~> 3.0, >= 3.0.1)
130
134
 
131
135
  BUNDLED WITH
132
- 1.16.1
136
+ 1.16.2
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
- # Pusher Push Notifications Ruby Server SDK
1
+ # Pusher Beams Ruby Server SDK
2
2
 
3
3
  [![Build Status](https://travis-ci.org/pusher/push-notifications-ruby.svg?branch=master)](https://travis-ci.org/pusher/push-notifications-ruby)
4
4
  [![Coverage Status](https://coveralls.io/repos/github/pusher/push-notifications-ruby/badge.svg?branch=update-sdk)](https://coveralls.io/github/pusher/push-notifications-ruby?branch=update-sdk)
5
5
 
6
- Push notifications using the Pusher system.
6
+ Pusher Beams using the Pusher system.
7
7
 
8
8
  ## Installation
9
9
 
@@ -22,19 +22,25 @@ gem 'pusher-push-notifications'
22
22
  This configuration can be done anywhere you want, but if you are using rails the better place to put it is inside an initializer
23
23
 
24
24
  ```ruby
25
+ require 'pusher/push_notifications'
26
+
25
27
  Pusher::PushNotifications.configure do |config|
26
28
   config.instance_id = ENV['PUSHER_INSTANCE_ID'] # or the value directly
27
29
   config.secret_key = ENV['PUSHER_SECRET_KEY']
28
30
  end
29
31
  ```
30
32
 
31
- Where `instance_id` and `secret_key` are the values of the instance you created in the push notifications dashboard
33
+ Where `instance_id` and `secret_key` are the values of the instance you created in the Pusher Beams dashboard.
34
+
35
+ If multiple clients are needed, store the reference that is returned from the `configure` method.
32
36
 
33
37
  ## Usage
34
38
 
35
39
  After the configuration is done you can push notifications like this:
36
40
 
37
41
  ```ruby
42
+ require 'pusher/push_notifications'
43
+
38
44
  data = {
39
45
  apns: {
40
46
  aps: {
@@ -52,7 +58,17 @@ data = {
52
58
  }
53
59
  }
54
60
 
55
- Pusher::PushNotifications.publish(interests: ['hello'], payload: data)
61
+ # Publish the given 'data' to the specified interests.
62
+ Pusher::PushNotifications.publish_to_interests(interests: ['hello'], payload: data)
63
+
64
+ # Publish the given 'data' to the specified users.
65
+ Pusher::PushNotifications.publish_to_users(users: ['jonathan', 'jordan', 'luis', 'luka', 'mina'], payload: data)
66
+
67
+ # Authenticate User
68
+ Pusher::PushNotifications.generate_token(user: 'Elmo')
69
+
70
+ # Delete User
71
+ Pusher::PushNotifications.delete_user(user: 'Elmo')
56
72
  ```
57
73
 
58
74
  The return of this call is a ruby struct containing the http status code (`status`) the response body (`content`) and an `ok?` attribute saying if the notification was successful or not.
@@ -61,14 +77,7 @@ The return of this call is a ruby struct containing the http status code (`statu
61
77
 
62
78
  ## Errors
63
79
 
64
- The errors statuses can be:
65
-
66
- HTTP Status | Reason
67
- --- | ---
68
- 401 | Incorrect secret key
69
- 400 | Payload too big (10Kb limit), Payload invalid, Payload in a wrong schema, instance_id missing
70
- 404 | Instance not found
71
- 500 | Internal server error
80
+ All available error responses can be be found [here](https://docs.pusher.com/beams/reference/publish-api#error-responses).
72
81
 
73
82
  ## Development
74
83
 
@@ -6,7 +6,7 @@ require 'bundler/setup'
6
6
  require 'dotenv'
7
7
  Dotenv.load
8
8
 
9
- require 'pusher'
9
+ require 'pusher/push_notifications'
10
10
 
11
11
  Pusher::PushNotifications.configure do |config|
12
12
  config.instance_id = ENV['PUSHER_INSTANCE_ID']
@@ -4,7 +4,12 @@ require 'caze'
4
4
 
5
5
  require_relative './push_notifications/client'
6
6
  require_relative './push_notifications/use_cases/publish'
7
+ require_relative './push_notifications/use_cases/publish_to_users'
8
+ require_relative './push_notifications/use_cases/delete_user'
9
+ require_relative './push_notifications/use_cases/generate_token'
7
10
  require_relative './push_notifications/version'
11
+ require_relative './push_notifications/user_id'
12
+ require_relative './push_notifications/token'
8
13
 
9
14
  module Pusher
10
15
  module PushNotifications
@@ -13,24 +18,48 @@ module Pusher
13
18
  class PushError < RuntimeError; end
14
19
 
15
20
  has_use_case :publish, UseCases::Publish
21
+ has_use_case :publish_to_interests, UseCases::Publish
22
+ has_use_case :publish_to_users, UseCases::PublishToUsers
23
+ has_use_case :delete_user, UseCases::DeleteUser
24
+ has_use_case :generate_token, UseCases::GenerateToken
16
25
 
17
26
  class << self
18
27
  attr_reader :instance_id, :secret_key
19
28
 
20
29
  def configure
21
30
  yield(self)
22
- self
31
+ # returning a duplicate of `self` to allow multiple clients to be
32
+ # configured without needing to reconfigure the singleton instance
33
+ dup
23
34
  end
24
35
 
25
36
  def instance_id=(instance_id)
26
- raise PushError, 'Invalid instance id' if instance_id.nil? || instance_id.delete(' ').empty?
37
+ if instance_id.nil? || instance_id.delete(' ').empty?
38
+ raise PushError, 'Invalid instance id'
39
+ end
27
40
  @instance_id = instance_id
28
41
  end
29
42
 
30
43
  def secret_key=(secret_key)
31
- raise PushError, 'Invalid secret key' if secret_key.nil? || secret_key.delete(' ').empty?
44
+ if secret_key.nil? || secret_key.delete(' ').empty?
45
+ raise PushError, 'Invalid secret key'
46
+ end
32
47
  @secret_key = secret_key
33
48
  end
49
+
50
+ def endpoint=(endpoint)
51
+ if !endpoint.nil? && endpoint.delete(' ').empty?
52
+ raise PushError, 'Invalid endpoint override'
53
+ end
54
+
55
+ @endpoint = endpoint
56
+ end
57
+
58
+ def endpoint
59
+ return @endpoint unless @endpoint.nil?
60
+
61
+ "https://#{@instance_id}.pushnotifications.pusher.com"
62
+ end
34
63
  end
35
64
  end
36
65
  end
@@ -9,8 +9,6 @@ module Pusher
9
9
  class Client
10
10
  extend Forwardable
11
11
 
12
- BASE_URL = 'pushnotifications.pusher.com/publish_api/v1/instances'
13
-
14
12
  Response = Struct.new(:status, :content, :ok?)
15
13
 
16
14
  def initialize(config: PushNotifications)
@@ -18,7 +16,7 @@ module Pusher
18
16
  end
19
17
 
20
18
  def post(resource, payload = {})
21
- url = build_url(resource)
19
+ url = build_publish_url(resource)
22
20
  body = payload.to_json
23
21
 
24
22
  RestClient::Request.execute(
@@ -30,7 +28,25 @@ module Pusher
30
28
  body = JSON.parse(response.body)
31
29
  Response.new(status, body, status == 200)
32
30
  else
33
- Response.new(500, nil, false)
31
+ Response.new(status, nil, false)
32
+ end
33
+ end
34
+ end
35
+
36
+ def delete(user)
37
+ url_encoded_user_id = CGI.escape(user)
38
+ url = build_users_url(url_encoded_user_id)
39
+
40
+ RestClient::Request.execute(
41
+ method: :delete, url: url,
42
+ headers: headers
43
+ ) do |response|
44
+ status = response.code
45
+ case status
46
+ when 200
47
+ Response.new(status, nil, true)
48
+ else
49
+ Response.new(status, nil, false)
34
50
  end
35
51
  end
36
52
  end
@@ -38,17 +54,24 @@ module Pusher
38
54
  private
39
55
 
40
56
  attr_reader :config
41
- def_delegators :@config, :instance_id, :secret_key
57
+ def_delegators :@config, :instance_id, :secret_key, :endpoint
58
+
59
+ def build_publish_url(resource)
60
+ "#{endpoint}/publish_api/v1/instances/#{instance_id}/#{resource}"
61
+ end
42
62
 
43
- def build_url(resource)
44
- "https://#{instance_id}.#{BASE_URL}/#{instance_id}/#{resource}"
63
+ def build_users_url(user)
64
+ "#{endpoint}/customer_api/v1/instances/#{instance_id}/users/#{user}"
45
65
  end
46
66
 
47
67
  def headers
48
68
  {
49
69
  content_type: 'application/json',
50
70
  accept: :json,
51
- Authorization: "Bearer #{secret_key}"
71
+ Authorization: "Bearer #{secret_key}",
72
+ 'X-Pusher-Library':
73
+ 'pusher-push-notifications-ruby ' \
74
+ "#{Pusher::PushNotifications::VERSION}"
52
75
  }
53
76
  end
54
77
 
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'jwt'
4
+
5
+ module Pusher
6
+ module PushNotifications
7
+ class Token
8
+ extend Forwardable
9
+ def initialize(config: PushNotifications)
10
+ @config = config
11
+ end
12
+
13
+ def generate(user)
14
+ exp = Time.now.to_i + 24 * 60 * 60 # Current time + 24h
15
+ iss = "https://#{instance_id}.pushnotifications.pusher.com"
16
+ payload = { 'sub' => user, 'exp' => exp, 'iss' => iss }
17
+ JWT.encode payload, secret_key, 'HS256'
18
+ end
19
+
20
+ private
21
+
22
+ attr_reader :config
23
+ def_delegators :@config, :instance_id, :secret_key
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'caze'
4
+
5
+ module Pusher
6
+ module PushNotifications
7
+ module UseCases
8
+ class DeleteUser
9
+ include Caze
10
+
11
+ class UserDeletionError < RuntimeError; end
12
+
13
+ export :delete_user, as: :delete_user
14
+
15
+ def initialize(user:)
16
+ @user = user
17
+ @user_id = Pusher::PushNotifications::UserId.new
18
+
19
+ raise UserDeletionError, 'User Id cannot be empty.' if user.empty?
20
+ if user.length > UserId::MAX_USER_ID_LENGTH
21
+ raise UserDeletionError, 'User id length too long ' \
22
+ "(expected fewer than #{UserId::MAX_USER_ID_LENGTH + 1} characters)"
23
+ end
24
+ end
25
+
26
+ # Contacts the Beams service
27
+ # to remove all the devices of the given user.
28
+ def delete_user
29
+ client.delete(user)
30
+ end
31
+
32
+ private
33
+
34
+ attr_reader :user
35
+
36
+ def client
37
+ @client ||= PushNotifications::Client.new
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'caze'
4
+
5
+ module Pusher
6
+ module PushNotifications
7
+ module UseCases
8
+ class GenerateToken
9
+ include Caze
10
+
11
+ class GenerateTokenError < RuntimeError; end
12
+
13
+ export :generate_token, as: :generate_token
14
+
15
+ def initialize(user:)
16
+ @user = user
17
+ @user_id = Pusher::PushNotifications::UserId.new
18
+
19
+ raise GenerateTokenError, 'User Id cannot be empty.' if user.empty?
20
+ if user.length > UserId::MAX_USER_ID_LENGTH
21
+ raise GenerateTokenError, 'User id length too long ' \
22
+ "(expected fewer than #{UserId::MAX_USER_ID_LENGTH + 1} characters)"
23
+ end
24
+ end
25
+
26
+ # Creates a signed JWT for a user id.
27
+ def generate_token
28
+ { 'token' => jwt_token.generate(user) }
29
+ end
30
+
31
+ private
32
+
33
+ attr_reader :user
34
+
35
+ def jwt_token
36
+ @jwt_token ||= PushNotifications::Token.new
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -10,25 +10,43 @@ module Pusher
10
10
 
11
11
  class PublishError < RuntimeError; end
12
12
 
13
- export :call, as: :publish
13
+ export :publish, as: :publish
14
+ export :publish_to_interests, as: :publish_to_interests
14
15
 
15
16
  def initialize(interests:, payload: {})
17
+ @interests = interests
18
+ @payload = payload
19
+ @user_id = Pusher::PushNotifications::UserId.new
20
+
16
21
  valid_interest_pattern = /^(_|\-|=|@|,|\.|:|[A-Z]|[a-z]|[0-9])*$/
17
22
 
18
23
  interests.each do |interest|
19
- if (is_invalid_interest_name = !valid_interest_pattern.match(interest))
20
- raise PublishError, "Invalid interest name \nMax 164 characters and can only contain ASCII upper/lower-case letters, numbers or one of _-=@,.:"
21
- end
24
+ next if valid_interest_pattern.match?(interest)
25
+ raise PublishError,
26
+ "Invalid interest name \nMax #{UserId::MAX_USER_ID_LENGTH}" \
27
+ ' characters and can only contain ASCII upper/lower-case' \
28
+ ' letters, numbers or one of _-=@,.:'
22
29
  end
23
30
 
24
- raise PublishError, 'Must provide at least one interest' if interests.length == 0
25
- raise PublishError, "Number of interests #{interests.length} exceeds maximum of 100" if interests.length > 100
31
+ if interests.empty?
32
+ raise PublishError, 'Must provide at least one interest'
33
+ end
34
+ if interests.length > 100
35
+ raise PublishError, "Number of interests #{interests.length}" \
36
+ ' exceeds maximum of 100'
37
+ end
38
+ end
26
39
 
27
- @interests = interests
28
- @payload = payload
40
+ # Publish the given payload to the specified interests.
41
+ # <b>DEPRECATED:</b> Please use <tt>publish_to_interests</tt> instead.
42
+ def publish
43
+ warn "[DEPRECATION] `publish` is deprecated. \
44
+ Please use `publish_to_interests` instead."
45
+ publish_to_interests
29
46
  end
30
47
 
31
- def call
48
+ # Publish the given payload to the specified interests.
49
+ def publish_to_interests
32
50
  data = { interests: interests }.merge!(payload)
33
51
  client.post('publishes', data)
34
52
  end
@@ -38,7 +56,7 @@ module Pusher
38
56
  attr_reader :interests, :payload
39
57
 
40
58
  def client
41
- @_client ||= PushNotifications::Client.new
59
+ @client ||= PushNotifications::Client.new
42
60
  end
43
61
  end
44
62
  end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'caze'
4
+
5
+ module Pusher
6
+ module PushNotifications
7
+ module UseCases
8
+ class PublishToUsers
9
+ include Caze
10
+
11
+ class UsersPublishError < RuntimeError; end
12
+
13
+ export :publish_to_users, as: :publish_to_users
14
+
15
+ def initialize(users:, payload: {})
16
+ @users = users
17
+ @user_id = Pusher::PushNotifications::UserId.new
18
+ @payload = payload
19
+
20
+ users.each do |user|
21
+ raise UsersPublishError, 'User Id cannot be empty.' if user.empty?
22
+
23
+ next unless user.length > UserId::MAX_USER_ID_LENGTH
24
+ raise UsersPublishError, 'User id length too long ' \
25
+ "(expected fewer than #{UserId::MAX_USER_ID_LENGTH + 1}" \
26
+ ' characters)'
27
+ end
28
+
29
+ if users.count < 1
30
+ raise UsersPublishError, 'Must supply at least one user id.'
31
+ end
32
+ if users.length > UserId::MAX_NUM_USER_IDS
33
+ raise UsersPublishError, "Number of user ids #{users.length} "\
34
+ "exceeds maximum of #{UserId::MAX_NUM_USER_IDS}."
35
+ end
36
+ end
37
+
38
+ # Publish the given payload to the specified users.
39
+ def publish_to_users
40
+ data = { users: users }.merge!(payload)
41
+ client.post('publishes/users', data)
42
+ end
43
+
44
+ private
45
+
46
+ attr_reader :users, :payload
47
+
48
+ def client
49
+ @client ||= PushNotifications::Client.new
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pusher
4
+ module PushNotifications
5
+ class UserId
6
+ MAX_USER_ID_LENGTH = 164
7
+ MAX_NUM_USER_IDS = 1000
8
+ end
9
+ end
10
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Pusher
4
4
  module PushNotifications
5
- VERSION = '0.3.1'
5
+ VERSION = '1.3.0'
6
6
  end
7
7
  end
@@ -1,7 +1,6 @@
1
-
2
1
  # frozen_string_literal: true
3
2
 
4
- lib = File.expand_path('../lib', __FILE__)
3
+ lib = File.expand_path('lib', __dir__)
5
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
5
  require 'pusher/push_notifications/version'
7
6
 
@@ -22,16 +21,19 @@ Gem::Specification.new do |spec|
22
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
22
  spec.require_paths = ['lib']
24
23
 
25
- spec.add_dependency 'caze'
26
- spec.add_dependency 'rest-client'
24
+ spec.add_dependency 'caze', '~> 0'
25
+ spec.add_dependency 'jwt', '~> 2.1', '>= 2.1.0'
26
+ spec.add_dependency 'rest-client', '~> 2.0', '>= 2.0.2'
27
27
 
28
28
  spec.add_development_dependency 'bundler', '~> 1.16'
29
+ spec.add_development_dependency 'codecov', '~> 0'
29
30
  spec.add_development_dependency 'coveralls', '~> 0.8.21'
30
31
  spec.add_development_dependency 'dotenv', '~> 2.2', '>= 2.2.1'
31
- spec.add_development_dependency 'pry-byebug'
32
+ spec.add_development_dependency 'pry-byebug', '~> 3.6', '>= 3.6.0'
32
33
  spec.add_development_dependency 'rake', '~> 10.0'
34
+ spec.add_development_dependency 'rb-readline', '~> 0'
33
35
  spec.add_development_dependency 'rspec', '~> 3.0'
34
- spec.add_development_dependency 'rubocop'
36
+ spec.add_development_dependency 'rubocop', '>= 0.49.0'
35
37
  spec.add_development_dependency 'vcr', '~> 3.0', '>= 3.0.3'
36
38
  spec.add_development_dependency 'webmock', '~> 3.0', '>= 3.0.1'
37
39
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pusher-push-notifications
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lucas Medeiros
@@ -9,36 +9,62 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2018-05-25 00:00:00.000000000 Z
12
+ date: 2020-07-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: caze
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ">="
18
+ - - "~>"
19
19
  - !ruby/object:Gem::Version
20
20
  version: '0'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ">="
25
+ - - "~>"
26
26
  - !ruby/object:Gem::Version
27
27
  version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: jwt
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 2.1.0
35
+ - - "~>"
36
+ - !ruby/object:Gem::Version
37
+ version: '2.1'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: 2.1.0
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.1'
28
48
  - !ruby/object:Gem::Dependency
29
49
  name: rest-client
30
50
  requirement: !ruby/object:Gem::Requirement
31
51
  requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
32
55
  - - ">="
33
56
  - !ruby/object:Gem::Version
34
- version: '0'
57
+ version: 2.0.2
35
58
  type: :runtime
36
59
  prerelease: false
37
60
  version_requirements: !ruby/object:Gem::Requirement
38
61
  requirements:
62
+ - - "~>"
63
+ - !ruby/object:Gem::Version
64
+ version: '2.0'
39
65
  - - ">="
40
66
  - !ruby/object:Gem::Version
41
- version: '0'
67
+ version: 2.0.2
42
68
  - !ruby/object:Gem::Dependency
43
69
  name: bundler
44
70
  requirement: !ruby/object:Gem::Requirement
@@ -53,6 +79,20 @@ dependencies:
53
79
  - - "~>"
54
80
  - !ruby/object:Gem::Version
55
81
  version: '1.16'
82
+ - !ruby/object:Gem::Dependency
83
+ name: codecov
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
56
96
  - !ruby/object:Gem::Dependency
57
97
  name: coveralls
58
98
  requirement: !ruby/object:Gem::Requirement
@@ -93,14 +133,20 @@ dependencies:
93
133
  requirements:
94
134
  - - ">="
95
135
  - !ruby/object:Gem::Version
96
- version: '0'
136
+ version: 3.6.0
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: '3.6'
97
140
  type: :development
98
141
  prerelease: false
99
142
  version_requirements: !ruby/object:Gem::Requirement
100
143
  requirements:
101
144
  - - ">="
102
145
  - !ruby/object:Gem::Version
103
- version: '0'
146
+ version: 3.6.0
147
+ - - "~>"
148
+ - !ruby/object:Gem::Version
149
+ version: '3.6'
104
150
  - !ruby/object:Gem::Dependency
105
151
  name: rake
106
152
  requirement: !ruby/object:Gem::Requirement
@@ -115,6 +161,20 @@ dependencies:
115
161
  - - "~>"
116
162
  - !ruby/object:Gem::Version
117
163
  version: '10.0'
164
+ - !ruby/object:Gem::Dependency
165
+ name: rb-readline
166
+ requirement: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - "~>"
169
+ - !ruby/object:Gem::Version
170
+ version: '0'
171
+ type: :development
172
+ prerelease: false
173
+ version_requirements: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - "~>"
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
118
178
  - !ruby/object:Gem::Dependency
119
179
  name: rspec
120
180
  requirement: !ruby/object:Gem::Requirement
@@ -135,14 +195,14 @@ dependencies:
135
195
  requirements:
136
196
  - - ">="
137
197
  - !ruby/object:Gem::Version
138
- version: '0'
198
+ version: 0.49.0
139
199
  type: :development
140
200
  prerelease: false
141
201
  version_requirements: !ruby/object:Gem::Requirement
142
202
  requirements:
143
203
  - - ">="
144
204
  - !ruby/object:Gem::Version
145
- version: '0'
205
+ version: 0.49.0
146
206
  - !ruby/object:Gem::Dependency
147
207
  name: vcr
148
208
  requirement: !ruby/object:Gem::Requirement
@@ -197,6 +257,7 @@ files:
197
257
  - ".rspec"
198
258
  - ".rubocop.yml"
199
259
  - ".travis.yml"
260
+ - CHANGELOG.md
200
261
  - Gemfile
201
262
  - Gemfile.lock
202
263
  - LICENSE.txt
@@ -204,11 +265,16 @@ files:
204
265
  - Rakefile
205
266
  - bin/console
206
267
  - bin/setup
207
- - lib/pusher-push-notifications.rb
208
268
  - lib/pusher/push_notifications.rb
209
269
  - lib/pusher/push_notifications/client.rb
270
+ - lib/pusher/push_notifications/token.rb
271
+ - lib/pusher/push_notifications/use_cases/delete_user.rb
272
+ - lib/pusher/push_notifications/use_cases/generate_token.rb
210
273
  - lib/pusher/push_notifications/use_cases/publish.rb
274
+ - lib/pusher/push_notifications/use_cases/publish_to_users.rb
275
+ - lib/pusher/push_notifications/user_id.rb
211
276
  - lib/pusher/push_notifications/version.rb
277
+ - lib/pusher_push_notifications.rb
212
278
  - pusher-push-notifications.gemspec
213
279
  homepage: https://github.com/pusher/push-notifications-ruby
214
280
  licenses:
@@ -229,8 +295,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
229
295
  - !ruby/object:Gem::Version
230
296
  version: '0'
231
297
  requirements: []
232
- rubyforge_project:
233
- rubygems_version: 2.7.6
298
+ rubygems_version: 3.0.8
234
299
  signing_key:
235
300
  specification_version: 4
236
301
  summary: Pusher Push Notifications Ruby server SDK