moromi-aws-sns 0.10.0 → 0.15.0

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
- SHA1:
3
- metadata.gz: 3baab0c1c05d47236977a93d32462c195497be00
4
- data.tar.gz: b9947afddc979487d1ceb5c4654b2256e79c2cfb
2
+ SHA256:
3
+ metadata.gz: e81f929cb8f988e4a6fcf67076daf379b41fe5d13832f6da060bc1536d055704
4
+ data.tar.gz: 540652fc01c31c623c40826e01ed2edbcb99937650442a0ade6a7549cd1a8d54
5
5
  SHA512:
6
- metadata.gz: f360b9ad84439904b3101fd04f8717daf6d74b715e066209642b39abaa050c750c36239b59b16b5d816ca357dab9c39f377e0d0e254e5a36958c624ed70e4abe
7
- data.tar.gz: 76b14ec220be6e4eb11f6ad9a9807051ecc03e4fb8d882643b2560cd99d7aa40954e1aee212a7fde8229edbea92b6a81f0bb37f541e2582634f8ac7e4587e21d
6
+ metadata.gz: 8804c680b64dbe83ec4e0a5e0b66640a6e96c9a33585f0f5ff0cad642b73a7ed6a35baab4f510a781fc1405104d99dc68d3d958dacf25419b28297bf7ba033cd
7
+ data.tar.gz: 949e8670aa6483c3a77ccb545017a893c68bdd44f1d703755dd602118e7240e24a608c5e466097a64d0b39773fca2ae67457559af429082cd76d28cc90ab3215
@@ -4,9 +4,8 @@ module Moromi
4
4
  module Aws
5
5
  module Sns
6
6
  class Client
7
- def initialize(access_key_id, secret_access_key, region)
8
- @access_key_id = access_key_id
9
- @secret_access_key = secret_access_key
7
+ def initialize(region, credentials: nil)
8
+ @credentials = credentials
10
9
  @region = region
11
10
  end
12
11
 
@@ -87,12 +86,14 @@ module Moromi
87
86
 
88
87
  private
89
88
 
90
- def credentials
91
- @credentials ||= ::Aws::Credentials.new(@access_key_id, @secret_access_key)
92
- end
93
-
94
89
  def client
95
- @client ||= ::Aws::SNS::Client.new(region: @region, credentials: credentials)
90
+ @client ||= begin
91
+ if @credentials
92
+ ::Aws::SNS::Client.new(region: @region, credentials: @credentials)
93
+ else
94
+ ::Aws::SNS::Client.new(region: @region)
95
+ end
96
+ end
96
97
  end
97
98
 
98
99
  def call_publish(options)
@@ -9,11 +9,13 @@ module Moromi
9
9
  attr_reader :content_available
10
10
  attr_reader :mutable_content
11
11
  attr_reader :category
12
+ attr_reader :thread_id
12
13
  attr_reader :priority
13
14
  attr_reader :type
14
15
  attr_reader :custom_data
15
16
 
16
- def initialize(alert:, badge:, sound: 'default', content_available: 1, mutable_content: 0, category: nil,
17
+
18
+ def initialize(alert:, badge:, sound: 'default', content_available: 1, mutable_content: 0, category: nil, thread_id: nil,
17
19
  priority: 10, type: nil, custom_data: {})
18
20
  @alert = alert
19
21
  @badge = badge
@@ -21,6 +23,7 @@ module Moromi
21
23
  @content_available = content_available
22
24
  @mutable_content = mutable_content
23
25
  @category = category
26
+ @thread_id = thread_id
24
27
  @priority = priority
25
28
  @type = type || self.class.name
26
29
  @custom_data = setup_initial_custom_data({type: @type}.merge(custom_data))
@@ -33,6 +36,7 @@ module Moromi
33
36
  sound: @sound,
34
37
  content_available: @content_available,
35
38
  mutable_content: @mutable_content,
39
+ thread_id: @thread_id,
36
40
  category: @category,
37
41
  priority: @priority,
38
42
  type: @type,
@@ -42,7 +46,10 @@ module Moromi
42
46
 
43
47
  def to_message_json
44
48
  aps = to_hash
45
- %i[custom_data type].each { |k| aps.delete(k) }
49
+ %i[custom_data type content_available mutable_content].each { |k| aps.delete(k) }
50
+ aps['content-available'] = @content_available
51
+ aps['mutable-content'] = @mutable_content
52
+ aps['thread-id'] = @thread_id
46
53
  @custom_data.merge({aps: aps}).to_json
47
54
  end
48
55
 
@@ -57,10 +57,27 @@ module Moromi
57
57
  }
58
58
  end
59
59
 
60
+ def to_data_hash
61
+ base = {
62
+ title: @title,
63
+ body: @body,
64
+ android_channel_id: @android_channel_id,
65
+ icon: @icon,
66
+ sound: @sound,
67
+ tag: @tag,
68
+ color: @color,
69
+ click_action: @click_action,
70
+ body_loc_key: @body_loc_key,
71
+ body_loc_args: @body_loc_args,
72
+ title_loc_key: @title_loc_key,
73
+ title_loc_args: @title_loc_args,
74
+ type: @type
75
+ }
76
+ flatten_hash(@custom_data).merge(base)
77
+ end
78
+
60
79
  def to_message_json
61
- notification = to_hash
62
- %i[custom_data type].each { |k| notification.delete(k) }
63
- {notification: notification, data: @custom_data}.to_json
80
+ {data: to_data_hash}.to_json
64
81
  end
65
82
 
66
83
  private
@@ -68,6 +85,18 @@ module Moromi
68
85
  def setup_initial_custom_data(custom_data)
69
86
  custom_data
70
87
  end
88
+
89
+ def flatten_hash(hash)
90
+ hash.each_with_object({}) do |(k, v), h|
91
+ if v.is_a? Hash
92
+ flatten_hash(v).map do |h_k, h_v|
93
+ h["#{k}_#{h_k}".to_sym] = h_v
94
+ end
95
+ else
96
+ h[k] = v
97
+ end
98
+ end
99
+ end
71
100
  end
72
101
  end
73
102
  end
@@ -1,7 +1,7 @@
1
1
  module Moromi
2
2
  module Aws
3
3
  module Sns
4
- VERSION = '0.10.0'
4
+ VERSION = '0.15.0'
5
5
  end
6
6
  end
7
7
  end
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_dependency 'aws-sdk-sns', '~> 1'
25
25
  spec.add_dependency 'activesupport', ['>= 4.2']
26
26
 
27
- spec.add_development_dependency "bundler", "~> 1.12"
28
- spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "bundler"
28
+ spec.add_development_dependency "rake", ">= 12.3.3"
29
29
  spec.add_development_dependency "rspec", "~> 3.0"
30
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moromi-aws-sns
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takahiro Ooishi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-04 00:00:00.000000000 Z
11
+ date: 2020-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-sns
@@ -42,30 +42,30 @@ dependencies:
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '1.12'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '1.12'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '10.0'
61
+ version: 12.3.3
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '10.0'
68
+ version: 12.3.3
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -123,8 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  requirements: []
126
- rubyforge_project:
127
- rubygems_version: 2.6.13
126
+ rubygems_version: 3.1.2
128
127
  signing_key:
129
128
  specification_version: 4
130
129
  summary: AWS SNS client.