wor-push-notifications-aws 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3b8ea9f5f5acde332401fc297c566f3f5daec527
4
- data.tar.gz: 7ac5140ce68d400bea02c177db0b93ca61086928
3
+ metadata.gz: 2579fa5d87164c198bdd3cb86e90d814ad261ff3
4
+ data.tar.gz: 432f4ce9d4b23d10837dd296035a6a8ce7e01de3
5
5
  SHA512:
6
- metadata.gz: 1138461202f9f5c86bd61bd1ce8a71fbb284f2afee1f6f3a0324ebacd0d3fdf4b3101b8d0d2d039e07869894d844232ce75dcfd8e45dcfbe8e8d233a66d73871
7
- data.tar.gz: 692de303da017b9df4fab6fc4df5b9db35113282c8f99c04fe0ea9b5f9eba65daf42360996f34d11fa143918899123214c12d29c956f0820d6383a6587b798cd
6
+ metadata.gz: 9d5ced70039d2f3bd7e25a4fd871e35eb80dadb47bd46bf29793ddcb4289618568531fb8f5a81bd98b559f7ada580c7b19cb01faaf1d1136467a64eea2cf0234
7
+ data.tar.gz: de0b2b76ad7aac52e7e268fc029035cf66a22c685ad86dc636dcd1acccbd79280754e4796c0d91a619922560bca0ac5048ca8cccf1cb2b149f6dfe21278e6a3e
data/.codeclimate.yml CHANGED
@@ -2,3 +2,8 @@ engines:
2
2
  rubocop:
3
3
  enabled: true
4
4
  channel: rubocop-0-48
5
+
6
+ ratings:
7
+ paths:
8
+ - "lib/**/*"
9
+ - "spec/**/*"
@@ -86,7 +86,7 @@ module Wor
86
86
  end
87
87
 
88
88
  def self.add_token(user, device_token, device_type)
89
- PushNotifications.add_token(user, device_token, device_type)
89
+ PushNotifications.add_token(user, device_token, device_type.to_sym)
90
90
  end
91
91
 
92
92
  def self.delete_token(user, device_token)
@@ -0,0 +1,11 @@
1
+ module Wor
2
+ module Push
3
+ module Notifications
4
+ module Aws
5
+ module Exceptions
6
+ class ModelWithoutDeviceTokensAttribute < StandardError; end
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,7 +1,7 @@
1
1
  require 'wor/push/notifications/aws/android_push_json_builder'
2
2
  require 'wor/push/notifications/aws/ios_push_json_builder'
3
- require 'wor/push/notifications/aws/services/sns_client'
4
3
  require 'wor/push/notifications/aws/validators/push_notifications_validator'
4
+ require 'aws-sdk-rails'
5
5
 
6
6
  module Wor
7
7
  module Push
@@ -62,7 +62,9 @@ module Wor
62
62
  end
63
63
 
64
64
  def sns
65
- @sns_client ||= SnsClient.new(Wor::Push::Notifications::Aws.aws_region)
65
+ @sns_client ||= ::Aws::SNS::Client.new(
66
+ region: Wor::Push::Notifications::Aws.aws_region
67
+ )
66
68
  end
67
69
 
68
70
  def app_arn(device_type)
@@ -10,27 +10,36 @@ module Wor
10
10
  end
11
11
 
12
12
  def validate_add_token
13
+ validate_model_existance
13
14
  validate_existence_of_attributes_in_model
14
15
  validate_parameters
15
16
  end
16
17
 
17
18
  def validate_delete_token
19
+ validate_model_existance
18
20
  validate_existence_of_attributes_in_model
19
21
  end
20
22
 
21
23
  def validate_send_message(message_content)
24
+ validate_model_existance
22
25
  validate_existence_of_attributes_in_model
23
26
  validate_message_content(message_content)
24
27
  end
25
28
 
26
29
  private
27
30
 
31
+ def validate_model_existance
32
+ raise ArgumentError, message_for_nil_model if @model.nil?
33
+ end
34
+
28
35
  def validate_existence_of_attributes_in_model
29
- raise message_for_missing_attribute unless @model.has_attribute?(:device_tokens)
36
+ return if @model.has_attribute?(:device_tokens)
37
+ raise Wor::Push::Notifications::Aws::Exceptions::ModelWithoutDeviceTokensAttribute,
38
+ message_for_missing_attribute_in_model
30
39
  end
31
40
 
32
41
  def validate_message_content(message_content)
33
- raise message_for_invalid_message_content if message_content[:message].blank?
42
+ raise ArgumentError, message_content_error_message if message_content[:message].blank?
34
43
  end
35
44
 
36
45
  def validate_parameters
@@ -38,20 +47,24 @@ module Wor
38
47
  raise ArgumentError, message_for_nil_device_token if @device_token.blank?
39
48
  end
40
49
 
41
- def message_for_missing_attribute
42
- 'Missing attribute device_tokens for model. Have you run the gem migration?'
43
- end
44
-
45
50
  def message_for_invalid_device_type
46
51
  "Invalid device_type. It has to be one of the types configured \
47
52
  #{Wor::Push::Notifications::Aws.device_types}."
48
53
  end
49
54
 
55
+ def message_for_missing_attribute_in_model
56
+ 'Missing attribute device_tokens for model. Have you run the gem migration?'
57
+ end
58
+
50
59
  def message_for_nil_device_token
51
60
  'device_token cannot be nil.'
52
61
  end
53
62
 
54
- def message_for_invalid_message_content
63
+ def message_for_nil_model
64
+ 'your entity instance cannot be nil.'
65
+ end
66
+
67
+ def message_content_error_message
55
68
  "the message_content must have a 'message' field"
56
69
  end
57
70
 
@@ -2,7 +2,7 @@ module Wor
2
2
  module Push
3
3
  module Notifications
4
4
  module Aws
5
- VERSION = '0.1.0'.freeze
5
+ VERSION = '0.1.1'.freeze
6
6
  end
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wor-push-notifications-aws
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leandro Masello
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-07-26 00:00:00.000000000 Z
12
+ date: 2017-07-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
@@ -67,9 +67,9 @@ files:
67
67
  - lib/generators/wor/push/notifications/aws/install_generator.rb
68
68
  - lib/wor/push/notifications/aws.rb
69
69
  - lib/wor/push/notifications/aws/android_push_json_builder.rb
70
+ - lib/wor/push/notifications/aws/exceptions.rb
70
71
  - lib/wor/push/notifications/aws/ios_push_json_builder.rb
71
72
  - lib/wor/push/notifications/aws/push_notifications.rb
72
- - lib/wor/push/notifications/aws/services/sns_client.rb
73
73
  - lib/wor/push/notifications/aws/validators/push_notifications_validator.rb
74
74
  - lib/wor/push/notifications/aws/version.rb
75
75
  - wor-push-notifications-aws.gemspec
@@ -1,15 +0,0 @@
1
- require 'aws-sdk-rails'
2
-
3
- module Wor
4
- module Push
5
- module Notifications
6
- module Aws
7
- class SnsClient
8
- def initialize(region)
9
- Aws::SNS::Client.new(region: region)
10
- end
11
- end
12
- end
13
- end
14
- end
15
- end