Skip to content

Commit b98f1ba

Browse files
Unnikrishnan KPUnnikrishnan KP
authored andcommitted
specs added
0 parents  commit b98f1ba

20 files changed

+682
-0
lines changed

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/.bundle/
2+
/.yardoc
3+
/_yardoc/
4+
/coverage/
5+
/doc/
6+
/pkg/
7+
/spec/reports/
8+
/tmp/
9+
/*.gem
10+
# rspec failure tracking
11+
.rspec_status

.rspec

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
--format documentation
2+
--color
3+
--require spec_helper

.rubocop.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
AllCops:
2+
TargetRubyVersion: 3.1
3+
4+
Style/StringLiterals:
5+
EnforcedStyle: double_quotes
6+
7+
Style/StringLiteralsInInterpolation:
8+
EnforcedStyle: double_quotes

Gemfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# frozen_string_literal: true
2+
3+
source "https://rubygems.org"
4+
5+
# Specify your gem's dependencies in sns_sender.gemspec
6+
gemspec
7+
8+
gem "irb"
9+
gem "rake", "~> 13.0"
10+
11+
gem "rspec", "~> 3.0"
12+
13+
gem "rubocop", "~> 1.21"

Gemfile.lock

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
PATH
2+
remote: .
3+
specs:
4+
sns_sender (0.1.0)
5+
aws-sdk-sns (~> 1.0)
6+
7+
GEM
8+
remote: https://rubygems.org/
9+
specs:
10+
ast (2.4.3)
11+
aws-eventstream (1.3.2)
12+
aws-partitions (1.1090.0)
13+
aws-sdk-core (3.222.2)
14+
aws-eventstream (~> 1, >= 1.3.0)
15+
aws-partitions (~> 1, >= 1.992.0)
16+
aws-sigv4 (~> 1.9)
17+
base64
18+
jmespath (~> 1, >= 1.6.1)
19+
logger
20+
aws-sdk-sns (1.97.0)
21+
aws-sdk-core (~> 3, >= 3.216.0)
22+
aws-sigv4 (~> 1.5)
23+
aws-sigv4 (1.11.0)
24+
aws-eventstream (~> 1, >= 1.0.2)
25+
base64 (0.2.0)
26+
date (3.4.1)
27+
diff-lcs (1.6.1)
28+
io-console (0.8.0)
29+
irb (1.15.2)
30+
pp (>= 0.6.0)
31+
rdoc (>= 4.0.0)
32+
reline (>= 0.4.2)
33+
jmespath (1.6.2)
34+
json (2.10.2)
35+
language_server-protocol (3.17.0.4)
36+
lint_roller (1.1.0)
37+
logger (1.7.0)
38+
mini_portile2 (2.8.8)
39+
nokogiri (1.18.7)
40+
mini_portile2 (~> 2.8.2)
41+
racc (~> 1.4)
42+
nokogiri (1.18.7-arm64-darwin)
43+
racc (~> 1.4)
44+
parallel (1.27.0)
45+
parser (3.3.8.0)
46+
ast (~> 2.4.1)
47+
racc
48+
pp (0.6.2)
49+
prettyprint
50+
prettyprint (0.2.0)
51+
prism (1.4.0)
52+
psych (5.2.3)
53+
date
54+
stringio
55+
racc (1.8.1)
56+
rainbow (3.1.1)
57+
rake (13.2.1)
58+
rdoc (6.13.1)
59+
psych (>= 4.0.0)
60+
regexp_parser (2.10.0)
61+
reline (0.6.1)
62+
io-console (~> 0.5)
63+
rspec (3.13.0)
64+
rspec-core (~> 3.13.0)
65+
rspec-expectations (~> 3.13.0)
66+
rspec-mocks (~> 3.13.0)
67+
rspec-core (3.13.3)
68+
rspec-support (~> 3.13.0)
69+
rspec-expectations (3.13.3)
70+
diff-lcs (>= 1.2.0, < 2.0)
71+
rspec-support (~> 3.13.0)
72+
rspec-mocks (3.13.2)
73+
diff-lcs (>= 1.2.0, < 2.0)
74+
rspec-support (~> 3.13.0)
75+
rspec-support (3.13.2)
76+
rubocop (1.75.2)
77+
json (~> 2.3)
78+
language_server-protocol (~> 3.17.0.2)
79+
lint_roller (~> 1.1.0)
80+
parallel (~> 1.10)
81+
parser (>= 3.3.0.2)
82+
rainbow (>= 2.2.2, < 4.0)
83+
regexp_parser (>= 2.9.3, < 3.0)
84+
rubocop-ast (>= 1.44.0, < 2.0)
85+
ruby-progressbar (~> 1.7)
86+
unicode-display_width (>= 2.4.0, < 4.0)
87+
rubocop-ast (1.44.1)
88+
parser (>= 3.3.7.2)
89+
prism (~> 1.4)
90+
ruby-progressbar (1.13.0)
91+
stringio (3.1.7)
92+
unicode-display_width (3.1.4)
93+
unicode-emoji (~> 4.0, >= 4.0.4)
94+
unicode-emoji (4.0.4)
95+
96+
PLATFORMS
97+
arm64-darwin-23
98+
ruby
99+
100+
DEPENDENCIES
101+
aws-sdk-core (~> 3.0)
102+
irb
103+
nokogiri (~> 1.15)
104+
rake (~> 13.0)
105+
rspec (~> 3.0)
106+
rubocop (~> 1.21)
107+
sns_sender!
108+
109+
BUNDLED WITH
110+
2.6.6

LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2025 TODO: Write your name
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# SNS Sender
2+
3+
A Ruby gem that provides a simple interface for publishing messages to AWS SNS topics, which can then be consumed by SQS queues.
4+
5+
## Installation
6+
7+
Add this line to your application's Gemfile:
8+
9+
```ruby
10+
gem 'sns_sender'
11+
```
12+
13+
And then execute:
14+
15+
$ bundle install
16+
17+
Or install it yourself as:
18+
19+
$ gem install sns_sender
20+
21+
## Configuration
22+
23+
Configure the gem with your AWS credentials. In a Rails application, you might want to put this in an initializer:
24+
25+
```ruby
26+
# config/initializers/sns_sender.rb
27+
SnsSender.configure do |config|
28+
config.aws_region = 'us-east-1' # Required
29+
config.aws_access_key_id = 'YOUR_ACCESS_KEY' # Required
30+
config.aws_secret_access_key = 'YOUR_SECRET_KEY' # Required
31+
config.default_topic_arn = 'YOUR_DEFAULT_TOPIC_ARN' # Optional
32+
end
33+
```
34+
35+
You can also use environment variables for AWS credentials:
36+
- AWS_REGION
37+
- AWS_ACCESS_KEY_ID
38+
- AWS_SECRET_ACCESS_KEY
39+
40+
## Usage
41+
42+
### Basic Usage
43+
44+
```ruby
45+
# Send a simple message
46+
SnsSender.publish(
47+
topic_arn: 'arn:aws:sns:us-east-1:123456789012:MyTopic',
48+
message: 'Hello, World!'
49+
)
50+
51+
# Send a JSON message
52+
SnsSender.publish(
53+
topic_arn: 'arn:aws:sns:us-east-1:123456789012:MyTopic',
54+
message: {
55+
event: 'user_created',
56+
data: {
57+
id: 123,
58+
name: 'John Doe',
59+
email: 'john@example.com'
60+
}
61+
}
62+
)
63+
64+
# Using the default topic (if configured)
65+
SnsSender.publish(
66+
message: 'Hello, World!'
67+
)
68+
69+
# With message attributes
70+
SnsSender.publish(
71+
topic_arn: 'arn:aws:sns:us-east-1:123456789012:MyTopic',
72+
message: 'Hello, World!',
73+
message_attributes: {
74+
event_type: 'greeting',
75+
priority: 'high'
76+
}
77+
)
78+
```
79+
80+
### Response Format
81+
82+
The `publish` method returns a hash with the following structure:
83+
84+
```ruby
85+
{
86+
success: true,
87+
message_id: 'abc123...' # The SNS message ID
88+
}
89+
```
90+
91+
### Error Handling
92+
93+
The gem can raise the following errors:
94+
95+
```ruby
96+
begin
97+
SnsSender.publish(topic_arn: 'arn:...', message: 'Hello')
98+
rescue SnsSender::ConfigurationError => e
99+
# Handle missing or invalid AWS configuration
100+
rescue SnsSender::PublishError => e
101+
# Handle SNS publishing errors
102+
rescue ArgumentError => e
103+
# Handle invalid arguments (missing topic_arn or message)
104+
end
105+
```
106+
107+
## Development
108+
109+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
110+
111+
To install this gem onto your local machine, run `bundle exec rake install`.
112+
113+
## Contributing
114+
115+
Bug reports and pull requests are welcome on GitHub at https://github.com/bigbinary/sns_sender.
116+
117+
## License
118+
119+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).

Rakefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# frozen_string_literal: true
2+
3+
require "bundler/gem_tasks"
4+
require "rspec/core/rake_task"
5+
6+
RSpec::Core::RakeTask.new(:spec)
7+
8+
require "rubocop/rake_task"
9+
10+
RuboCop::RakeTask.new
11+
12+
task default: %i[spec rubocop]

bin/console

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
require "bundler/setup"
5+
require "sns_sender"
6+
7+
# You can add fixtures and/or initialization code here to make experimenting
8+
# with your gem easier. You can also use a different console, if you like.
9+
10+
require "irb"
11+
IRB.start(__FILE__)

bin/setup

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
IFS=$'\n\t'
4+
set -vx
5+
6+
bundle install
7+
8+
# Do any other automated setup that you need to do here

0 commit comments

Comments
 (0)