push_to_sns 0.2.0 → 0.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
  SHA1:
3
- metadata.gz: bdb88b92dcd3dc7f89ad71992c1f05bcb496765f
4
- data.tar.gz: 2c64da57edee3c5d6a8b668b26fde82861a6c89e
3
+ metadata.gz: 454e432ec1f42eaa7923f2fce621100f5ec767ee
4
+ data.tar.gz: f43a33da8de39283f8d7044c27e93e7ed93ff18a
5
5
  SHA512:
6
- metadata.gz: e11f5cbead59e666895f74ce48f5dbb1b2964c74a304acad1694751876ad955bc6cf0230ffca7cff0dfb4af1438e6b7e4f47afad0ef763497e3b80a84819f197
7
- data.tar.gz: d3da5122c6ac0d62601d7d22fc009671b423de37cbc0de4d2f29eda298f310f159f1e860a14718751c19db011c7e6583afa9aab83cb0fe5f9127ea442998255b
6
+ metadata.gz: 122c2811a58f9fbd806d6e67e7f3bd68504b9a3911eea336fb7d853bd686e56ac3577e253e44a2ef8c01d80954db83da671700a4308d1fd443c80c98c36ff2e6
7
+ data.tar.gz: 0fdd53cb5e7212b4cb107a4ddb84910e3ffa12ef28165129e331006d32227e32137e76b1cfb91e65fbeac230af1096c18dd8774990d413ac56fb7e2a25b8cca2
data/README.md CHANGED
@@ -31,7 +31,7 @@ $ bundle
31
31
 
32
32
  ```ruby
33
33
  PushToSNS.configure do
34
- read_device_id { |device| }
34
+ read_device_token { |device| }
35
35
  read_source { |device| }
36
36
  read_endpoint_arn { |device| }
37
37
  read_platform_arn { |device| }
@@ -46,7 +46,7 @@ $ bundle
46
46
 
47
47
  ```ruby
48
48
  PushToSNS.configure do
49
- read_device_id { |device| device.device_id }
49
+ read_device_token { |device| device.device_token }
50
50
  read_source { |device| device.source }
51
51
  read_endpoint_arn { |device| device.endpoint_arn }
52
52
  read_platform_arn { |device| ENV["SNS_#{device.source.upcase}_PLATFORM_ARN"] }
@@ -60,20 +60,28 @@ $ bundle
60
60
 
61
61
  ### Device Setup
62
62
 
63
- This is up to you in some way. For example, you can have a controller to receive `device_id`s from a mobile device and you want to register the device to be able to receive push notifications. You can do it in this way:
63
+ This is up to you in some way. For example, you can have a controller to receive a `device_token` and `device_uuid` from a mobile device and you want to register the device to be able to receive push notifications. You can do it in this way:
64
64
 
65
65
  ```ruby
66
66
  class DevicesController < ApiController
67
67
  def create
68
- device = Device.create(device_params)
69
- PushToSNS.setup_device(device)
68
+ device = Device.find_by(device_uuid: device_params[:device_uuid])
69
+ if device.present?
70
+ # We first teardown the old endpoint arn.
71
+ PushToSNS.teardown_device(device)
72
+ device.update(device_params.slice(:device_token))
73
+ else
74
+ device = Device.create(device_params)
75
+ end
76
+
77
+ PushToSNS.setup_device(device)
70
78
  respond_with device
71
79
  end
72
80
 
73
81
  private
74
82
 
75
83
  def device_params
76
- params.require(:device).permit(:device_id, :source)
84
+ params.require(:device).permit(:device_token, :device_uuid, :source)
77
85
  end
78
86
  end
79
87
  ```
data/lib/push_to_sns.rb CHANGED
@@ -4,6 +4,7 @@ require_relative "./push_to_sns/version"
4
4
  require_relative "./push_to_sns/messages"
5
5
  require_relative "./push_to_sns/configuration"
6
6
  require_relative "./push_to_sns/setup_push_notification"
7
+ require_relative "./push_to_sns/teardown_push_notification"
7
8
  require_relative "./push_to_sns/push_notifier"
8
9
  require_relative "./push_to_sns/send_push_notification"
9
10
  require_relative "./push_to_sns/basic_push_notification"
@@ -22,4 +23,8 @@ module PushToSNS
22
23
  def self.setup_device(device)
23
24
  PushToSNS::SetupPushNotification.new(device).perform
24
25
  end
26
+
27
+ def self.teardown_device(device)
28
+ PushToSNS::TeardownPushNotification.new(device).perform
29
+ end
25
30
  end
@@ -1,7 +1,7 @@
1
1
  module PushToSNS
2
2
  class Configuration
3
3
  PROC_PROPERTIES = %i(
4
- read_device_id
4
+ read_device_token
5
5
  read_source
6
6
  read_endpoint_arn
7
7
  read_platform_arn
@@ -8,8 +8,8 @@ module PushToSNS
8
8
  "Not Implemented Method `#{method_name.to_s}`: #{message.call}"
9
9
  end
10
10
 
11
- READ_DEVICE_ID_NOT_IMPLEMENTED = not_implemented_config(:read_device_id) do
12
- "How to read the device's id from a device object?"
11
+ READ_DEVICE_TOKEN_NOT_IMPLEMENTED = not_implemented_config(:read_device_token) do
12
+ "How to read the device's token from a device object?"
13
13
  end
14
14
 
15
15
  READ_SOURCE_NOT_IMPLEMENTED = not_implemented_config(:read_source) do
@@ -36,7 +36,7 @@ module PushToSNS
36
36
  def ensure_endpoint_arn_is_enabled
37
37
  attributes = get_endpoint_attributes
38
38
 
39
- if attributes["Enabled"].downcase == "false" || attributes["Token"] != device_id
39
+ if attributes["Enabled"].downcase == "false" || attributes["Token"] != device_token
40
40
  enable_endpoint_arn
41
41
  end
42
42
  end
@@ -52,13 +52,13 @@ module PushToSNS
52
52
  endpoint_arn: endpoint_arn,
53
53
  attributes: {
54
54
  "Enabled" => "True",
55
- "Token" => device_id
55
+ "Token" => device_token
56
56
  }
57
57
  )[:endpoint_arn]
58
58
  end
59
59
 
60
- def device_id
61
- @device_id ||= configuration.apply(:read_device_id, device)
60
+ def device_token
61
+ @device_token ||= configuration.apply(:read_device_token, device)
62
62
  end
63
63
 
64
64
  def endpoint_arn
@@ -16,7 +16,7 @@ module PushToSNS
16
16
  def create_endpoint_arn
17
17
  AWS.sns.client.create_platform_endpoint({
18
18
  platform_application_arn: configuration.apply(:read_platform_arn, device),
19
- token: configuration.apply(:read_device_id, device)
19
+ token: configuration.apply(:read_device_token, device)
20
20
  })[:endpoint_arn]
21
21
  end
22
22
  end
@@ -0,0 +1,17 @@
1
+ module PushToSNS
2
+ class TeardownPushNotification
3
+ def initialize(device, configuration = PushToSNS.configuration)
4
+ self.device = device
5
+ self.configuration = configuration
6
+ end
7
+
8
+ def perform
9
+ endpoint = configuration.apply(:read_endpoint_arn, device)
10
+ AWS.sns.client.delete_endpoint(endpoint_arn: endpoint) if endpoint
11
+ end
12
+
13
+ private
14
+
15
+ attr_accessor :device, :configuration
16
+ end
17
+ end
@@ -1,3 +1,3 @@
1
1
  module PushToSNS
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -1,5 +1,5 @@
1
1
  PushToSNS.configure do
2
- read_device_id { |device| fail PushToSNS::Messages::READ_DEVICE_ID_NOT_IMPLEMENTED }
2
+ read_device_token { |device| fail PushToSNS::Messages::READ_DEVICE_TOKEN_NOT_IMPLEMENTED }
3
3
  read_source { |device| fail PushToSNS::Messages::READ_SOURCE_NOT_IMPLEMENTED }
4
4
  read_endpoint_arn { |device| fail PushToSNS::Messages::READ_ENDPOINT_ARN_NOT_IMPLEMENTED }
5
5
  read_platform_arn { |device| fail PushToSNS::Messages::READ_PLATFORM_ARN_NOT_IMPLEMENTED }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: push_to_sns
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - juliogarciag
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-11 00:00:00.000000000 Z
11
+ date: 2015-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -148,6 +148,7 @@ files:
148
148
  - lib/push_to_sns/push_notifier.rb
149
149
  - lib/push_to_sns/send_push_notification.rb
150
150
  - lib/push_to_sns/setup_push_notification.rb
151
+ - lib/push_to_sns/teardown_push_notification.rb
151
152
  - lib/push_to_sns/version.rb
152
153
  - lib/rails/generators/push_to_sns/install_generator.rb
153
154
  - lib/rails/generators/push_to_sns/notifier_generator.rb