Skip to content

Commit

Permalink
Merge pull request #21 from jordansgrant/refactor/remove-caze-gems-wi…
Browse files Browse the repository at this point in the history
…th-dependency-upgrades

[refactor] remove caze gems with dependency upgrades
  • Loading branch information
Jon Elverkilde authored Mar 17, 2021
2 parents 0aa329d + 42bc88f commit 04344aa
Show file tree
Hide file tree
Showing 16 changed files with 292 additions and 283 deletions.
10 changes: 8 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
sudo: false
language: ruby
rvm:
- 2.4.2
before_install: gem install bundler -v 1.16.0
- 2.6.6
- 2.7.2
- 3.0.0
before_install: gem install bundler
script:
- bundle exec rake
- bundle exec rubocop
env:
- PUSHER_INSTANCE_ID=1b880590-6301-4bb5-b34f-45db1c5f5644
PUSHER_SECRET_KEY=abc

150 changes: 70 additions & 80 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,124 +2,114 @@ PATH
remote: .
specs:
pusher-push-notifications (1.3.0)
caze (~> 0)
jwt (~> 2.1, >= 2.1.0)
rest-client (~> 2.0, >= 2.0.2)

GEM
remote: https://rubygems.org/
specs:
activesupport (5.2.2)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0)
ast (2.3.0)
byebug (10.0.2)
caze (0.2.2)
activesupport (>= 3)
codecov (0.1.10)
json
simplecov
url
coderay (1.1.2)
concurrent-ruby (1.1.4)
coveralls (0.8.21)
addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0)
ast (2.4.2)
byebug (11.1.3)
codecov (0.5.1)
simplecov (>= 0.15, < 0.22)
coderay (1.1.3)
coveralls (0.8.23)
json (>= 1.8, < 3)
simplecov (~> 0.14.1)
simplecov (~> 0.16.1)
term-ansicolor (~> 1.3)
thor (~> 0.19.4)
thor (>= 0.19.4, < 2.0)
tins (~> 1.6)
crack (0.4.3)
safe_yaml (~> 1.0.0)
diff-lcs (1.3)
docile (1.1.5)
domain_name (0.5.20180417)
crack (0.4.5)
rexml
diff-lcs (1.4.4)
docile (1.3.5)
domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0)
dotenv (2.2.1)
hashdiff (0.3.7)
dotenv (2.7.6)
hashdiff (1.0.1)
http-accept (1.7.0)
http-cookie (1.0.3)
domain_name (~> 0.5)
i18n (1.5.3)
concurrent-ruby (~> 1.0)
json (2.1.0)
jwt (2.1.0)
method_source (0.9.2)
mime-types (3.2.2)
json (2.5.1)
jwt (2.2.2)
method_source (1.0.0)
mime-types (3.3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2018.0812)
minitest (5.11.3)
mime-types-data (3.2021.0225)
netrc (0.11.0)
parallel (1.12.1)
parser (2.4.0.2)
ast (~> 2.3)
powerpack (0.1.1)
pry (0.12.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
pry-byebug (3.6.0)
byebug (~> 10.0)
pry (~> 0.10)
public_suffix (3.0.1)
parallel (1.20.1)
parser (3.0.0.0)
ast (~> 2.4.1)
pry (0.13.1)
coderay (~> 1.1)
method_source (~> 1.0)
pry-byebug (3.9.0)
byebug (~> 11.0)
pry (~> 0.13.0)
public_suffix (4.0.6)
rainbow (3.0.0)
rake (10.5.0)
rb-readline (0.5.5)
rest-client (2.0.2)
regexp_parser (2.1.1)
rest-client (2.1.0)
http-accept (>= 1.7.0, < 2.0)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
rspec (3.7.0)
rspec-core (~> 3.7.0)
rspec-expectations (~> 3.7.0)
rspec-mocks (~> 3.7.0)
rspec-core (3.7.0)
rspec-support (~> 3.7.0)
rspec-expectations (3.7.0)
rexml (3.2.4)
rspec (3.10.0)
rspec-core (~> 3.10.0)
rspec-expectations (~> 3.10.0)
rspec-mocks (~> 3.10.0)
rspec-core (3.10.1)
rspec-support (~> 3.10.0)
rspec-expectations (3.10.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.7.0)
rspec-mocks (3.7.0)
rspec-support (~> 3.10.0)
rspec-mocks (3.10.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.7.0)
rspec-support (3.7.0)
rubocop (0.52.0)
rspec-support (~> 3.10.0)
rspec-support (3.10.2)
rubocop (1.11.0)
parallel (~> 1.10)
parser (>= 2.4.0.2, < 3.0)
powerpack (~> 0.1)
parser (>= 3.0.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml
rubocop-ast (>= 1.2.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.9.0)
safe_yaml (1.0.4)
simplecov (0.14.1)
docile (~> 1.1.0)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.4.1)
parser (>= 2.7.1.5)
ruby-progressbar (1.11.0)
simplecov (0.16.1)
docile (~> 1.1)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.2)
term-ansicolor (1.6.0)
sync (0.5.0)
term-ansicolor (1.7.1)
tins (~> 1.0)
thor (0.19.4)
thread_safe (0.3.6)
tins (1.16.3)
tzinfo (1.2.5)
thread_safe (~> 0.1)
thor (1.1.0)
tins (1.28.0)
sync
unf (0.1.4)
unf_ext
unf_ext (0.0.7.5)
unicode-display_width (1.3.0)
url (0.3.2)
unf_ext (0.0.7.7)
unicode-display_width (2.0.0)
vcr (3.0.3)
webmock (3.1.1)
webmock (3.12.0)
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff
hashdiff (>= 0.4.0, < 2.0.0)

PLATFORMS
ruby

DEPENDENCIES
bundler (~> 1.16)
bundler (~> 2.2)
codecov (~> 0)
coveralls (~> 0.8.21)
dotenv (~> 2.2, >= 2.2.1)
Expand All @@ -133,4 +123,4 @@ DEPENDENCIES
webmock (~> 3.0, >= 3.0.1)

BUNDLED WITH
1.16.2
2.2.13
31 changes: 12 additions & 19 deletions lib/pusher/push_notifications.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require 'caze'

require_relative './push_notifications/client'
require_relative './push_notifications/use_cases/publish'
require_relative './push_notifications/use_cases/publish_to_users'
Expand All @@ -13,19 +11,18 @@

module Pusher
module PushNotifications
include Caze

class PushError < RuntimeError; end

has_use_case :publish, UseCases::Publish
has_use_case :publish_to_interests, UseCases::Publish
has_use_case :publish_to_users, UseCases::PublishToUsers
has_use_case :delete_user, UseCases::DeleteUser
has_use_case :generate_token, UseCases::GenerateToken

class << self
extend Forwardable

attr_reader :instance_id, :secret_key

def_delegators UseCases::Publish, :publish, :publish_to_interests
def_delegators UseCases::PublishToUsers, :publish_to_users
def_delegators UseCases::DeleteUser, :delete_user
def_delegators UseCases::GenerateToken, :generate_token

def configure
yield(self)
# returning a duplicate of `self` to allow multiple clients to be
Expand All @@ -34,23 +31,19 @@ def configure
end

def instance_id=(instance_id)
if instance_id.nil? || instance_id.delete(' ').empty?
raise PushError, 'Invalid instance id'
end
raise PushError, 'Invalid instance id' if instance_id.nil? || instance_id.delete(' ').empty?

@instance_id = instance_id
end

def secret_key=(secret_key)
if secret_key.nil? || secret_key.delete(' ').empty?
raise PushError, 'Invalid secret key'
end
raise PushError, 'Invalid secret key' if secret_key.nil? || secret_key.delete(' ').empty?

@secret_key = secret_key
end

def endpoint=(endpoint)
if !endpoint.nil? && endpoint.delete(' ').empty?
raise PushError, 'Invalid endpoint override'
end
raise PushError, 'Invalid endpoint override' if !endpoint.nil? && endpoint.delete(' ').empty?

@endpoint = endpoint
end
Expand Down
1 change: 1 addition & 0 deletions lib/pusher/push_notifications/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def delete(user)
private

attr_reader :config

def_delegators :@config, :instance_id, :secret_key, :endpoint

def build_publish_url(resource)
Expand Down
1 change: 1 addition & 0 deletions lib/pusher/push_notifications/token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def generate(user)
private

attr_reader :config

def_delegators :@config, :instance_id, :secret_key
end
end
Expand Down
11 changes: 6 additions & 5 deletions lib/pusher/push_notifications/use_cases/delete_user.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
# frozen_string_literal: true

require 'caze'

module Pusher
module PushNotifications
module UseCases
class DeleteUser
include Caze

class UserDeletionError < RuntimeError; end

export :delete_user, as: :delete_user
class << self
def delete_user(*args, **kwargs)
new(*args, **kwargs).delete_user
end
end

def initialize(user:)
@user = user
@user_id = Pusher::PushNotifications::UserId.new

raise UserDeletionError, 'User Id cannot be empty.' if user.empty?

if user.length > UserId::MAX_USER_ID_LENGTH
raise UserDeletionError, 'User id length too long ' \
"(expected fewer than #{UserId::MAX_USER_ID_LENGTH + 1} characters)"
Expand Down
11 changes: 6 additions & 5 deletions lib/pusher/push_notifications/use_cases/generate_token.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
# frozen_string_literal: true

require 'caze'

module Pusher
module PushNotifications
module UseCases
class GenerateToken
include Caze

class GenerateTokenError < RuntimeError; end

export :generate_token, as: :generate_token
class << self
def generate_token(*args, **kwargs)
new(*args, **kwargs).generate_token
end
end

def initialize(user:)
@user = user
@user_id = Pusher::PushNotifications::UserId.new

raise GenerateTokenError, 'User Id cannot be empty.' if user.empty?

if user.length > UserId::MAX_USER_ID_LENGTH
raise GenerateTokenError, 'User id length too long ' \
"(expected fewer than #{UserId::MAX_USER_ID_LENGTH + 1} characters)"
Expand Down
Loading

0 comments on commit 04344aa

Please sign in to comment.